Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
DESKTOP-U434MT0\hiro committed Sep 11, 2024
1 parent 631449c commit 2674f66
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 11 deletions.
42 changes: 34 additions & 8 deletions src/structs/office/excel/reference_sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Range>,
}
impl ReferenceSequence {
pub fn get_value(&self) -> &Coordinate {
pub fn get_value(&self) -> &Vec<Range> {
&self.value
}

pub fn get_value_mut(&mut self) -> &mut Coordinate {
pub fn get_value_mut(&mut self) -> &mut Vec<Range> {
&mut self.value
}

pub fn set_value(&mut self, value: Coordinate) -> &mut Self {
pub fn set_value(&mut self, value: Vec<Range>) -> &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<S: Into<String>>(&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::<Vec<String>>()
.join(" ")
}

pub(crate) fn set_attributes<R: std::io::BufRead>(
&mut self,
reader: &mut Reader<R>,
Expand All @@ -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;
}
Expand All @@ -58,7 +84,7 @@ impl ReferenceSequence {

pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
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");
}
}
14 changes: 11 additions & 3 deletions src/structs/sequence_of_references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,28 @@ impl SequenceOfReferences {
&mut self.range_collection
}

pub fn set_range_collection(&mut self, value: Vec<Range>) {
pub fn set_range_collection(&mut self, value: Vec<Range>) -> &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<S: Into<String>>(&mut self, value: S) {
pub fn remove_range_collection(&mut self) -> &mut Self {
self.range_collection.clear();
self
}

pub fn set_sqref<S: Into<String>>(&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 {
Expand Down
9 changes: 9 additions & 0 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Binary file added tests/test_files/issue_222.xlsx
Binary file not shown.

0 comments on commit 2674f66

Please sign in to comment.