[gnumeric] ssconvert: add ability to change a cell value.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] ssconvert: add ability to change a cell value.
- Date: Thu, 14 Nov 2019 00:37:09 +0000 (UTC)
commit bf91d2f454732f21ed2e1b6bfbfa7b81494392a0
Author: Morten Welinder <terra gnome org>
Date: Wed Nov 13 19:36:18 2019 -0500
ssconvert: add ability to change a cell value.
NEWS | 1 +
doc/ssconvert.1 | 5 +++++
src/ssconvert.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 68 insertions(+)
---
diff --git a/NEWS b/NEWS
index 8bb069dee..de5ea7c12 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,7 @@ Gnumeric 1.12.47
Morten:
* Fix dialog size problem.
+ * Add "--set CELL=CONTENTS" option to ssconvert.
--------------------------------------------------------------------------
Gnumeric 1.12.46
diff --git a/doc/ssconvert.1 b/doc/ssconvert.1
index 5763ede94..12b3aa2a4 100644
--- a/doc/ssconvert.1
+++ b/doc/ssconvert.1
@@ -31,6 +31,11 @@ starting with two dashes (`--').
.B \-\-recalc
Recalculate all cells before writing the result.
.TP
+.B \-\-set \fICELL=CONTENTS\fR
+Set the value of \fICELL\fR to \fICONTENTS\fR. Implies --recalc. To
+put an expression in a cell, add an extra =, for example \-\-set "A11==A10+1".
+This option may be repeated as many times as needed.
+.TP
.B \-v, \-\-verbose
Be slightly more verbose about what is going on.
.TP
diff --git a/src/ssconvert.c b/src/ssconvert.c
index 612840f74..235586661 100644
--- a/src/ssconvert.c
+++ b/src/ssconvert.c
@@ -66,6 +66,7 @@ static char *ssconvert_import_id = NULL;
static char *ssconvert_export_id = NULL;
static char *ssconvert_export_options = NULL;
static char *ssconvert_merge_target = NULL;
+static char **ssconvert_set_cells = NULL;
static char **ssconvert_goal_seek = NULL;
static char **ssconvert_tool_test = NULL;
static const char *ssconvert_image_format = "svg";
@@ -152,6 +153,13 @@ static const GOptionEntry ssconvert_options [] = {
NULL
},
+ {
+ "set", 0,
+ 0, G_OPTION_ARG_STRING_ARRAY, &ssconvert_set_cells,
+ N_("Change the contents of a cell before writing --set A12=2"),
+ NULL
+ },
+
{
"recalc", 0,
0, G_OPTION_ARG_NONE, &ssconvert_recalc,
@@ -412,6 +420,7 @@ read_files_to_merge (const char *inputs[], GOFileOpener *fo,
WorkbookView *wbv =
workbook_view_new_from_uri (uri, fo, io_context,
ssconvert_import_encoding);
+ // Do not apply any changes
g_free (uri);
inputs++;
@@ -883,6 +892,48 @@ do_split_save (GOFileSaver *fs, WorkbookView *wbv,
return res;
}
+static int
+apply_updates (WorkbookView *wbv)
+{
+ Workbook *wb = wb_view_get_workbook (wbv);
+ unsigned ui;
+ GnmParsePos pp;
+
+ pp.wb = wb;
+ pp.sheet = workbook_sheet_by_index (wb, 0);
+ pp.eval.col = 0;
+ pp.eval.row = 0;
+
+ for (ui = 0; ssconvert_set_cells[ui]; ui++) {
+ const char *s = ssconvert_set_cells[ui];
+ const char *eq;
+ GnmRangeRef rr;
+ GnmRange r;
+ GnmParsePos pp2;
+ Sheet *start_sheet, *end_sheet;
+
+ eq = rangeref_parse (&rr, s, &pp, gnm_conventions_default);
+ if (!eq || *eq != '=')
+ goto error;
+
+ parse_pos_init_sheet (&pp2, wb_view_cur_sheet (wbv));
+ gnm_rangeref_normalize_pp (&rr, &pp2,
+ &start_sheet, &end_sheet,
+ &r);
+
+ pp2.eval.col = r.start.col;
+ pp2.eval.row = r.start.row;
+ sheet_range_set_text (&pp2, &r, eq + 1);
+ continue;
+
+ error:
+ g_printerr (_("Failed to set cell %s\n"), s);
+ return 1;
+ }
+
+ return 0;
+}
+
static int
convert (char const *inarg, char const *outarg, char const *mergeargs[],
GOCmdContext *cc)
@@ -968,6 +1019,10 @@ convert (char const *inarg, char const *outarg, char const *mergeargs[],
wbv = workbook_view_new_from_uri (infile, fo,
io_context,
ssconvert_import_encoding);
+ if (apply_updates (wbv)) {
+ res = 1;
+ goto out;
+ }
} else {
wbv = workbook_view_new (NULL);
}
@@ -1118,6 +1173,10 @@ clipboard_export (const char *inarg, char const *outarg, GOCmdContext *cc)
wbv = workbook_view_new_from_uri (infile, fo,
io_context,
ssconvert_import_encoding);
+ if (apply_updates (wbv)) {
+ res = 1;
+ goto out;
+ }
if (go_io_error_occurred (io_context)) {
go_io_error_display (io_context);
@@ -1219,6 +1278,9 @@ main (int argc, char const **argv)
return 1;
}
+ if (ssconvert_set_cells && ssconvert_set_cells[0])
+ ssconvert_recalc = TRUE; // Implied
+
if (ssconvert_object_export) {
// One file per object
ssconvert_one_file_per_sheet = TRUE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]