MathNya / umya-spreadsheet

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

Panic when Number Format has a Condition without Decimal Places #224

Open Redfire75369 opened 2 days ago

Redfire75369 commented 2 days ago

When using Worksheet::get_formatted_value, and the cell contains a number format [<1]0;0, a panic occurs.

In particular, the problem occurs when the value used in the conditional (1 in the above example) has no decimal places. This means that the third capture is None, which causes a panic when trying to unwrap it. Excel automatically truncates 1.0 to 1 , making this issue worse.

Panic Backtrace:

thread 'main' panicked at C:\Users\Redfire\.cargo\registry\src\index.crates.io-6f17d22bba15001f\umya-spreadsheet-2.0.2\src\helper\number_format.rs:231:31: called `Option::unwrap()` on a `None` value stack backtrace: 0: std::panicking::begin_panic_handler at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\panicking.rs:665 1: core::panicking::panic_fmt at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\core\src\panicking.rs:74 2: core::panicking::panic at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\core\src\panicking.rs:148 3: core::option::unwrap_failed at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\core\src\option.rs:2020 4: core::iter::traits::iterator::Iterator::for_each::call::closure$0 at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c\library\core\src\iter\traits\iterator.rs:815 5: core::iter::adapters::enumerate::impl$1::fold::enumerate::closure$0 at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c\library\core\src\iter\adapters\enumerate.rs:108 6: alloc::vec::into_iter::impl$5::fold,alloc::alloc::Global,tuple$<>,core::iter::adapters::enumerate::impl$1::fold::enumerate::closure_env$0,tuple$<>,core::iter::traits::iterator::Iterator::for_each::call::closure_env$0 > >,ref$ > at C:\Users\Redfire\.cargo\registry\src\index.crates.io-6f17d22bba15001f\umya-spreadsheet-2.0.2\src\helper\number_format.rs:132 9: umya_spreadsheet::structs::cell::Cell::get_formatted_value at C:\Users\Redfire\.cargo\registry\src\index.crates.io-6f17d22bba15001f\umya-spreadsheet-2.0.2\src\structs\cell.rs:256 10: umya_spreadsheet::structs::cells::Cells::get_formatted_value_by_column_and_row at C:\Users\Redfire\.cargo\registry\src\index.crates.io-6f17d22bba15001f\umya-spreadsheet-2.0.2\src\structs\cells.rs:190 11: umya_spreadsheet::structs::worksheet::Worksheet::get_formatted_value at C:\Users\Redfire\.cargo\registry\src\index.crates.io-6f17d22bba15001f\umya-spreadsheet-2.0.2\src\structs\worksheet.rs:156 12: testing::main at .\src\main.rs:7 13: core::ops::function::FnOnce::call_once at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c\library\core\src\ops\function.rs:250 note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
MathNya commented 1 day ago

@Redfire75369 Thank you for contacting us. We will proceed to investigate and correct the cause of the problem.