mirror of
https://github.com/storytold/gridcraft.git
synced 2026-11-29 01:36:39 +01:00
Split XLSX workbook validation from writer
This commit is contained in:
1 parent
493ceae678
commit
6856c3cfdf
1 file changed
+6
-2
@@ -240,14 +240,18 @@ fn workbook_view_attrs(wb: &Workbook) -> String {
|
||||
|
||||
/// Writes the workbook for the file `book_name` (a bare file name). A PivotChart is bound to its
|
||||
/// PivotTable in Excel only when its link starts with the workbook in brackets.
|
||||
pub fn write_xlsx_named(wb: &Workbook, kind: XlsxKind, book_name: Option<&str>) -> Result<Vec<u8>, IoError> {
|
||||
fn validate_xlsx_workbook(wb: &Workbook) -> Result<(), IoError> {
|
||||
if wb.sheets.is_empty() {
|
||||
return Err(IoError::Format("a workbook needs at least one sheet".into()));
|
||||
}
|
||||
if wb.sheets.iter().any(|sheet| sheet.cell_pictures.keys().any(|c| sheet.cell(*c).is_some_and(|cell| cell.formula.is_some()))) {
|
||||
return Err(IoError::Format("a static cell picture cannot also contain a formula".into()));
|
||||
}
|
||||
check_sheet_names(wb)?;
|
||||
check_sheet_names(wb)
|
||||
}
|
||||
|
||||
pub fn write_xlsx_named(wb: &Workbook, kind: XlsxKind, book_name: Option<&str>) -> Result<Vec<u8>, IoError> {
|
||||
validate_xlsx_workbook(wb)?;
|
||||
let mut out = Out {
|
||||
parts: vec![],
|
||||
overrides: vec![],
|
||||
|
||||
Reference in new issue
Block a user