Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
DESKTOP-U434MT0\hiro committed Jun 18, 2024
1 parent f3b75f6 commit 1f09092
Show file tree
Hide file tree
Showing 7 changed files with 249 additions and 65 deletions.
38 changes: 18 additions & 20 deletions src/structs/drawing/spreadsheet/marker_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,28 +70,26 @@ impl MarkerType {
self.row = row.unwrap() - 1;
}

pub(crate) fn _adjustment_insert_row(&mut self, num_rows: &u32) {
self.row += num_rows;
}

pub(crate) fn _adjustment_insert_column(&mut self, num_cols: &u32) {
self.col += num_cols;
}

pub(crate) fn _adjustment_remove_row(&mut self, num_rows: &u32) {
self.row = if &self.row > num_rows {
self.row - num_rows
} else {
1
};
pub(crate) fn adjustment_insert_coordinate(
&mut self,
root_col_num: &u32,
offset_col_num: &u32,
root_row_num: &u32,
offset_row_num: &u32,
) {
self.col = adjustment_insert_coordinate(&self.col, root_row_num, offset_row_num);
self.row = adjustment_insert_coordinate(&self.row, root_row_num, offset_row_num);
}

pub(crate) fn _adjustment_remove_column(&mut self, num_cols: &u32) {
self.col = if &self.col > num_cols {
self.col - num_cols
} else {
1
};
pub(crate) fn adjustment_remove_coordinate(
&mut self,
root_col_num: &u32,
offset_col_num: &u32,
root_row_num: &u32,
offset_row_num: &u32,
) {
self.col = adjustment_remove_coordinate(&self.col, root_row_num, offset_row_num);
self.row = adjustment_remove_coordinate(&self.row, root_row_num, offset_row_num);
}

pub(crate) fn set_attributes<R: std::io::BufRead>(
Expand Down
38 changes: 26 additions & 12 deletions src/structs/drawing/spreadsheet/one_cell_anchor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,34 @@ impl OneCellAnchor {
self
}

pub(crate) fn _adjustment_insert_row(&mut self, num_rows: &u32) {
self.from_marker._adjustment_insert_row(num_rows);
}

pub(crate) fn _adjustment_insert_column(&mut self, num_cols: &u32) {
self.from_marker._adjustment_insert_column(num_cols);
}

pub(crate) fn _adjustment_remove_row(&mut self, num_rows: &u32) {
self.from_marker._adjustment_remove_row(num_rows);
pub(crate) fn adjustment_insert_coordinate(
&mut self,
root_col_num: &u32,
offset_col_num: &u32,
root_row_num: &u32,
offset_row_num: &u32,
) {
self.from_marker.adjustment_insert_coordinate(
root_col_num,
offset_col_num,
root_row_num,
offset_row_num,
);
}

pub(crate) fn _adjustment_remove_column(&mut self, num_cols: &u32) {
self.from_marker._adjustment_remove_column(num_cols);
pub(crate) fn adjustment_remove_coordinate(
&mut self,
root_col_num: &u32,
offset_col_num: &u32,
root_row_num: &u32,
offset_row_num: &u32,
) {
self.from_marker.adjustment_remove_coordinate(
root_col_num,
offset_col_num,
root_row_num,
offset_row_num,
);
}

pub(crate) fn is_image(&self) -> bool {
Expand Down
54 changes: 38 additions & 16 deletions src/structs/drawing/spreadsheet/two_cell_anchor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,24 +141,46 @@ impl TwoCellAnchor {
self
}

pub(crate) fn _adjustment_insert_row(&mut self, num_rows: &u32) {
self.from_marker._adjustment_insert_row(num_rows);
self.to_marker._adjustment_insert_row(num_rows);
}

pub(crate) fn _adjustment_insert_column(&mut self, num_cols: &u32) {
self.from_marker._adjustment_insert_column(num_cols);
self.to_marker._adjustment_insert_column(num_cols);
}

pub(crate) fn _adjustment_remove_row(&mut self, num_rows: &u32) {
self.from_marker._adjustment_remove_row(num_rows);
self.to_marker._adjustment_remove_row(num_rows);
pub(crate) fn adjustment_insert_coordinate(
&mut self,
root_col_num: &u32,
offset_col_num: &u32,
root_row_num: &u32,
offset_row_num: &u32,
) {
self.from_marker.adjustment_insert_coordinate(
root_col_num,
offset_col_num,
root_row_num,
offset_row_num,
);
self.to_marker.adjustment_insert_coordinate(
root_col_num,
offset_col_num,
root_row_num,
offset_row_num,
);
}

pub(crate) fn _adjustment_remove_column(&mut self, num_cols: &u32) {
self.from_marker._adjustment_remove_column(num_cols);
self.to_marker._adjustment_remove_column(num_cols);
pub(crate) fn adjustment_remove_coordinate(
&mut self,
root_col_num: &u32,
offset_col_num: &u32,
root_row_num: &u32,
offset_row_num: &u32,
) {
self.from_marker.adjustment_remove_coordinate(
root_col_num,
offset_col_num,
root_row_num,
offset_row_num,
);
self.to_marker.adjustment_remove_coordinate(
root_col_num,
offset_col_num,
root_row_num,
offset_row_num,
);
}

pub(crate) fn is_support(&self) -> bool {
Expand Down
133 changes: 132 additions & 1 deletion src/structs/drawing/spreadsheet/worksheet_drawing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,140 @@ impl WorksheetDrawing {
}
result
}

/// (This method is crate only.)
/// Adjustment Insert Coordinate
pub(crate) fn adjustment_insert_coordinate(
&mut self,
root_col_num: &u32,
offset_col_num: &u32,
root_row_num: &u32,
offset_row_num: &u32,
) {
// one_cell_anchor
for anchor in self.get_one_cell_anchor_collection_mut() {
anchor.adjustment_insert_coordinate(
root_col_num,
offset_col_num,
root_row_num,
offset_row_num,
);
}
for image in self.get_image_collection_mut() {
match image.get_one_cell_anchor_mut() {
Some(anchor) => {
anchor.adjustment_insert_coordinate(
root_col_num,
offset_col_num,
root_row_num,
offset_row_num,
);
}
None => {}
}
}

// two_cell_anchor
for anchor in self.get_two_cell_anchor_collection_mut() {
anchor.adjustment_insert_coordinate(
root_col_num,
offset_col_num,
root_row_num,
offset_row_num,
);
}
for chart in self.get_chart_collection_mut() {
let mut anchor = chart.get_two_cell_anchor_mut();
anchor.adjustment_insert_coordinate(
root_col_num,
offset_col_num,
root_row_num,
offset_row_num,
);
}
for image in self.get_image_collection_mut() {
match image.get_two_cell_anchor_mut() {
Some(anchor) => {
anchor.adjustment_insert_coordinate(
root_col_num,
offset_col_num,
root_row_num,
offset_row_num,
);
}
None => {}
}
}
}

/// (This method is crate only.)
/// Adjustment Insert Coordinate
pub(crate) fn adjustment_remove_coordinate(
&mut self,
root_col_num: &u32,
offset_col_num: &u32,
root_row_num: &u32,
offset_row_num: &u32,
) {
// one_cell_anchor
for anchor in self.get_one_cell_anchor_collection_mut() {
anchor.adjustment_remove_coordinate(
root_col_num,
offset_col_num,
root_row_num,
offset_row_num,
);
}
for image in self.get_image_collection_mut() {
match image.get_one_cell_anchor_mut() {
Some(anchor) => {
anchor.adjustment_remove_coordinate(
root_col_num,
offset_col_num,
root_row_num,
offset_row_num,
);
}
None => {}
}
}

// two_cell_anchor
for anchor in self.get_two_cell_anchor_collection_mut() {
anchor.adjustment_remove_coordinate(
root_col_num,
offset_col_num,
root_row_num,
offset_row_num,
);
}
for chart in self.get_chart_collection_mut() {
let mut anchor = chart.get_two_cell_anchor_mut();
anchor.adjustment_remove_coordinate(
root_col_num,
offset_col_num,
root_row_num,
offset_row_num,
);
}
for image in self.get_image_collection_mut() {
match image.get_two_cell_anchor_mut() {
Some(anchor) => {
anchor.adjustment_remove_coordinate(
root_col_num,
offset_col_num,
root_row_num,
offset_row_num,
);
}
None => {}
}
}
}

/// (This method is crate only.)
/// Adjustment Insert Coordinate
pub(crate) fn adjustment_insert_coordinate_from_other_sheet(
&mut self,
sheet_name: &str,
root_col_num: &u32,
Expand Down Expand Up @@ -260,7 +391,7 @@ impl WorksheetDrawing {

/// (This method is crate only.)
/// Adjustment Remove Coordinate
pub(crate) fn adjustment_remove_coordinate(
pub(crate) fn adjustment_remove_coordinate_from_other_sheet(
&mut self,
sheet_name: &str,
root_col_num: &u32,
Expand Down
34 changes: 18 additions & 16 deletions src/structs/worksheet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1030,14 +1030,15 @@ impl Worksheet {
offset_row_num,
);

// chart
self.worksheet_drawing.adjustment_insert_coordinate(
sheet_name,
root_col_num,
offset_col_num,
root_row_num,
offset_row_num,
);
// worksheet_drawing
self.worksheet_drawing
.adjustment_insert_coordinate_from_other_sheet(
sheet_name,
root_col_num,
offset_col_num,
root_row_num,
offset_row_num,
);
}

/// (This method is crate only.)
Expand Down Expand Up @@ -1202,14 +1203,15 @@ impl Worksheet {
offset_row_num,
);

// chart
self.worksheet_drawing.adjustment_remove_coordinate(
sheet_name,
root_col_num,
offset_col_num,
root_row_num,
offset_row_num,
);
// worksheet_drawing
self.worksheet_drawing
.adjustment_remove_coordinate_from_other_sheet(
sheet_name,
root_col_num,
offset_col_num,
root_row_num,
offset_row_num,
);
}

/// Get Code Name.
Expand Down
17 changes: 17 additions & 0 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1429,3 +1429,20 @@ fn expect_red_indexed_color() {

assert_eq!("FFFF0000", color);
}

#[test]
fn issue_190() {
let path = std::path::Path::new("./tests/test_files/issue_190.xlsx");
let mut book = umya_spreadsheet::reader::xlsx::read(path).unwrap();

// remove
book.get_sheet_mut(&0).unwrap().remove_column("E", &1);
book.get_sheet_mut(&0).unwrap().remove_row(&4, &1);

// insert
book.get_sheet_mut(&1).unwrap().insert_new_column("E", &1);
book.get_sheet_mut(&1).unwrap().insert_new_row(&4, &1);

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

0 comments on commit 1f09092

Please sign in to comment.