GNOME Bugzilla – Bug 581616
ssconvert from a set of single sheets to a merged workbook
Last modified: 2009-05-12 12:38:40 UTC
The ssconvert command is very useful for converting between formats from the command line. Some formats have multiple sheets, some have single sheets. I see a TODO in the ssconvert source code for handling the output side of this problem. Equally useful would be the input side, for example to merge several CSV files into a single workbook and save that as a single file. I need this functionality, and would be interested in helping create it. I'll be attaching a patch I have that works, but may not be the most efficient approach possible (I'm a newbie to the gnumeric source code). It lets you call ssconvert like this: ssconvert --merge-to=output.xls sheet1.csv sheet2.csv sheet3.csv I thought it would be better to specify the output file explicitly as an option, rather than taking it from the tail of the list of files (which could cause confusion with other usages of ssconvert). The patch is limited to merging input files of the same type.
Created attachment 134116 [details] [review] Patch to allow sheet merging with ssconvert
Thanks. This is very, very interesting. There are some issues that need to be dealt with, though. 1. I am not yet ready to believe that one workbook containing sheets of different sizes actually works. 2. The sheets need to be moved over, not copied, I think. Otherwise, a workbook with two sheets that reference each other will not get there correctly. 3. Moving sheets over will take care of sheet-local names. Something still needs to be done about global names which, of course, can clash. If you have time for this, that would be great. Otherwise we'll have a look eventually.
Thanks for the feedback! > 1. I am not yet ready to believe that one workbook containing sheets of > different sizes actually works. Ah. It seemed to work in my tests, but they weren't particularly demanding. I could easily do a two-pass process to figure out the largest sheet and use that throughout the merged workbook. > 2. The sheets need to be moved over, not copied, I think. Otherwise, a > workbook with two sheets that reference each other will not get there > correctly. That's actually what I tried first, but I couldn't figure out how to take a sheet from one workbook and move it into another. The closest I could get was to clone a sheet and change its workbook pointer, which didn't seem very safe. If you could give me a tip on how to do this right, that would be a big help. I'm just not spotting it, which is why I fell back on copying and pasting. > 3. Moving sheets over will take care of sheet-local names. Something > still needs to be done about global names which, of course, can clash. Ah, right. I could take a shot at this. > If you have time for this, that would be great. Otherwise we'll have a > look eventually. If you can point me in the right direction for moving a sheet, I'd be happy to take another pass at this. Thanks!
No-one ever moved sheets before, but I think we have the pieces we need. A guess: 1. workbook_sheet_delete 2. Change sheet->workbook 3. workbook_sheet_attach_at_pos dependents_revive_sheet
Great, thanks Morten! Wrapped in a g_object_ref/unref of the sheet, that sequence seems to do the job. I'll work on the other issues you raised and submit a revised patch.
Created attachment 134330 [details] [review] Better patch for merging workbooks with ssconvert Improvements in this patch: 1. Output sheets will all be same size (biggest size in any input). 2. Sheets are moved, not copied, using Morten's tip. 3. Because of (2), sheet-local names now work. 4. Workbook-scope names work. Clashes result in an error.
Committed, with changes. Notably we now read the files only once. Could you please have a look at the man page too?
Oh, and thanks for this nice feature! We knew it was needed, but we never got around to doing it.
Created attachment 134462 [details] [review] Patch to ssconvert manpage, describing merge option Added the merge option to synopsis because its usage is quite distinct from the general form.
Thanks Morten! Glad I could help with a utility that has been helping me.
This problem has been fixed in the development version. The fix will be available in the next major software release. Thank you for your bug report.