jmcnamara / rust_xlsxwriter

A Rust library for creating Excel XLSX files.
https://crates.io/crates/rust_xlsxwriter
Apache License 2.0
250 stars 23 forks source link

question: Is it normal that "23/07/2023" renders "'23/07/2023"? #89

Closed Antonio225t closed 3 months ago

Antonio225t commented 3 months ago

Question

It's pretty weird but it happens for 23/07/2023 and 23/07/23 it renders a ' at the start when rendering it and it prevents for formatting the date (I put a .set_num_format("dd mmm yyyy") in the format, but it shows the ' even without the format). Is this normal behaviour?

(I made it a question because I didn't want to make another bug for then it to be solved after 15 minutes.)

jmcnamara commented 3 months ago

Datetimes in Excel are numbers with a format. See the docs on ExcelDateTime and Datetimes in Excel.

So, if you are trying to write dates as strings that won't work. If that isn't the case then submit a small working program that shows the issue.

(I made it a question because I didn't want to make another bug for then it to be solved after 15 minutes.)

Questions are fine. But for your own sake have a read through the Tutorial and maybe some of the reference examples in the Cookbook.

Antonio225t commented 3 months ago

Thanks for the information, I'll read the Tutorial and the Cookbook. Anyways I saw that this is present even with single numbers (like "5" renders '5)

jmcnamara commented 3 months ago

Anyways I saw that this is present even with single numbers (like "5" renders '5)

In that case add a small complete example program that demonstrates the issue.

Antonio225t commented 3 months ago

This is what I used:


worksheet.write_string_with_format(row+1, col+7, "5", &Format::new().set_num_format("€ 0,00").set_border_top(FormatBorder::Dashed).set_border_bottom(FormatBorder::Double).set_border_left(FormatBorder::Thin).set_border_right(FormatBorder::Thin))?;```
Antonio225t commented 3 months ago

Alright I guess that the error was me using worksheet.write_string_with_format instead of worksheet.write_number_with_format

Antonio225t commented 3 months ago

Yes it was the issue, with ExcelDateTime and everything works fine now. Thanks for pointing out where to search in case I'm not understanding something 😄

jmcnamara commented 3 months ago

Alright I guess that the error was me using worksheet.write_string_with_format instead of worksheet.write_number_with_format

Yes it was the issue. Thanks for pointing out where to search in case I'm not understanding something

No worries. For what it is worth here is what that output would look like in Excel:

screenshot

I think the apostrophe is LibreOffice's way of saying "Number stored as string".

Antonio225t commented 3 months ago

Such an odd way but at least I now know it. Thanks for the information and hard work 😃