firegloves / MemPOI

A library to simplify export from database to Excel files using Apache POI :japanese_goblin:
MIT License
57 stars 7 forks source link

Integer values are formatted with decimals in Excel result #4

Closed lbruun closed 4 years ago

lbruun commented 4 years ago

Describe the bug From a cellstyle perspective MemPOI doesn't seem to differentiate between SQL columns of integer type and SQL columns that can hold decimals. This is unfortunate.

To Reproduce I use a PostgreSQL table which has a column of type SMALLINT. The values in this column gets formatted in the resulting Excel sheet with visible decimals, i.e. 15.00 as opposed to just 15.

Expected behavior That integer columns would have a cellstyle with zero decimals. It doesn't make sense to format such values with decimal digits.

firegloves commented 4 years ago

Thank you for your report.

Your request makes sense. The behavior found stems from misuse of integer data types for monetary representation.

This correction will be present in the future version, probably as an additional style option to ensure backward compatibility.

In the meantime, can you use a workaround solution using the MemPOI data processing pipeline to manually set the necessary style on the desired columns? You can achieve this result by adding one class that extends MempoiColumnElaborationStep or StreamApiElaborationStep (depending on the desired Workbook implementation) and overriding the needed methods. It should be simple, but let me know if you need clarifications.

lbruun commented 4 years ago

Thanks. I appreciate the desire not to break anything (backwards compatibility) but I doubt any existing use-case of the library would mind if integer values were no longer formatted with visible decimals.

firegloves commented 4 years ago

You could be right, but MemPOI is used by many people and I can't release a minor update that changes the default behaviour.

Probably your suggestion will become the default behaviour in the next major release.

firegloves commented 4 years ago

I've reviewed your request and decided to switch to a default behaviour for integer fields as you suggested.