MathNya / umya-spreadsheet

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

Can I change the value of a cell from a opening book without closing it? #120

Closed baiguoname closed 10 months ago

baiguoname commented 1 year ago

The work process: close the book -> delete the book -> run the code -> open the book, is too long for some small tasks. Can I just modify the existing book without closing it? (like xlwings in python)

MathNya commented 1 year ago

hi baiguoname.

You can change value of a cell by following this procedure.

// file path
let path = std::path::Path::new("./tests/test_files/aaa_replace.xlsx");
// open the book
let mut book = umya_spreadsheet::reader::xlsx::read(path).unwrap();
// change value
book.get_sheet_by_name_mut("Sheet1").unwrap().get_cell_mut("A1").set_value("TEST");
// save file
let _ = umya_spreadsheet::writer::xlsx::write(&book, path);
baiguoname commented 1 year ago

Yes, that is a wonderful way. But sometimes there may be a more convenient way to play data. For example, I have a data in Rust repl . I need to know the detail of the data, then I write the data to a excel, and open the excel to check the detail of it. And next, I modify the data and again check the detail of the data. I have to close the old excel, and run the program(saving data to excel), and open the file again. If I can save the data to excel without closing the file, then I don't have to redo opening and closing again and again.

MathNya commented 1 year ago

@baiguoname I finally understand your question. Umya-spreadsheet cannot perform operations like xlwings. This library is designed like pandas in python.