informationsea / xlsxwriter-rs

Excel file writer for Rust
https://crates.io/crates/xlsxwriter
Apache License 2.0
265 stars 44 forks source link

Invalid xlsx files generated with some locales #35

Closed birktj closed 1 year ago

birktj commented 1 year ago

I was recently hit by this issue: https://github.com/jmcnamara/libxlsxwriter/issues/64. The problem is that libxlsxwirter uses sprintf by default which formats decimal numbers in a locale-dependent way, resulting in invalid xlsx files on locales which uses comma as a decimal separator. This is a very confusing problem, as the spreadsheet application I was using (libreoffice calc) did throw any errors on the invalid files, but instead only parses the integer portion of the numbers. Also note that the issue only arises if setlocale is called, possibly in some external library (for me it was possibly gtk?)

A simple solution to solve this problem is to set LC_NUMERIC to C early in main with something like this:

std::env::set_var("LC_NUMERIC", "C");

However it would be preferable to compile libxlsxwriter with USE_DTOA_LIBRARY in order for it to use a locale-independent function. This flag was introduced in https://github.com/jmcnamara/libxlsxwriter/issues/272 and is documented here.