Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
DESKTOP-U434MT0\hiro committed Jul 12, 2024
1 parent 51d0beb commit 158877c
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/reader/xlsx/worksheet.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use super::driver::*;
use super::XlsxError;
use hashbrown::HashMap;
use quick_xml::events::Event;
use quick_xml::Reader;

use helper::formula::*;
use structs::office2010::excel::DataValidations as DataValidations2010;
use structs::raw::RawRelationships;
use structs::raw::RawWorksheet;
Expand All @@ -27,7 +29,7 @@ pub(crate) fn read(
let data = std::io::Cursor::new(raw_data_of_worksheet.get_worksheet_file().get_file_data());
let mut reader = Reader::from_reader(data);
reader.config_mut().trim_text(true);

let mut formula_shared_list: HashMap<u32, (String, Vec<FormulaToken>)> = HashMap::new();
xml_read_loop!(
reader,
Event::Start(ref e) => match e.name().into_inner() {
Expand Down Expand Up @@ -71,6 +73,7 @@ pub(crate) fn read(
worksheet.get_cell_collection_crate_mut(),
shared_string_table,
stylesheet,
&mut formula_shared_list,
false,
);
worksheet.set_row_dimension(obj);
Expand Down Expand Up @@ -170,6 +173,7 @@ pub(crate) fn read(
worksheet.get_cell_collection_crate_mut(),
shared_string_table,
stylesheet,
&mut formula_shared_list,
true,
);
worksheet.set_row_dimension(obj);
Expand Down Expand Up @@ -224,7 +228,7 @@ pub(crate) fn read_lite(
reader.config_mut().trim_text(true);

let mut cells = Cells::default();

let mut formula_shared_list: HashMap<u32, (String, Vec<FormulaToken>)> = HashMap::new();
xml_read_loop!(
reader,
Event::Start(ref e) => {
Expand All @@ -236,6 +240,7 @@ pub(crate) fn read_lite(
&mut cells,
shared_string_table,
stylesheet,
&mut formula_shared_list,
false,
);
}
Expand All @@ -249,6 +254,7 @@ pub(crate) fn read_lite(
&mut cells,
shared_string_table,
stylesheet,
&mut formula_shared_list,
true,
);
}
Expand Down
1 change: 1 addition & 0 deletions src/structs/cell_formula.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use hashbrown::HashMap;
use helper::coordinate::*;
use helper::formula::*;
use quick_xml::de;
use quick_xml::events::{BytesStart, Event};
use quick_xml::Reader;
use quick_xml::Writer;
Expand Down
6 changes: 3 additions & 3 deletions src/structs/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ impl Row {
cells: &mut Cells,
shared_string_table: &SharedStringTable,
stylesheet: &Stylesheet,
formula_shared_list: &mut HashMap<u32, (String, Vec<FormulaToken>)>,
empty_flag: bool,
) {
set_string_from_xml!(self, e, row_num, "r");
Expand All @@ -126,20 +127,19 @@ impl Row {
return;
}

let mut formula_shared_list: HashMap<u32, (String, Vec<FormulaToken>)> = HashMap::new();
xml_read_loop!(
reader,
Event::Empty(ref e) => {
if e.name().into_inner() == b"c" {
let mut obj = Cell::default();
obj.set_attributes(reader, e, shared_string_table, stylesheet, true, &mut formula_shared_list);
obj.set_attributes(reader, e, shared_string_table, stylesheet, true, formula_shared_list);
cells.set_fast(obj);
}
},
Event::Start(ref e) => {
if e.name().into_inner() == b"c" {
let mut obj = Cell::default();
obj.set_attributes(reader, e, shared_string_table, stylesheet, false, &mut formula_shared_list);
obj.set_attributes(reader, e, shared_string_table, stylesheet, false, formula_shared_list);
cells.set_fast(obj);
}
},
Expand Down
11 changes: 11 additions & 0 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1500,6 +1500,17 @@ fn issue_194_2() {
let path = std::path::Path::new("./tests/test_files/issue_194_2.xlsx");
let mut book = umya_spreadsheet::reader::xlsx::read(path).unwrap();

dbg!(book
.get_sheet(&0)
.unwrap()
.get_cell("P16")
.map_or("", |c| c.get_formula()));
dbg!(book
.get_sheet(&0)
.unwrap()
.get_cell("P17")
.map_or("", |c| c.get_formula()));

let path = std::path::Path::new("./tests/result_files/issue_194_2.xlsx");
let _ = umya_spreadsheet::writer::xlsx::write(&book, path);
}
Expand Down
Binary file added tests/test_files/issue_188_3.xlsx
Binary file not shown.
Binary file added tests/test_files/issue_194_2.xlsx
Binary file not shown.

0 comments on commit 158877c

Please sign in to comment.