Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
DESKTOP-U434MT0\hiro committed Dec 13, 2024
1 parent 913c3d2 commit 5e20000
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ pub fn new_file() -> structs::Spreadsheet {
spreadsheet.set_stylesheet_defalut_value();
let worksheet = spreadsheet.new_sheet("Sheet1").unwrap();
worksheet.set_active_cell("A1");
let mut sheet_view = SheetView::default();
sheet_view.set_workbook_view_id(0);
let mut sheet_views = SheetViews::default();
sheet_views.add_sheet_view_list_mut(sheet_view);
worksheet.set_sheets_views(sheet_views);
spreadsheet.set_active_sheet(0);
spreadsheet
}
Expand Down
16 changes: 16 additions & 0 deletions src/structs/sheet_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use thin_vec::ThinVec;

#[derive(Clone, Default, Debug)]
pub struct SheetView {
show_grid_lines: BooleanValue,
tab_selected: BooleanValue,
workbook_view_id: UInt32Value,
pane: Option<Box<Pane>>,
Expand All @@ -29,6 +30,17 @@ pub struct SheetView {
}

impl SheetView {
#[inline]
pub fn get_show_grid_lines(&self) -> &bool {
self.show_grid_lines.get_value()
}

#[inline]
pub fn set_show_grid_lines(&mut self, value: bool) -> &mut Self {
self.show_grid_lines.set_value(value);
self
}

#[inline]
pub fn get_tab_selected(&self) -> &bool {
self.tab_selected.get_value()
Expand Down Expand Up @@ -155,6 +167,7 @@ impl SheetView {
e: &BytesStart,
empty_flag: bool,
) {
set_string_from_xml!(self, e, show_grid_lines, "showGridLines");
set_string_from_xml!(self, e, tab_selected, "tabSelected");
set_string_from_xml!(self, e, workbook_view_id, "workbookViewId");
set_string_from_xml!(self, e, view, "view");
Expand Down Expand Up @@ -209,6 +222,9 @@ impl SheetView {

// sheetView
let mut attributes: Vec<(&str, &str)> = Vec::new();
if self.show_grid_lines.has_value() {
attributes.push(("showGridLines", self.show_grid_lines.get_value_string()));
}
if *self.tab_selected.get_value() {
attributes.push(("tabSelected", self.tab_selected.get_value_string()));
}
Expand Down
15 changes: 15 additions & 0 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1891,3 +1891,18 @@ fn issue_246() {
let path = std::path::Path::new("./tests/result_files/issue_246.xlsx");
let _ = umya_spreadsheet::writer::xlsx::write(&book, path);
}

#[test]
fn issue_248() {
let mut book = new_file();
let mut sheet = book.get_sheet_mut(&0).unwrap();
sheet
.get_sheet_views_mut()
.get_sheet_view_list_mut()
.get_mut(0)
.unwrap()
.set_show_grid_lines(false);

let path = std::path::Path::new("./tests/result_files/issue_248.xlsx");
let _ = umya_spreadsheet::writer::xlsx::write(&book, path);
}

0 comments on commit 5e20000

Please sign in to comment.