mirror of
https://github.com/jmcnamara/libxlsxwriter
synced 2025-03-28 21:13:14 +00:00
parent
f44f25aa6f
commit
84dd312e79
1
.gitignore
vendored
1
.gitignore
vendored
@ -20,6 +20,7 @@ TAGS
|
||||
*.bak
|
||||
!test/functional/xlsx_files/*.xlsx
|
||||
*.pyc
|
||||
.pytest_cache/
|
||||
.cproject
|
||||
.project
|
||||
.pydevproject
|
||||
|
@ -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");
|
||||
|
@ -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++;
|
||||
|
40
test/functional/src/test_format51.c
Normal file
40
test/functional/src/test_format51.c
Normal 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);
|
||||
}
|
60
test/functional/src/test_format52.c
Normal file
60
test/functional/src/test_format52.c
Normal 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);
|
||||
}
|
@ -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')
|
||||
|
BIN
test/functional/xlsx_files/format51.xlsx
Normal file
BIN
test/functional/xlsx_files/format51.xlsx
Normal file
Binary file not shown.
BIN
test/functional/xlsx_files/format52.xlsx
Normal file
BIN
test/functional/xlsx_files/format52.xlsx
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user