Fix for issue when hashing number formats.

Issue #203
This commit is contained in:
John McNamara 2018-10-30 23:16:32 +00:00
parent f44f25aa6f
commit 84dd312e79
8 changed files with 115 additions and 1 deletions

1
.gitignore vendored
View File

@ -20,6 +20,7 @@ TAGS
*.bak
!test/functional/xlsx_files/*.xlsx
*.pyc
.pytest_cache/
.cproject
.project
.pydevproject

View File

@ -155,6 +155,7 @@ _write_num_fmts(lxw_styles *self)
struct xml_attribute_list attributes;
struct xml_attribute *attribute;
lxw_format *format;
uint16_t last_format_index = 0;
if (!self->num_format_count)
return;
@ -171,7 +172,13 @@ _write_num_fmts(lxw_styles *self)
if (format->num_format_index < 164)
continue;
/* Ignore duplicates which have an already used index. */
if (format->num_format_index <= last_format_index)
continue;
_write_num_fmt(self, format->num_format_index, format->num_format);
last_format_index = format->num_format_index;
}
lxw_xml_end_tag(self->file, "numFmts");

View File

@ -471,7 +471,7 @@ _prepare_num_formats(lxw_workbook *self)
num_format_index = calloc(1, sizeof(uint16_t));
*num_format_index = index;
format->num_format_index = index;
lxw_insert_hash_element(num_formats, num_format,
lxw_insert_hash_element(num_formats, format->num_format,
num_format_index,
LXW_FORMAT_FIELD_LEN);
index++;

View File

@ -0,0 +1,40 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Simple test case to test data writing.
*
* Copyright 2014-2018, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = workbook_new("test_format51.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
lxw_format *format;
double value = 123.456;
worksheet_set_column(worksheet, 0, 0, 12, NULL);
format = workbook_add_format(workbook);
format_set_num_format(format, "0.0");
worksheet_write_number(worksheet, 0, 0, value, format);
format = workbook_add_format(workbook);
format_set_num_format(format, "0.000");
worksheet_write_number(worksheet, 1, 0, value, format);
format = workbook_add_format(workbook);
format_set_num_format(format, "0.0000");
worksheet_write_number(worksheet, 2, 0, value, format);
format = workbook_add_format(workbook);
format_set_num_format(format, "0.00000");
worksheet_write_number(worksheet, 3, 0, value, format);
return workbook_close(workbook);
}

View File

@ -0,0 +1,60 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Simple test case to test data writing.
*
* Copyright 2014-2018, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = workbook_new("test_format52.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
lxw_format *format;
double value = 123.456;
worksheet_set_column(worksheet, 0, 0, 12, NULL);
format = workbook_add_format(workbook);
format_set_num_format(format, "0.0");
worksheet_write_number(worksheet, 0, 0, value, format);
format = workbook_add_format(workbook);
format_set_num_format(format, "0.000");
worksheet_write_number(worksheet, 1, 0, value, format);
format = workbook_add_format(workbook);
format_set_num_format(format, "0.0000");
worksheet_write_number(worksheet, 2, 0, value, format);
format = workbook_add_format(workbook);
format_set_num_format(format, "0.00000");
worksheet_write_number(worksheet, 3, 0, value, format);
format = workbook_add_format(workbook);
format_set_num_format(format, "0.0");
format_set_bold(format);
worksheet_write_number(worksheet, 4, 0, value, format);
format = workbook_add_format(workbook);
format_set_num_format(format, "0.000");
format_set_bold(format);
worksheet_write_number(worksheet, 5, 0, value, format);
format = workbook_add_format(workbook);
format_set_num_format(format, "0.0000");
format_set_bold(format);
worksheet_write_number(worksheet, 6, 0, value, format);
format = workbook_add_format(workbook);
format_set_num_format(format, "0.00000");
format_set_bold(format);
worksheet_write_number(worksheet, 7, 0, value, format);
return workbook_close(workbook);
}

View File

@ -39,3 +39,9 @@ class TestCompareXLSXFiles(base_test_class.XLSXBaseTest):
def test_format50(self):
self.run_exe_test('test_format50')
def test_format51(self):
self.run_exe_test('test_format51')
def test_format52(self):
self.run_exe_test('test_format52')

Binary file not shown.

Binary file not shown.