diff --git a/src/xlsb/mod.rs b/src/xlsb/mod.rs index 49ce436b..29aa1bb1 100644 --- a/src/xlsb/mod.rs +++ b/src/xlsb/mod.rs @@ -328,6 +328,9 @@ impl Xlsb { Some("worksheets") => SheetType::WorkSheet, Some("chartsheets") => SheetType::ChartSheet, Some("dialogsheets") => SheetType::DialogSheet, + // Excel 4.0 macro sheets and international macro + // sheets. + Some("macrosheets") => SheetType::MacroSheet, _ => { return Err(XlsbError::Unrecognized { typ: "BoundSheet8:dt", diff --git a/src/xlsx/mod.rs b/src/xlsx/mod.rs index 31132fb6..c527a7f8 100644 --- a/src/xlsx/mod.rs +++ b/src/xlsx/mod.rs @@ -652,6 +652,8 @@ impl Xlsx { Some("worksheet") => SheetType::WorkSheet, Some("chartsheet") => SheetType::ChartSheet, Some("dialogsheet") => SheetType::DialogSheet, + // Excel 4.0 macro sheets and international macro sheets. + Some("xlMacrosheet" | "xlIntlMacrosheet") => SheetType::MacroSheet, _ => { return Err(XlsxError::Unrecognized { typ: "sheet:type", diff --git a/tests/macro_sheets.xls b/tests/macro_sheets.xls new file mode 100644 index 00000000..f5cb85f2 Binary files /dev/null and b/tests/macro_sheets.xls differ diff --git a/tests/macro_sheets.xlsb b/tests/macro_sheets.xlsb new file mode 100644 index 00000000..8eacc4a4 Binary files /dev/null and b/tests/macro_sheets.xlsb differ diff --git a/tests/macro_sheets.xlsm b/tests/macro_sheets.xlsm new file mode 100644 index 00000000..54889fa4 Binary files /dev/null and b/tests/macro_sheets.xlsm differ diff --git a/tests/test.rs b/tests/test.rs index c6c7e7f4..0a9179d3 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -2457,6 +2457,51 @@ fn test_ods_sheets_metadata() { ); } +#[rstest] +#[case("macro_sheets.xlsm")] +#[case("macro_sheets.xlsb")] +#[case("macro_sheets.xls")] +fn test_all_macro_sheets(#[case] test_file: &str) { + // Test that Excel 4.0 macro sheets and international macro sheets are read + // as macro sheets, along with their cells and formulas. The files are the + // same workbook saved by Excel in each format. See issue #802. + let mut workbook = open_workbook_auto(test_path(test_file)).unwrap(); + + assert_eq!( + workbook.sheets_metadata(), + &[ + Sheet { + name: "Data".to_string(), + typ: SheetType::WorkSheet, + visible: SheetVisible::Visible + }, + Sheet { + name: "Macro1".to_string(), + typ: SheetType::MacroSheet, + visible: SheetVisible::Visible + }, + Sheet { + name: "Intl1".to_string(), + typ: SheetType::MacroSheet, + visible: SheetVisible::Visible + }, + ] + ); + + let range = workbook.worksheet_range("Macro1").unwrap(); + range_eq!(range, [[Bool(false)], [Bool(false)]]); + let formulas = workbook.worksheet_formula("Macro1").unwrap(); + range_eq!( + formulas, + [["ECHO(FALSE)".to_string()], ["RETURN()".to_string()]] + ); + + let range = workbook.worksheet_range("Intl1").unwrap(); + range_eq!(range, [[Bool(false)]]); + let formulas = workbook.worksheet_formula("Intl1").unwrap(); + range_eq!(formulas, [["RETURN()".to_string()]]); +} + #[test] fn test_xlsx_password_protected() { // Test that a password protected xlsx file returns XlsxError::Password.