brechtsanders / xlsxio

XLSX I/O - C library for reading and writing .xlsx files
MIT License
417 stars 112 forks source link

Current locale can corrupt the xlsx-file #45

Open Maxxan opened 5 years ago

Maxxan commented 5 years ago

If the application uses the static library and set the locale to use a comma instead of a dot for decimals, then the formatting in the xlsxio will produce corrupt xlsx-files since for example the width of the columns will be "19,5" instead of "19.5".

So formatting should use the a locale that gives a decimal dot. Either set the locale and restore the old one when done saving or use a format function that takes a locale as a parameter.

brechtsanders commented 5 years ago

Your point makes sense. I couldn't reproduce it here right away though. Which platform and which locale setting did you use?

I looked into sprintf_l but that doesn't seem to exist on all platforms. Which function do you propose?

Maxxan commented 5 years ago

An easy way to reproduce it is to use setlocale when opening the excel file (start writing) and set it to a locale that uses a decimal comma like std::setlocale(LC_NUMERIC, "de_DE.UTF-8");. I don't know what is the best way to solve it though. Same with fprintf_l, might not exist for all platforms.

ghost commented 4 years ago

I have exactly the same problem (france). I guess that a simple way to solve it is to compile the library by setting

define CALCULATE_COLUMN_HEIGHT(characters) ((double)characters * 13) instead of 12.75 in xlsxio_write.c and avoid the decimal numbers in the width and height of the columns/rows.

Thank you brechtsanders for this nice library