Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
brechtsanders committed May 25, 2024
1 parent fd58301 commit f008507
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 29 deletions.
19 changes: 12 additions & 7 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -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/
Expand Down Expand Up @@ -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/
Expand Down Expand Up @@ -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
Expand All @@ -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/
Expand All @@ -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/
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion include/xlsxio_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
31 changes: 10 additions & 21 deletions src/xlsxio_xlsx2csv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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"
Expand All @@ -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 = '"',
Expand Down Expand Up @@ -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";
Expand Down

0 comments on commit f008507

Please sign in to comment.