dhatim / fastexcel

Generate and read big Excel files quickly
Other
641 stars 116 forks source link

Column formatting working in Libreoffice, not excel 365 #368

Open akobberup opened 6 months ago

akobberup commented 6 months ago

I create a file with 4 columns formatted as datetime, date, number and decimal.

When opening in excel (online) the columns are not formatted: image

When opening in libreoffice it works. image

If i open the file in libreoffice and saves it, then the formatting will work in excel when opened there. image

Here is the styling routine i use:

        for (int index = 0; index < headerElements.size(); index++) {
            final HeaderElement dataElement = headerElements.get(index);
            ColumnStyleSetter style = worksheet.style(index);
            style.fontSize(10);
            switch (dataElement.getDataType()) {
                case Boolean:
                    style.horizontalAlignment("center");
                    break;
                case String:
                    break;
                case Number:
                    style.horizontalAlignment("right");
                    style.format("#,##0");
                    break;
                case Decimal:
                    style.horizontalAlignment("right");
                    style.format("#,##0.00");
                    break;
                case Date:
                    style.format("yyyy/mm/dd");
                    break;
                case DateTime:
                    style.format("yyyy/mm/dd HH:mm");
                    break;
            }
            style.set();
        }

Edit: Just to clarify, I'm danish, and we use period for thousand separator and comma as decimal separator :)

test5581114334280939970.xlsx

MrAlucardDante commented 1 month ago

I encountered the same issue. Setting the style both with ColumeStyleSetter and StyleSetter (on each cell) worked in both Excel and LibreOffice For instance :

ws.style(row, column).format(date_format).set();
ws.style(column).format(date_format).set();