Skip to content

Commit

Permalink
excel: better cell error handling
Browse files Browse the repository at this point in the history
before, we were returning the debug value, which didn't have the '#' prefix to clearly indicate its a cell error - i.e. `#DIV/0!` instead of `Div0`

This improves Excel error handling while I research how to get the "original value" of a cell that's causing the error as discussed in #1682
  • Loading branch information
jqnatividad committed Mar 22, 2024
1 parent 05cda18 commit 012aa3f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
Binary file modified resources/test/excel-xlsx.xlsx
Binary file not shown.
2 changes: 1 addition & 1 deletion src/cmd/excel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ pub fn run(argv: &[&str]) -> CliResult<()> {

record.push_field(&work_date);
},
Data::Error(ref e) => record.push_field(&format!("{e:?}")),
Data::Error(ref e) => record.push_field(&format!("{e}")),
Data::Bool(ref b) => {
record.push_field(if *b { "true" } else { "false" });
},
Expand Down
21 changes: 21 additions & 0 deletions tests/test_excel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,27 @@ fn excel_open_xls() {
assert_eq!(got, expected);
}

#[test]
fn excel_cellerrors() {
let wrk = Workdir::new("excel_cellerrors");

let xls_file = wrk.load_test_file("excel-xlsx.xlsx");

let mut cmd = wrk.command("excel");
cmd.args(["--sheet", "cellerrors"]).arg(xls_file);

let got: Vec<Vec<String>> = wrk.read_stdout(&mut cmd);
let expected = vec![
svec!["col1", "col 2", "column-3"],
svec!["1", "-50", "15"],
svec!["2", "#DIV/0!", "#NAME?"],
svec!["3", "50", "20"],
svec!["4", "33.333333333333336", "3"],
svec!["5", "25", "4"],
];
assert_eq!(got, expected);
}

#[test]
fn excel_open_xls_delimiter() {
let wrk = Workdir::new("excel_open_xls_delimiter");
Expand Down

0 comments on commit 012aa3f

Please sign in to comment.