MathNya / umya-spreadsheet

A pure rust library for reading and writing spreadsheet files
MIT License
294 stars 46 forks source link

Is it supports excel sheet with pivot table ? #238

Open pcenshao opened 1 day ago

pcenshao commented 1 day ago

Firstly, this is a good library,think you author. Before this ,I use calamine for reading excel,and use rust_xlsxwriter for writing excel.But,when I want to modify a excel file,this method is hard to satisfy this situation.umya-spreadsheet can very good to do this work.

Important Point Below

When read a excel sheet with pivot table,it works good,also can read formula cells.But after write to the same excel file,open excel with Microsoft Office app,the pivot table disappeared.

the code:

` fn run_ln_code(self: &Self) -> Result<(), String> { let path = std::path::Path::new("aaa.xlsx"); let mut book = umya_spreadsheet::reader::xlsx::read(path).unwrap(); let sheet = book.get_sheet_by_name_mut("Sheet1").ok_or("找不到Sheet1".to_string())?;

    print_cell_at("A1", sheet);
    print_cell_at("B1", sheet);
    print_cell_at("B2", sheet);
    print_cell_at("C1", sheet);
    print_cell_at("P1", sheet); // P1是一个公式单元格,包含读取数据透视表的公式,读取没问题。

    let mut c2 = sheet.get_cell_mut("C2");
    print_cell(c2);
    // c2.set_value_number(666666.6666);
    c2.set_formula("=100*100");

    // umya_spreadsheet::writer::xlsx::write(&book, path).map_err(|e| e.to_string())?; // 此包含透视表的sheet,如果使用umya写入,会导致丢失数据透视表。

    Ok(())
}

`

thinks.

MathNya commented 18 hours ago

@pcenshao Thank you for contacting us. umya-spreadsheet does not support pivot tables. It does support tables, which are a similar function.

Pivot table support may be a bit further down the road. I will try to support it eventually.