jmcnamara / rust_xlsxwriter

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

Feature Request: add `write_datetime_with_format`, while `write_datetime` should not receive a format #47

Closed lucatrv closed 1 year ago

lucatrv commented 1 year ago

Feature Request

I set a column format with

worksheet.set_column_format(col, &rust_xlsxwriter::Format::new().set_num_format("dd/mm/yyyy"))?;

So IMHO I should be able to write dates to that column with:

worksheet.write_datetime(row, col, &date)?;

instead of having to repeat the same format with:

worksheet.write_datetime(row, col, &date, &rust_xlsxwriter::Format::new().set_num_format("dd/mm/yyyy"))?;

In other words, the plain write_datetime method should not receive a format, while a separate write_datetime_with_format method should be added for those cases where the date format has not already been applied to the cell.

jmcnamara commented 1 year ago

So IMHO I should be able to write dates to that column with:

You are correct. You should be able to do that.

I implemented write_datetime() as write_datetime_with_format() since it almost never makes sense in Excel to write a date without a format. However, that creates an inconsistency for the case you pointed out so I will need to fix it. It is also inconsistent with the other language versions of the library.

Thanks for the input.

jmcnamara commented 1 year ago

This is now fixed on main and will be in the next release.

The write_datetime() method no longer takes a format (that becomes write_datetime_with_format()) and the write() method no longer add a default date/time format.

The datetime will pick up any implicit column or row formatting or display as an unformatted number.

jmcnamara commented 1 year ago

This is fixed in version v0.42.0. Thanks for the report.