diff --git a/src/worksheet.c b/src/worksheet.c index cb11b43a..c2ff3bb1 100644 --- a/src/worksheet.c +++ b/src/worksheet.c @@ -615,7 +615,7 @@ _write_formula_num_cell(lxw_worksheet *self, lxw_cell *cell) } /* - * Calculate the "spans" attribute of the tag. This is an XLSX + * Calculate the "spans" attribute of the tag. This is an XLSX * optimisation and isn't strictly required. However, it makes comparing * files easier. * @@ -656,7 +656,7 @@ _calculate_spans(struct lxw_row *row, char *span, int32_t *block_num) * Write out a generic worksheet cell. */ STATIC void -_write_cell(lxw_worksheet *self, lxw_cell *cell) +_write_cell(lxw_worksheet *self, lxw_cell *cell, lxw_format *row_format) { struct xml_attribute_list attributes; struct xml_attribute *attribute; @@ -672,6 +672,11 @@ _write_cell(lxw_worksheet *self, lxw_cell *cell) if (index) _PUSH_ATTRIBUTES_INT("s", index); } + else if (row_format) { + int32_t index = _get_xf_index(row_format); + if (index) + _PUSH_ATTRIBUTES_INT("s", index); + } if (cell->type == STRING_CELL) _PUSH_ATTRIBUTES_STR("t", "s"); @@ -711,17 +716,22 @@ _write_rows(lxw_worksheet *self) TAILQ_FOREACH(row, self->table, list_pointers) { - if ((int32_t) row->row_num / 16 > block_num) - _calculate_spans(row, spans, &block_num); + if (TAILQ_EMPTY(row->cells)) { + /* Row data only. No cells. */ + _write_row(self, row, NULL); + } + else { + /* Row and cell data. */ + if ((int32_t) row->row_num / 16 > block_num) + _calculate_spans(row, spans, &block_num); - if (!TAILQ_EMPTY(row->cells)) { _write_row(self, row, spans); TAILQ_FOREACH(cell, row->cells, list_pointers) { - _write_cell(self, cell); + _write_cell(self, cell, row->format); } + _xml_end_tag(self->file, "row"); } - _xml_end_tag(self->file, "row"); } } diff --git a/test/functional/src/test_row_col_format01.c b/test/functional/src/test_row_col_format01.c new file mode 100644 index 00000000..988fd58d --- /dev/null +++ b/test/functional/src/test_row_col_format01.c @@ -0,0 +1,23 @@ +/***************************************************************************** + * Test cases for libxlsxwriter. + * + * Simple test case to test worksheet set_row() and set_column(). + * + * Copyright 2014, John McNamara, jmcnamara@cpan.org + * + */ + +#include "xlsxwriter.h" + +int main() { + + lxw_workbook *workbook = new_workbook("test_row_col_format01.xlsx"); + lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL); + + lxw_format *bold = workbook_add_format(workbook); + format_set_bold(bold); + + worksheet_set_row(worksheet, 0, 15, bold, NULL); + + return workbook_close(workbook); +} diff --git a/test/functional/src/test_row_col_format02.c b/test/functional/src/test_row_col_format02.c new file mode 100644 index 00000000..7c50b3c9 --- /dev/null +++ b/test/functional/src/test_row_col_format02.c @@ -0,0 +1,25 @@ +/***************************************************************************** + * Test cases for libxlsxwriter. + * + * Simple test case to test worksheet set_row() and set_column(). + * + * Copyright 2014, John McNamara, jmcnamara@cpan.org + * + */ + +#include "xlsxwriter.h" + +int main() { + + lxw_workbook *workbook = new_workbook("test_row_col_format02.xlsx"); + lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL); + + lxw_format *bold = workbook_add_format(workbook); + format_set_bold(bold); + + worksheet_set_row(worksheet, 0, 15, bold, NULL); + + worksheet_write_string(worksheet, 0, 0, "Foo", NULL); + + return workbook_close(workbook); +} diff --git a/test/functional/src/test_row_col_format03.c b/test/functional/src/test_row_col_format03.c new file mode 100644 index 00000000..9a391844 --- /dev/null +++ b/test/functional/src/test_row_col_format03.c @@ -0,0 +1,23 @@ +/***************************************************************************** + * Test cases for libxlsxwriter. + * + * Simple test case to test worksheet set_row() and set_column(). + * + * Copyright 2014, John McNamara, jmcnamara@cpan.org + * + */ + +#include "xlsxwriter.h" + +int main() { + + lxw_workbook *workbook = new_workbook("test_row_col_format03.xlsx"); + lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL); + + lxw_format *italic = workbook_add_format(workbook); + format_set_italic(italic); + + worksheet_set_column(worksheet, 0, 0, 8.43, italic, NULL); + + return workbook_close(workbook); +} diff --git a/test/functional/test_row_col_format.py b/test/functional/test_row_col_format.py new file mode 100644 index 00000000..04121b16 --- /dev/null +++ b/test/functional/test_row_col_format.py @@ -0,0 +1,24 @@ +############################################################################### +# +# Tests for libxlsxwriter. +# +# Copyright (c), 2014, John McNamara, jmcnamara@cpan.org +# + +import base_test_class + +class TestCompareXLSXFiles(base_test_class.XLSXBaseTest): + """ + Test file created with libxlsxwriter against a file created by Excel. + + """ + + def test_row_colformat01(self): + self.run_exe_test('test_row_col_format01') + + def test_row_colformat02(self): + self.run_exe_test('test_row_col_format02') + + # def test_row_colformat03(self): + # self.run_exe_test('test_row_col_format03') + diff --git a/test/functional/xlsx_files/row_col_format01.xlsx b/test/functional/xlsx_files/row_col_format01.xlsx new file mode 100644 index 00000000..8ddfcb74 Binary files /dev/null and b/test/functional/xlsx_files/row_col_format01.xlsx differ diff --git a/test/functional/xlsx_files/row_col_format02.xlsx b/test/functional/xlsx_files/row_col_format02.xlsx new file mode 100644 index 00000000..906659c5 Binary files /dev/null and b/test/functional/xlsx_files/row_col_format02.xlsx differ diff --git a/test/functional/xlsx_files/row_col_format03.xlsx b/test/functional/xlsx_files/row_col_format03.xlsx new file mode 100644 index 00000000..8b182a21 Binary files /dev/null and b/test/functional/xlsx_files/row_col_format03.xlsx differ