MathNya / umya-spreadsheet

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

`get_cell_by_column_and_row_mut` casuses panic #2

Closed SpyrosRoum closed 4 years ago

SpyrosRoum commented 4 years ago

Code:

use umya_spreadsheet;

pub fn write_strings(
    sheet: &mut Worksheet,
    strings: &[&str],
    row_target: usize,
    start_index: usize,
) {
    for (i, &text) in strings.iter().enumerate() {
        let col = start_index + i;
        sheet
            .get_cell_by_column_and_row_mut(col, row_target)
            .set_value(text)
            .expect("Failed to write to sheet");
    }
}

panic:

thread 'main' panicked at 'attempt to subtract with overflow', /home/spyros/.cargo/registry/src/github.com-1ecc6299db9ec823/umya-spreadsheet-0.1.14-beta/src/structs/worksheet.rs:138:48
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:78
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:59
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1076
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1537
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:62
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:198
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:217
  10: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:526
  11: rust_begin_unwind
             at src/libstd/panicking.rs:437
  12: core::panicking::panic_fmt
             at src/libcore/panicking.rs:85
  13: core::panicking::panic
             at src/libcore/panicking.rs:50
  14: umya_spreadsheet::structs::worksheet::Worksheet::get_cell_by_column_and_row_mut
             at /home/spyros/.cargo/registry/src/github.com-1ecc6299db9ec823/umya-spreadsheet-0.1.14-beta/src/structs/worksheet.rs:138
  15: support::utils::write_strings
             at src/utils.rs:89
  16: support::main
             at src/main.rs:45
  17: std::rt::lang_start::{{closure}}
             at /home/spyros/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/rt.rs:67
  18: std::rt::lang_start_internal::{{closure}}
             at src/libstd/rt.rs:52
  19: std::panicking::try::do_call
             at src/libstd/panicking.rs:348
  20: std::panicking::try
             at src/libstd/panicking.rs:325
  21: std::panic::catch_unwind
             at src/libstd/panic.rs:394
  22: std::rt::lang_start_internal
             at src/libstd/rt.rs:51
  23: std::rt::lang_start
             at /home/spyros/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/rt.rs:67
  24: main
  25: __libc_start_main

Sorry for all the edits, I thought the error was something else until I saw the full backtrace

Update: I understand now that you assume colums start at 1 but I find this a little weird? Even though it's excel, we are still programmers and usually indexes start at 0. Anyway, maybe at least mention this somewhere in the docs

MathNya commented 4 years ago

This method starts at column number 1. It is based on the VBA specification. This specification will be documented in the next update.

MathNya commented 4 years ago

This case has been dealt with. Please check with the latest version.