Initial work on row/col formatting.

This commit is contained in:
John McNamara 2014-06-17 01:08:21 +01:00
parent dc79221163
commit 3b35214983
8 changed files with 112 additions and 7 deletions

View File

@ -615,7 +615,7 @@ _write_formula_num_cell(lxw_worksheet *self, lxw_cell *cell)
}
/*
* Calculate the "spans" attribute of the <row> tag. This is an XLSX
* Calculate the "spans" attribute of the <row> 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");
}
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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')

Binary file not shown.

Binary file not shown.

Binary file not shown.