MathNya / umya-spreadsheet

A pure rust library for reading and writing spreadsheet files
MIT License
276 stars 44 forks source link

the to_formatted_string isn't handling date formats well #7

Closed nomad-scl closed 3 years ago

nomad-scl commented 3 years ago

the following code :

let x1 = umya_spreadsheet::NumberFormat::FORMAT_DATE_YYYYMMDD; let x2 = umya_spreadsheet::NumberFormat::FORMAT_DATE_YYYYMMDD2; let x3 = umya_spreadsheet::NumberFormat::FORMAT_DATE_YYYYMMDDSLASH; let x4 = umya_spreadsheet::NumberFormat::FORMAT_DATE_DATETIME; let x5 = umya_spreadsheet::NumberFormat::FORMAT_DATE_DDMMYYYY; let x6 = umya_spreadsheet::NumberFormat::FORMAT_DATE_DMMINUS; let x7 = umya_spreadsheet::NumberFormat::FORMAT_DATE_DMYMINUS; let x8 = umya_spreadsheet::NumberFormat::FORMAT_DATE_DMYSLASH; let x9 = umya_spreadsheet::NumberFormat::FORMAT_DATE_XLSX22; let x10 = umya_spreadsheet::NumberFormat::FORMAT_DATE_XLSX17; let x11 = umya_spreadsheet::NumberFormat::FORMAT_DATE_XLSX16; let x12 = umya_spreadsheet::NumberFormat::FORMAT_DATE_XLSX15; let x13 = umya_spreadsheet::NumberFormat::FORMAT_DATE_XLSX14; println!("{:?}", to_formatted_string(cell.get_value(), &x1.to_string())); println!("{:?}", to_formatted_string(cell.get_value(), &x2.to_string())); println!("{:?}", to_formatted_string(cell.get_value(), &x3.to_string())); println!("{:?}", to_formatted_string(cell.get_value(), &x4.to_string())); println!("{:?}", to_formatted_string(cell.get_value(), &x5.to_string())); println!("{:?}", to_formatted_string(cell.get_value(), &x6.to_string())); println!("{:?}", to_formatted_string(cell.get_value(), &x7.to_string())); println!("{:?}", to_formatted_string(cell.get_value(), &x8.to_string())); println!("{:?}", to_formatted_string(cell.get_value(), &x9.to_string())); println!("{:?}", to_formatted_string(cell.get_value(), &x10.to_string())); println!("{:?}", to_formatted_string(cell.get_value(), &x11.to_string())); println!("{:?}", to_formatted_string(cell.get_value(), &x12.to_string())); println!("{:?}", to_formatted_string(cell.get_value(), &x13.to_string()));

presents the following output "2024-%m-%d" "2024-%m-%d" "2024/%m/%d" "12/05/24 0:00" "%d/%m/2024" "12-05" "12-05-24" "12/05/24" "05/12/24 0:00" "May-24" "12-May" "12-May-24" "%m-%d-24"

keep in mind that the data structure in the excel file is a correct date, I tried using different ways to represent the date in the excel cell but the result is the same, from the output above the date isn't always parsed correctly and I need the date to be formatted as DD/MM/YYYY

MathNya commented 3 years ago

Thank you for your report. We will fix the problem in the next update.

MathNya commented 3 years ago

We have updated the program to fix this bug.

With this update, we have also updated here. https://github.com/MathNya/umya-spreadsheet/blob/c960006dea7a378f16da842c8f9d442438b4f4fb/src/structs/number_format.rs#L108-L109

nomad-scl commented 3 years ago

it is working now, thanks