After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 581616 - ssconvert from a set of single sheets to a merged workbook
ssconvert from a set of single sheets to a merged workbook
Status: RESOLVED FIXED
Product: Gnumeric
Classification: Applications
Component: General
git master
Other All
: Normal enhancement
: ---
Assigned To: Jody Goldberg
Jody Goldberg
Depends on:
Blocks:
 
 
Reported: 2009-05-06 16:34 UTC by Paul Fitzpatrick
Modified: 2009-05-12 12:38 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch to allow sheet merging with ssconvert (3.17 KB, patch)
2009-05-06 16:36 UTC, Paul Fitzpatrick
none Details | Review
Better patch for merging workbooks with ssconvert (7.11 KB, patch)
2009-05-09 22:47 UTC, Paul Fitzpatrick
committed Details | Review
Patch to ssconvert manpage, describing merge option (922 bytes, patch)
2009-05-12 03:34 UTC, Paul Fitzpatrick
none Details | Review

Description Paul Fitzpatrick 2009-05-06 16:34:45 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.
Comment 1 Paul Fitzpatrick 2009-05-06 16:36:12 UTC
Created attachment 134116 [details] [review]
Patch to allow sheet merging with ssconvert
Comment 2 Morten Welinder 2009-05-06 20:25:35 UTC
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.
Comment 3 Paul Fitzpatrick 2009-05-07 03:11:33 UTC
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!
Comment 4 Morten Welinder 2009-05-07 20:22:19 UTC
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
Comment 5 Paul Fitzpatrick 2009-05-08 04:10:06 UTC
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.
Comment 6 Paul Fitzpatrick 2009-05-09 22:47:46 UTC
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.
Comment 7 Morten Welinder 2009-05-12 00:59:32 UTC
Committed, with changes.  Notably we now read the files only once.

Could you please have a look at the man page too?
Comment 8 Morten Welinder 2009-05-12 01:00:16 UTC
Oh, and thanks for this nice feature!  We knew it was needed, but we never
got around to doing it.
Comment 9 Paul Fitzpatrick 2009-05-12 03:34:41 UTC
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.
Comment 10 Paul Fitzpatrick 2009-05-12 03:39:24 UTC
Thanks Morten! Glad I could help with a utility that has been helping me.
Comment 11 Morten Welinder 2009-05-12 12:38:40 UTC
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.