Add a new sheet to an existing excel file

xlsxwriter-rs only creates new file; calamine only reads an excel file. Do you guys know about any crate which modifies an existing excel file?

"Modifying" an Excel workbook is really just reading it into memory, modifying the in-memory representation, and writing out the new result to the same file. An Excel file cannot truly be "modified" partially/incrementally, because it's just a gigantic bunch of XMLs in a zip archive. If you want real updating, use a database, not Excel.


I simply want to add a sheet with a small calculated data table to an existing excel file. I don't want to implement my own custom solution if it can be done by a crate easily.

There probably won't be a separate crate with the single specific purpose of adding a sheet to a workbook. Using two crates to read and write back a file hardly counts as a "custom" solution, and it's probably what you should do.

Can you provide a pseudocode using calamine and xlsxwriter? File read using one crate won't be compatible with another crate, and xlsxwriter only creates new files. If I create a new file using xlsxwriter I will have to write the entire contents of the old file cell by cell which is completely unnecessary.

By custom solution I meant manipulating XML files directly.

I think it will be better for your learning if you try to do this yourself. If you are struggling, you can post your code here for others to help you with.

1 Like

Did you try this, or is it only speculation? If this were true, that would completely defeat the purpose of any given format. If you write an XLSX using one crate but the other one can't read it, that's a bug in either (or both) crate(s).

Yet this is basically what Excel itself does. Again, if you have an amount of data that is problematic to read and write in one go, then you shouldn't be storing that data in a spreadsheet.

1 Like

Calamine can read a file but can't write. xlsxwriter can write a xlsx file but can't read. So it is not possible.

The excel file has charts, so your suggestion doesn't work. Some other file may also have VBA code.

1 Like

Why would it not be possible? You read the contents to an in-memory structure using the crate that can read, and then write out the in-memory structure using the crate that can write. Both crates seem to support writing the basic data types (strings, numbers, date/time, etc), so you can write up one to the other quite easily.


xlsxwriter API doesn't allow for it. If you could provide a simple code example, it would be helpful.

It totally does. I'm on my phone right now, but their very own example includes methods like write_string() and write_number(). Not sure what else you would expect.

As I mentioned the file has charts.

Xlsxwriter seems to support adding charts.

1 Like

I don't want to do it that way. The files will change from one to another. I am directly writing the XML files.