[gnumeric] ssconvert: add active-sheet export option.



commit caf80ea5848c804991cec76ea37b52ee93be7377
Author: Morten Welinder <terra gnome org>
Date:   Tue Apr 9 20:18:17 2019 -0400

    ssconvert: add active-sheet export option.

 ChangeLog       |  3 +++
 NEWS            |  1 +
 doc/ssconvert.1 | 17 +++++++++++++----
 src/gutils.c    | 28 +++++++++++++++++++---------
 4 files changed, 36 insertions(+), 13 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 07a2b6fba..6e73d5baf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2019-04-09  Morten Welinder  <terra gnome org>
 
+       * src/gutils.c (gnm_file_saver_common_export_option): Allow option
+       "active-sheet=" to select the active sheet.
+
        * src/stf-parse.c (stf_parse_options_guess_csv): Avoid guessing
        insane separators.  Fixes #397.
 
diff --git a/NEWS b/NEWS
index 6ddd66662..d27978b7f 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,7 @@ Morten:
        * Add DIGAMMA function.
        * Support ISO-8601 UTC date/time input.  Mostly.  [#371]
        * Improve cvs separator guessing.  [#397]
+       * Add export option "active-sheet".  [#396]
 
 Thomas Klausner:
        * Fix compilation issue.  [#378]
diff --git a/doc/ssconvert.1 b/doc/ssconvert.1
index b325e51f4..5763ede94 100644
--- a/doc/ssconvert.1
+++ b/doc/ssconvert.1
@@ -69,7 +69,7 @@ workbook.  The merge will be aborted if there are name conflicts.
 Export a file for each sheet if the exporter only supports one sheet at a
 time.  The output filename is treated as a template in which sheet number
 is substituted for %n and/or sheet name is substituted for %s.  If there
-are not substitutions, a default of ".%s" is added.
+are no substitutions, a default of ".%s" is added.
 
 .SS "Help options"
 .TP
@@ -230,10 +230,14 @@ Mixed Integer Linear Programming (MILP) solver
 .TP
 .B sheet
 Name of the workbook sheet to operate on.
-You can specify several sheets by repeating this option. If this option is not given the active
-sheet (i. e. the sheet that was active when the file was saved) is used.
+You can specify several sheets by repeating this option.
 This is ignored if the \fBobject\fR option is given.
 
+.TP
+.B active-sheet
+Select the active sheet to operate on.  The value for this option is
+irrelevant, but the equal sign is mandatory.
+
 .TP
 .B object
 Name of the sheet object to print. If this option is given any \fBsheet\fR option is ignored.
@@ -255,7 +259,12 @@ size of the graph.
 .TP
 .B sheet
 Name of the workbook sheet to operate on.
-You can specify several sheets by repeating this option. If this option is not given, all sheets are 
selected.
+You can specify several sheets by repeating this option.
+
+.TP
+.B active-sheet
+Select the active sheet to operate on.  The value for this option is
+irrelevant, but the equal sign is mandatory.
 
 .TP
 .B eol
diff --git a/src/gutils.c b/src/gutils.c
index 0560687ff..18031f659 100644
--- a/src/gutils.c
+++ b/src/gutils.c
@@ -17,6 +17,7 @@
 #include <mathfunc.h>
 #include <workbook-view.h>
 #include <workbook.h>
+#include <workbook-priv.h>
 
 #include <goffice/goffice.h>
 
@@ -951,16 +952,25 @@ gnm_file_saver_common_export_option (GOFileSaver const *fs,
        g_return_val_if_fail (key != NULL, FALSE);
        g_return_val_if_fail (value != NULL, FALSE);
 
-       if (strcmp (key, "sheet") == 0) {
+       if (strcmp (key, "sheet") == 0 ||
+           strcmp (key, "active-sheet") == 0) {
                GPtrArray *sheets;
-               Sheet *sheet = workbook_sheet_by_name (wb, value);
-
-               if (!sheet) {
-                       if (err)
-                               *err = g_error_new (go_error_invalid (), 0,
-                                                   _("Unknown sheet \"%s\""),
-                                                   value);
-                       return TRUE;
+               Sheet *sheet;
+
+               if (key[0] == 'a') {
+                       // Not ideal -- we lack a view here
+                       WORKBOOK_FOREACH_VIEW (wb, wbv, {
+                                       sheet = wb_view_cur_sheet (wbv);
+                               });
+               } else {
+                       sheet = workbook_sheet_by_name (wb, value);
+                       if (!sheet) {
+                               if (err)
+                                       *err = g_error_new (go_error_invalid (), 0,
+                                                           _("Unknown sheet \"%s\""),
+                                                           value);
+                               return TRUE;
+                       }
                }
 
                sheets = g_object_get_data (G_OBJECT (wb), SSCONVERT_SHEET_SET_KEY);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]