From 3b6c52bfe5aae236b3226eecca5e645a1fcb58cd Mon Sep 17 00:00:00 2001 From: Morten Welinder Date: Thu, 10 May 2018 20:02:13 -0400 Subject: [PATCH] ssconvert: enable --export-file-per-sheet for html and latex. Also fix scope of latex savers -- one sheet only. --- NEWS | 1 + plugins/html/html.c | 18 +++++++++++++----- plugins/html/latex.c | 34 +++++++++++++++++++++++----------- plugins/html/plugin.xml.in | 21 ++++++++++++++------- 4 files changed, 51 insertions(+), 23 deletions(-) diff --git a/NEWS b/NEWS index 0e9e87ab7..a6717d2e7 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,7 @@ Morten: * Introspection fixes. * Work around gtk+ breakage re. link colors. * Fix problems with ssconvert --export-file-per-sheet. [#694408] + * Enable --export-file-per-sheet for html and latex. -------------------------------------------------------------------------- Gnumeric 1.12.41 diff --git a/plugins/html/html.c b/plugins/html/html.c index 364487c10..f400c7ad5 100644 --- a/plugins/html/html.c +++ b/plugins/html/html.c @@ -48,6 +48,8 @@ #include #include +#define SHEET_SELECTION_KEY "sheet-selection" + /* * html_version_t: * @@ -694,9 +696,10 @@ static void html_file_save (GOFileSaver const *fs, GOIOContext *io_context, WorkbookView const *wb_view, GsfOutput *output, html_version_t version) { - GSList *sheets, *ptr; Workbook *wb = wb_view_get_workbook (wb_view); GOFileSaveScope save_scope; + GPtrArray *sel; + unsigned ui, count; g_return_if_fail (fs != NULL); g_return_if_fail (wb != NULL); @@ -775,12 +778,17 @@ html_file_save (GOFileSaver const *fs, GOIOContext *io_context, break; } - sheets = workbook_sheets (wb); save_scope = go_file_saver_get_save_scope (fs); - for (ptr = sheets ; ptr != NULL ; ptr = ptr->next) { - write_sheet (output, (Sheet *) ptr->data, version, save_scope); + + sel = g_object_get_data (G_OBJECT (wb), SHEET_SELECTION_KEY); + count = sel ? sel->len : workbook_sheet_count (wb); + for (ui = 0; ui < count; ui++) { + Sheet *sheet = sel + ? g_ptr_array_index (sel, ui) + : workbook_sheet_by_index (wb, ui); + write_sheet (output, sheet, version, save_scope); } - g_slist_free (sheets); + if (version == HTML32 || version == HTML40 || version == XHTML) gsf_output_puts (output, "\n\n"); } diff --git a/plugins/html/latex.c b/plugins/html/latex.c index 0afc47b8c..722b33109 100644 --- a/plugins/html/latex.c +++ b/plugins/html/latex.c @@ -63,6 +63,8 @@ #include #include +#define SHEET_SELECTION_KEY "sheet-selection" + typedef enum { LATEX_NO_BORDER = 0, LATEX_SINGLE_BORDER = 1, @@ -1290,6 +1292,7 @@ void latex_file_save (G_GNUC_UNUSED GOFileSaver const *fs, G_GNUC_UNUSED GOIOContext *io_context, WorkbookView const *wb_view, GsfOutput *output) { + Workbook *wb = wb_view_get_workbook (wb_view); GnmCell *cell; Sheet *current_sheet; GnmRange total_range; @@ -1299,9 +1302,13 @@ latex_file_save (G_GNUC_UNUSED GOFileSaver const *fs, G_GNUC_UNUSED GOIOContext GnmStyleBorderType *clines, *this_clines; GnmStyleBorderType *prev_vert = NULL, *next_vert = NULL, *this_vert; gboolean needs_hline; + GPtrArray *sel; - /* Get the topmost sheet and its range from the plugin function argument. */ - current_sheet = wb_view_cur_sheet(wb_view); + /* Get the sheet and its range from the plugin function argument. */ + sel = g_object_get_data (G_OBJECT (wb), SHEET_SELECTION_KEY); + current_sheet = sel && sel->len + ? g_ptr_array_index (sel, 0) + : wb_view_cur_sheet(wb_view); total_range = file_saver_sheet_get_extent (current_sheet); /* This is the preamble of the LaTeX2e file. */ @@ -1551,7 +1558,7 @@ latex2e_table_write_file_header(GsfOutput *output) } /** - * latex_table_file_save : The LaTeX2e exporter plugin function. + * latex_table_file_save_impl : The LaTeX2e exporter plugin function. * * @WorkbookView: this provides the way to access the sheet being exported. * @outpu: where we'll write. @@ -1563,16 +1570,21 @@ latex2e_table_write_file_header(GsfOutput *output) static void latex_table_file_save_impl (WorkbookView const *wb_view, GsfOutput *output, gboolean all) { + Workbook *wb = wb_view_get_workbook (wb_view); GnmCell *cell; Sheet *current_sheet; GnmRange total_range; int row, col; + GPtrArray *sel; /* This is the preamble of the LaTeX2e file. */ latex2e_table_write_file_header(output); - /* Get the topmost sheet and its range from the plugin function argument. */ - current_sheet = wb_view_cur_sheet(wb_view); + /* Get the sheet and its range from the plugin function argument. */ + sel = g_object_get_data (G_OBJECT (wb), SHEET_SELECTION_KEY); + current_sheet = sel && sel->len + ? g_ptr_array_index (sel, 0) + : wb_view_cur_sheet(wb_view); total_range = file_saver_sheet_get_extent (current_sheet); /* Step through the sheet, writing cells as appropriate. */ @@ -1609,8 +1621,8 @@ latex_table_file_save_impl (WorkbookView const *wb_view, GsfOutput *output, gboo * @WorkbookView: this provides the way to access the sheet being exported. * @output: where we'll write. * - * This writes the top sheet of a Gnumeric workbook as the content of a latex table environment. - * We try to avoid all formatting. + * This writes the selected sheet of a Gnumeric workbook as the content of a + * latex table environment. We try to avoid all formatting. */ void latex_table_file_save (G_GNUC_UNUSED GOFileSaver const *fs, @@ -1628,13 +1640,13 @@ latex_table_file_save (G_GNUC_UNUSED GOFileSaver const *fs, * @WorkbookView: this provides the way to access the sheet being exported. * @output: where we'll write. * - * This writes the top sheet of a Gnumeric workbook as the content of a latex table environment. - * We try to avoid all formatting. + * This writes the selected sheet of a Gnumeric workbook as the content of a + * latex table environment. We try to avoid all formatting. */ void latex_table_visible_file_save (G_GNUC_UNUSED GOFileSaver const *fs, - G_GNUC_UNUSED GOIOContext *io_context, - WorkbookView const *wb_view, GsfOutput *output) + G_GNUC_UNUSED GOIOContext *io_context, + WorkbookView const *wb_view, GsfOutput *output) { latex_table_file_save_impl (wb_view, output, FALSE); } diff --git a/plugins/html/plugin.xml.in b/plugins/html/plugin.xml.in index 9d49ff354..7016237d5 100644 --- a/plugins/html/plugin.xml.in +++ b/plugins/html/plugin.xml.in @@ -17,22 +17,26 @@ htm - + <_description>HTML 3.2 (*.html) - + <_description>HTML 4.0 (*.html) - + <_description>HTML (*.html) fragment - + <_description>XHTML (*.html) @@ -44,17 +48,20 @@ <_description>XHTML range - for export to clipboard - + <_description>LaTeX 2e (*.tex) - + <_description>LaTeX 2e (*.tex) table fragment - + <_description>LaTeX 2e (*.tex) table fragment of visible rows -- 2.11.4.GIT