umya-spreadsheet
umya-spreadsheet copied to clipboard
Corrupt Theme
I think I'm doing a fairly simple set of write operations, but when I open the file in Excel, the file opens in readonly mode unless I ask Excel to repair the file. The reported error is:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
<logFileName>error456680_01.xml</logFileName>
<summary>Errors were detected in file 'C:\exported (4).xlsx'</summary>
<additionalInfo>
<info>Excel completed file level validation and repair. Some parts of this workbook may have been repaired or discarded.</info>
</additionalInfo>
<removedRecords>
<removedRecord>Removed Records: Document Theme from /xl/workbook.xml part (Workbook)</removedRecord>
</removedRecords>
</recoveryLog>
Here is my code:
pub fn export_excel(&self) -> Result<Vec<u8>> {
let mut book = Spreadsheet::default();
for sheet in self.sheets() {
let worksheet = book
.new_sheet(sheet.name.to_string())
.map_err(|e| anyhow!("Error creating excel sheet: {}", e))?;
let bounds = sheet.bounds(true);
// add grid values to the worksheet
match bounds {
GridBounds::Empty => continue,
GridBounds::NonEmpty(rect) => {
for y in rect.y_range() {
for x in rect.x_range() {
let pos = Pos { x, y };
let cell = worksheet.get_cell_mut(pos.a1_string());
cell.set_value(cell_value.to_string());
}
}
}
}
let mut writer = vec![];
writer::xlsx::write_writer(&mut book, &mut writer)
.map_err(|e| anyhow!("Error writing excel file: {}", e))?;
Ok(writer)
}
Is it because I'm creating a default spreadsheet?
let mut book = Spreadsheet::default();
My use case is that I need to output the bytes in the browser since I can't write to a filesystem in wasm. Any thoughts?
@ddimaria Thank you for contacting us. Here is the implementation for creating a new file.
let mut book = umya_spreadsheet::new_file();