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 d9482a3 commit d6e212a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
6 changes: 1 addition & 5 deletions build/xlsxio_xlsx2csv.cbp
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@
<Unit filename="../src/xlsxio_xlsx2csv.c">
<Option compilerVar="CC" />
</Unit>
<Extensions>
<code_completion />
<envvars />
<debugger />
</Extensions>
<Extensions />
</Project>
</CodeBlocks_project_file>
2 changes: 1 addition & 1 deletion build/xlsxio_xlsx2csv.depend
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

1544956328 \\server\users\brecht\sources\cpp\xlsxio\include\xlsxio_version.h

1716652262 source:z:\xlsxio\src\xlsxio_xlsx2csv.c
1716653912 source:z:\xlsxio\src\xlsxio_xlsx2csv.c
<stdlib.h>
<stdio.h>
<string.h>
Expand Down
18 changes: 8 additions & 10 deletions src/xlsxio_xlsx2csv.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ struct xlsx_data {
FILE* dst;
int nobom;
int sheetnumbers;
int sheetcount;
const char* newline;
char separator;
char quote;
const char* filename;
unsigned int sheetcount;
};

int sheet_row_callback (size_t row, size_t maxcol, void* callbackdata)
Expand Down Expand Up @@ -77,19 +77,17 @@ int xlsx_list_sheets_callback (const char* name, void* callbackdata)
{
char* filename;
struct xlsx_data* data = (struct xlsx_data*)callbackdata;
size_t filenamelen = strlen(data->filename) + (data->sheetnumbers ? 16 : strlen(name)) + 6;
data->sheetcount++;
//determine output file
if ((filename = (char*)malloc(strlen(data->filename) + (data->sheetnumbers ? 16 : strlen(name)) + 6)) == NULL ){
if ((filename = (char*)malloc(filenamelen)) == NULL) {
fprintf(stderr, "Memory allocation error\n");
} else {
data->sheetcount++;
//determine export filename
strcpy(filename, data->filename);
strcat(filename, ".");
if (data->sheetnumbers)
itoa(data->sheetcount, filename + strlen(filename), 10);
else
strcat(filename, name);
strcat(filename, ".csv");
snprintf(filename, filenamelen, "%s.%u.csv", data->filename, data->sheetcount);
else
snprintf(filename, filenamelen, "%s.%s.csv", data->filename, name);
//display status
printf("Sheet found: %s, exporting to: %s\n", name, filename);
//open output file
Expand Down Expand Up @@ -136,7 +134,6 @@ int main (int argc, char* argv[])
struct xlsx_data sheetdata = {
.nobom = 0,
.sheetnumbers = 0,
.sheetcount = 0,
.newline = "\r\n",
.separator = ',',
.quote = '"',
Expand Down Expand Up @@ -179,6 +176,7 @@ int main (int argc, char* argv[])
if ((xlsxioread = xlsxioread_open(argv[i])) != NULL) {
sheetdata.xlsxioread = xlsxioread;
sheetdata.filename = argv[i];
sheetdata.sheetcount = 0;
//iterate through available sheets
printf("Processing file: %s\n", argv[i]);
xlsxioread_list_sheets(xlsxioread, xlsx_list_sheets_callback, &sheetdata);
Expand Down

0 comments on commit d6e212a

Please sign in to comment.