From 8ef344a3195c45f2d9cee024fe946418a1a90db0 Mon Sep 17 00:00:00 2001 From: "V. Guruprasad" Date: Tue, 17 Dec 2024 06:48:06 -0500 Subject: [PATCH] command option to export to xlsx --- src/doc | 3 ++- src/help.c | 1 + src/main.c | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/doc b/src/doc index 6ab07f1f..63d0fb8b 100755 --- a/src/doc +++ b/src/doc @@ -1947,10 +1947,11 @@ Commands for handling cell content: You can set the --quiet parameter to avoid printing messages of all kinds (info, error or debug). - Export to csv, tab, markdown or plain text formats without interaction: + Export to csv, tab, markdown, xlsx or plain text formats without interaction: ./sc-im --quit_afterload --nocurses --export_csv ./sc-im --quit_afterload --nocurses --export_tab ./sc-im --quit_afterload --nocurses --export_mkd + ./sc-im --quit_afterload --nocurses --export_xlsx ./sc-im --quit_afterload --nocurses --export_txt # (or just --export) If you set the --quit_afterload flag, sc-im will quit after loading all diff --git a/src/help.c b/src/help.c index 6cb6b547..ec60efd2 100644 --- a/src/help.c +++ b/src/help.c @@ -572,6 +572,7 @@ void show_usage_and_quit(){ \n --export_tab Export to tab without interaction\ \n --export_txt Export to txt without interaction\ \n --export_mkd Export to markdown without interaction\ +\n --export_xlsx Export to xlsx without interaction\ \n --external_functions Set variable 'external_functions'\ \n --half_page_scroll Set variable 'half_page_scroll'\ \n --ignorecase Set variable 'ignorecase'\ diff --git a/src/main.c b/src/main.c index 945803da..87447a67 100644 --- a/src/main.c +++ b/src/main.c @@ -579,6 +579,21 @@ void handle_argv_exports() { export_markdown(NULL, 0, 0, session->cur_doc->cur_sh->maxrow, session->cur_doc->cur_sh->maxcol); } + if (get_conf_value("export_xlsx") && session->cur_doc != NULL) { +#ifndef XLSX_EXPORT + sc_error("XLSX export support not compiled in. Please save file in other extension."); + return -1; +#else + char * curfile = session->cur_doc->name; + char name[BUFFERSIZE]; + strcpy(name, curfile); + if (!strcasecmp(&name[strlen(name)-3], ".sc") && strlen(name)+5 < BUFFERSIZE) { + strcpy(&name[strlen(name)-3], ".xlsx"); + export_xlsx(name); + } +#endif + } + if ((get_conf_value("export") || get_conf_value("export_txt")) && session->cur_doc != NULL) { export_plain(NULL, 0, 0, session->cur_doc->cur_sh->maxrow, session->cur_doc->cur_sh->maxcol); }