From f008507901a3aaa391eb22e952bb2b6b2f0ae42b Mon Sep 17 00:00:00 2001 From: Brecht Sanders Date: Sat, 25 May 2024 18:04:42 +0200 Subject: [PATCH] - --- Changelog.txt | 19 ++++++++++++------- include/xlsxio_version.h | 2 +- src/xlsxio_xlsx2csv.c | 31 ++++++++++--------------------- 3 files changed, 23 insertions(+), 29 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 6abab18..58f46db 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,3 +1,8 @@ +0.2.36 + + * fixed CMakeLists.txt to use EXPAT_INCLUDE_DIR instead of EXPAT_INCLUDE_DIRS (#108) + * added -u option to xlsxio_xlsx2csv to use sheet numbers instead of sheet names (#118) + 0.2.35 2023-08-03 Brecht Sanders https://github.com/brechtsanders/ @@ -49,15 +54,15 @@ 2020-12-29 Viest https://github.com/viest * added XLSXIOREAD_SKIP_HIDDEN_ROWS to xlsxio_read.h, skipping hidden rows is no longer the default setting - + 2020-12-29 akuhtr https://github.com/akuhtr * fixed example in README.md to use xlsxioread_free() instead of free() - + 2020-07-12 Remi Collet https://github.com/remicollet * added XLSXIO_VERSION_ID to xlsxio_version.h - + 0.2.29 2020-07-10 Brecht Sanders https://github.com/brechtsanders/ @@ -145,7 +150,7 @@ 2018-06-18 Brecht Sanders https://github.com/brechtsanders/ * fixed crash in xlsx_read.c when XML_Char_openzip is called with empty filename (crash reported by Matthew James Briggs) - + 2018-05-17 Brecht Sanders https://github.com/brechtsanders/ * fixed memory allocation issue when using minizip version of xlsx_read @@ -155,7 +160,7 @@ 2018-04-27 Brecht Sanders https://github.com/brechtsanders/ * fixed formatting issue with cell coordinates - + 0.2.17 2018-03-22 Brecht Sanders https://github.com/brechtsanders/ @@ -167,7 +172,7 @@ 2018-03-18 Brecht Sanders https://github.com/brechtsanders/ * fixed formatting issue with cell coordinates - + 0.2.15 2018-03-18 Brecht Sanders https://github.com/brechtsanders/ @@ -295,7 +300,7 @@ 2016-05-05 Brecht Sanders https://github.com/brechtsanders/ * added CMake BUILD_DOCUMENTATION option (defaults to ON if Doxygen is detected) - * workaround for missing stdint.h/unistd.h on Visual C + * workaround for missing stdint.h/unistd.h on Visual C * removed -pthread when building for Apple * released Windows binaries (32-bit and 64-bit) diff --git a/include/xlsxio_version.h b/include/xlsxio_version.h index eb07707..c742279 100644 --- a/include/xlsxio_version.h +++ b/include/xlsxio_version.h @@ -49,7 +49,7 @@ THE SOFTWARE. /*! \brief minor version number */ #define XLSXIO_VERSION_MINOR 2 /*! \brief micro version number */ -#define XLSXIO_VERSION_MICRO 35 +#define XLSXIO_VERSION_MICRO 36 /*! @} */ /*! \cond PRIVATE */ diff --git a/src/xlsxio_xlsx2csv.c b/src/xlsxio_xlsx2csv.c index d10a650..d7af940 100644 --- a/src/xlsxio_xlsx2csv.c +++ b/src/xlsxio_xlsx2csv.c @@ -31,8 +31,8 @@ struct xlsx_data { xlsxioreader xlsxioread; FILE* dst; int nobom; - int numbers; - int file_count; + int sheetnumbers; + int sheetcount; const char* newline; char separator; char quote; @@ -78,28 +78,17 @@ int xlsx_list_sheets_callback (const char* name, void* callbackdata) char* filename; struct xlsx_data* data = (struct xlsx_data*)callbackdata; //determine output file - if ((filename = (char*)malloc(strlen(data->filename) + strlen(name) + 6)) == NULL ){ + if ((filename = (char*)malloc(strlen(data->filename) + (data->sheetnumbers ? 16 : strlen(name)) + 6)) == NULL ){ fprintf(stderr, "Memory allocation error\n"); } else { - - char str[16]; - - if (data->numbers) - { - //Vs writing the sheetname, this will write the number of the sheet ! - snprintf(str, sizeof(str), "%d", data->file_count++); - } - - - + data->sheetcount++; //determine export filename strcpy(filename, data->filename); strcat(filename, "."); - if (data->numbers) - strcat(filename, str); + if (data->sheetnumbers) + itoa(data->sheetcount, filename + strlen(filename), 10); else strcat(filename, name); - strcat(filename, ".csv"); //display status printf("Sheet found: %s, exporting to: %s\n", name, filename); @@ -130,7 +119,7 @@ void show_help () " -s separator\tspecify separator to use (default is comma)\n" " -b \tdon't write UTF-8 BOM signature\n" " -n \tuse UNIX style line breaks\n" - " -u \toutput sheet number instead of sheet name\n" + " -u \tuse sheet number in output file name (instead of sheet name)\n" " xlsxfile \tpath to .xlsx file (multiple may be specified)\n" "Description:\n" "Converts all sheets in all specified .xlsx files to individual CSV (Comma Separated Values) files.\n" @@ -146,8 +135,8 @@ int main (int argc, char* argv[]) xlsxioreader xlsxioread; struct xlsx_data sheetdata = { .nobom = 0, - .numbers = 0, - .file_count = 1, + .sheetnumbers = 0, + .sheetcount = 0, .newline = "\r\n", .separator = ',', .quote = '"', @@ -179,7 +168,7 @@ int main (int argc, char* argv[]) sheetdata.nobom = 1; continue; case 'u' : - sheetdata.numbers = 1; + sheetdata.sheetnumbers = 1; continue; case 'n' : sheetdata.newline = "\n";