tfussell / xlnt

:bar_chart: Cross-platform user-friendly xlsx library for C++11+
Other
1.43k stars 402 forks source link

When string tables entries exceed 1000, a ',' is being inserted in the string table number, resulting in errors opening file #721

Open gavin-blakeman opened 7 months ago

gavin-blakeman commented 7 months ago

When a worksheet with a large number of string is created, once the string index (number) rolls over to 1000, a 'c' is inserted to the number when it is written to the XML file.

999 1,000

Excel opens with an error and truncates data. LibreOffice uses the wrong string (Uses 1 and ignores the rest of the value)

Without looking at the code, I suspect this is due to the stream being imbued with a locale that then adds the thousands separator to the number when the number is converted to text.

gavin-blakeman commented 7 months ago

Update: A work around is to ensure that the global locale is setup with a facet that does not implement thousands separators.

I used this link on stack overflow to create a solution. https://stackoverflow.com/questions/10685229/use-local-decimal-separator-but-not-grouping-character-with-stringstream

class no_separator : public std::numpunct_byname { protected: virtual string_type do_grouping() const { return "\000"; } // groups of 0 (disable) public: no_separator() : numpunct_byname(""){} };

std::locale loc(std::locale(""), new no_separator); std::locale::global(loc);