umya-spreadsheet
umya-spreadsheet copied to clipboard
Sheet state not persisted when saving file
When opening an XLSX file with hidden sheet and saving it, it does not keep the state of hidden sheet.
After investigating, the state field is not even present anymore on the workbook.xml file for any sheet.
I tried to manually call this code but it does not work.
sheet.set_sheet_state("hidden".to_string());
Here is basically what I am doing:
pub struct ExcelModifier {
book: Spreadsheet,
}
impl ExcelModifier {
pub fn from_file(path: &str) -> Result<Self> {
let path = Path::new(path);
let book = xlsx::read(path)?;
Ok(ExcelModifier { book })
}
pub fn save_to_file(&self, path: &str) -> Result<()> {
let path = Path::new(path);
write(&self.book, path)?;
Ok(())
}
}
fn main() {
let mut modifier = ExcelModifier::from_file("path/to/file").unwrap();
modifier.save_to_file("./result.xlsx").unwrap();
}
@Aeradriel Thank you for contacting us. We will investigate the cause of the problem.
@Aeradriel Fixed issue. Please get the latest version and check it.
To hide the sheet programmatically, do the following
let path = std::path::Path::new("./tests/test_files/issue_217.xlsx");
let mut book = reader::xlsx::read(path).unwrap();
book.get_sheet_mut(&2)
.unwrap()
.set_state(SheetStateValues::Hidden);
let path = std::path::Path::new("./tests/result_files/issue_217.xlsx");
let _ = writer::xlsx::write(&book, path);
Thanks for your quick intervention. It appears to be working on my side!