MathNya / umya-spreadsheet

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

Ranges for complete row fail parsing #11

Closed 8191 closed 3 years ago

8191 commented 3 years ago

I have a workbook which contains a definition for a complete row (Sheet1!$6:$6). Opening the workbook fails at umya_spreadsheet::helper::coordinate::coordinate_from_string as the regex [A-Z]+ returns None but gets unwrapped unconditionally:

pub fn coordinate_from_string(coordinate:&str)->Vec<&str> {
    let re = Regex::new(r"[A-Z]+").unwrap();
    let caps = re.captures(coordinate).unwrap(); // panic!
    // ...
}

Backtrace:

stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633\/library\std\src\panicking.rs:515
   1: core::panicking::panic_fmt
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633\/library\core\src\panicking.rs:92
   2: core::panicking::panic
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633\/library\core\src\panicking.rs:50
   3: enum$<core::option::Option<regex::re_unicode::Captures>, 1, 18446744073709551615, Some>::unwrap<regex::re_unicode::Captures>
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633\library\core\src\option.rs:388
   4: umya_spreadsheet::helper::coordinate::coordinate_from_string
             at C:\Users\mfaux\source\rust\umya-spreadsheet\src\helper\coordinate.rs:66
   5: umya_spreadsheet::helper::coordinate::index_from_coordinate<alloc::string::String>
             at C:\Users\mfaux\source\rust\umya-spreadsheet\src\helper\coordinate.rs:98
   6: umya_spreadsheet::structs::range::Range::set_range<str>
             at C:\Users\mfaux\source\rust\umya-spreadsheet\src\structs\range.rs:26
   7: umya_spreadsheet::structs::address::Address::set_address<alloc::string::String>
             at C:\Users\mfaux\source\rust\umya-spreadsheet\src\structs\address.rs:40
   8: umya_spreadsheet::structs::defined_name::DefinedName::set_address<alloc::string::String>
             at C:\Users\mfaux\source\rust\umya-spreadsheet\src\structs\defined_name.rs:32
   9: umya_spreadsheet::reader::xlsx::workbook::read
             at C:\Users\mfaux\source\rust\umya-spreadsheet\src\reader\xlsx\workbook.rs:55
  10: umya_spreadsheet::reader::xlsx::read
             at C:\Users\mfaux\source\rust\umya-spreadsheet\src\reader\xlsx.rs:82
  11: palcreator::run
             at .\src\lib.rs:30
  12: palcreator::main
             at .\src\main.rs:13
  13: core::ops::function::FnOnce::call_once<fn(),tuple<>>
8191 commented 3 years ago

What might be the best approach to solve this? I think setting the Range.coordinate_start column to 0 and Range.coordinate_end to 18278 (=ZZZ) is the most straight forward solution, but most likely not the best one...?

Same is valid for ranges covering a complete column.

MathNya commented 3 years ago

Thank you for reporting this.

We did not anticipate this pattern in our current implementation. As you mentioned, the above fix may avoid the error, but we believe the following fixes are necessary to fully address this issue.

  1. change each parameter of the Coordinate structure to Option.
  2. modify various parts of the code accordingly.

We understand that this bug is of high priority. We will give the highest priority to this issue.

MathNya commented 3 years ago

The program has been updated. This error has been resolved.