From 2674f6692bacbb0cb7492f6f45e93b8ad6a76126 Mon Sep 17 00:00:00 2001 From: "DESKTOP-U434MT0\\hiro" Date: Wed, 11 Sep 2024 12:38:37 +0900 Subject: [PATCH] #222 --- .../office/excel/reference_sequence.rs | 42 ++++++++++++++---- src/structs/sequence_of_references.rs | 14 ++++-- tests/integration_test.rs | 9 ++++ tests/test_files/issue_222.xlsx | Bin 0 -> 9773 bytes 4 files changed, 54 insertions(+), 11 deletions(-) create mode 100644 tests/test_files/issue_222.xlsx diff --git a/src/structs/office/excel/reference_sequence.rs b/src/structs/office/excel/reference_sequence.rs index c53eacda..0caa0051 100644 --- a/src/structs/office/excel/reference_sequence.rs +++ b/src/structs/office/excel/reference_sequence.rs @@ -6,26 +6,54 @@ use reader::driver::*; use std::io::Cursor; use std::vec; use structs::Coordinate; +use structs::Range; use writer::driver::*; #[derive(Default, Debug, Clone)] pub struct ReferenceSequence { - value: Coordinate, + value: Vec, } impl ReferenceSequence { - pub fn get_value(&self) -> &Coordinate { + pub fn get_value(&self) -> &Vec { &self.value } - pub fn get_value_mut(&mut self) -> &mut Coordinate { + pub fn get_value_mut(&mut self) -> &mut Vec { &mut self.value } - pub fn set_value(&mut self, value: Coordinate) -> &mut Self { + pub fn set_value(&mut self, value: Vec) -> &mut Self { self.value = value; self } + pub fn add_value(&mut self, value: Range) -> &mut Self { + self.value.push(value); + self + } + + pub fn remove_value(&mut self) -> &mut Self { + self.value.clear(); + self + } + + pub fn set_sqref>(&mut self, value: S) -> &mut Self { + value.into().split(' ').for_each(|range_value| { + let mut range = Range::default(); + range.set_range(range_value); + self.value.push(range); + }); + self + } + + pub fn get_sqref(&self) -> String { + self.value + .iter() + .map(|range| range.get_range()) + .collect::>() + .join(" ") + } + pub(crate) fn set_attributes( &mut self, reader: &mut Reader, @@ -40,9 +68,7 @@ impl ReferenceSequence { } Ok(Event::End(ref e)) => match e.name().into_inner() { b"xm:sqref" => { - let mut obj = Coordinate::default(); - obj.set_coordinate(value); - self.value = obj; + self.set_sqref(value); value = String::from(""); return; } @@ -58,7 +84,7 @@ impl ReferenceSequence { pub(crate) fn write_to(&self, writer: &mut Writer>>) { write_start_tag(writer, "xm:sqref", vec![], false); - write_text_node(writer, &self.value.get_coordinate()); + write_text_node(writer, &self.get_sqref()); write_end_tag(writer, "xm:sqref"); } } diff --git a/src/structs/sequence_of_references.rs b/src/structs/sequence_of_references.rs index 2a73af82..907ba2a1 100644 --- a/src/structs/sequence_of_references.rs +++ b/src/structs/sequence_of_references.rs @@ -15,20 +15,28 @@ impl SequenceOfReferences { &mut self.range_collection } - pub fn set_range_collection(&mut self, value: Vec) { + pub fn set_range_collection(&mut self, value: Vec) -> &mut Self { self.range_collection = value; + self } - pub fn add_range_collection(&mut self, value: Range) { + pub fn add_range_collection(&mut self, value: Range) -> &mut Self { self.range_collection.push(value); + self } - pub fn set_sqref>(&mut self, value: S) { + pub fn remove_range_collection(&mut self) -> &mut Self { + self.range_collection.clear(); + self + } + + pub fn set_sqref>(&mut self, value: S) -> &mut Self { value.into().split(' ').for_each(|range_value| { let mut range = Range::default(); range.set_range(range_value); self.range_collection.push(range); }); + self } pub fn get_sqref(&self) -> String { diff --git a/tests/integration_test.rs b/tests/integration_test.rs index 7ff977dd..0243fdf7 100644 --- a/tests/integration_test.rs +++ b/tests/integration_test.rs @@ -1757,3 +1757,12 @@ fn issue_220() { let path = std::path::Path::new("./tests/result_files/issue_220.xlsx"); let _ = umya_spreadsheet::writer::xlsx::write(&book, path); } + +#[test] +fn issue_222() { + let path = std::path::Path::new("./tests/test_files/issue_222.xlsx"); + let mut book = umya_spreadsheet::reader::xlsx::read(path).unwrap(); + + let path = std::path::Path::new("./tests/result_files/issue_222.xlsx"); + let _ = umya_spreadsheet::writer::xlsx::write(&book, path); +} diff --git a/tests/test_files/issue_222.xlsx b/tests/test_files/issue_222.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..23e15111850c05c61eadef624d1e44ee6933dc94 GIT binary patch literal 9773 zcmeHN1y>!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