Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
brechtsanders committed Mar 20, 2016
1 parent bfb105f commit fe07d1a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
5 changes: 5 additions & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
0.1.5

2016-03-20 Brecht Sanders https://github.com/brechtsanders/

* fixed issue with detecting with of columns with NULL data
* chaged with detection to only count first line of multiline data

0.1.4

2016-03-19 Brecht Sanders https://github.com/brechtsanders/
Expand Down
14 changes: 7 additions & 7 deletions examples/example_xlsxio_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ int main (int argc, char* argv[])
//how many rows to buffer to detect column widths
xlsxiowrite_set_detection_rows(handle, 10);
//write column names
xlsxiowrite_add_column(handle, "Col1", 4);
xlsxiowrite_add_column(handle, "Col2", 21);
xlsxiowrite_add_column(handle, "Col3", 12*0);
xlsxiowrite_add_column(handle, "Col4", 2);
xlsxiowrite_add_column(handle, "Col5", 4);
xlsxiowrite_add_column(handle, "Col6", 16);
xlsxiowrite_add_column(handle, "Col7", 10);
xlsxiowrite_add_column(handle, "Col1", 0*4);
xlsxiowrite_add_column(handle, "Col2", 0*21);
xlsxiowrite_add_column(handle, "Col3", 0*12);
xlsxiowrite_add_column(handle, "Col4", 0*2);
xlsxiowrite_add_column(handle, "Col5", 0*4);
xlsxiowrite_add_column(handle, "Col6", 0*16);
xlsxiowrite_add_column(handle, "Col7", 0*10);
xlsxiowrite_next_row(handle);
//write data
int i;
Expand Down
13 changes: 10 additions & 3 deletions lib/xlsxio_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -601,8 +601,15 @@ void write_cell_data (xlsxiowriter handle, const char* rowattr, const char* pref
}
}
//keep track of biggest column width
if (datalen > 0 && datalen > (*handle->pcurrentcolumn)->maxwidth)
(*handle->pcurrentcolumn)->maxwidth = datalen;
if (data) {
//only count first line in multiline data
char* p = strchr(data, '\n');
if (p)
datalen = p - data;
//remember this length if it is the longest one so far
if (datalen > 0 && datalen > (*handle->pcurrentcolumn)->maxwidth)
(*handle->pcurrentcolumn)->maxwidth = datalen;
}
//prepare for the next column
handle->pcurrentcolumn = &(*handle->pcurrentcolumn)->next;
}
Expand Down Expand Up @@ -658,7 +665,7 @@ void flush_buffer (xlsxiowriter handle)
DLL_EXPORT_XLSXIO void xlsxiowrite_set_detection_rows (xlsxiowriter handle, size_t rows)
{
//abort if currently not buffering
if (!handle->rowstobuffer || !handle->sheetopen)
if (!handle->rowstobuffer || handle->sheetopen)
return;
//set number of rows to buffer
handle->rowstobuffer = rows;
Expand Down

0 comments on commit fe07d1a

Please sign in to comment.