Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Number Format is never automatically set #343

Open
desoss opened this issue Oct 19, 2023 · 3 comments
Open

Number Format is never automatically set #343

desoss opened this issue Oct 19, 2023 · 3 comments

Comments

@desoss
Copy link

desoss commented Oct 19, 2023

Whenever I write an Integer or a Long, the generated Excel cell has a General numbering format.
Isn't it possible to generate it as a Number?

Here's the code that I'm using:

Worksheet ws = wb.newWorksheet("Sheet 1");
ws.value(0, 2, 1234);
ws.value(0, 3, 123456L);
ws.value(0, 4, 1.234);

I don't know if it might help or not, but I've decompiled the .xlsx file that I've generated, here's the XML code related to some cells:

<row>
    ....
    <c r="D1" t="n"><v>123456</v></c>
    <c r="E1" t="n"><v>1.234</v></c>
</row>

If I manually change the numbering format of these 2 cells from General to Number the related decompiled XML is:

<row>
    ....
    <c r="D1" s="1"><v>123456</v></c>
    <c r="E1"><v>1.234</v></c>
</row>
@holleymcfly
Copy link

Hi desoss,
just setting the value doesn't format the cell.
You should do something like:

sheet.style(row, col).format("0").set();  // format as number without digits
sheet.style(row, col).format("0.00").set(); // format as number with 2 digits
sheet.style(row, col).format("dd.MM.yyyy").set(); // format as date
sheet.style(row, col).format("0.00%").set(); // format as percent

Does that help?

Best regards,
Holger

@CamilYed
Copy link

@holleymcfly Could you add more examples about cell formatting to README file?

@holleymcfly
Copy link

Hi CamilYed,

I'm not a contributor on the project. Which examples are you looking for?

Best,
Holger

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants