umya-spreadsheet icon indicating copy to clipboard operation
umya-spreadsheet copied to clipboard

comments in original excel file are lost

Open MarcoBelluDev opened this issue 6 months ago • 5 comments

Hi,

I found a new issue when opening and saving an excel file with umya-spreadsheet. Existing comments are deleted. Consider attached excel file with a comment in cell B2.

test.xlsx

When using following script:

use umya_spreadsheet::{reader, writer};

fn main() {
    // path
    let path = "test.xlsx";

    // 1. open excel file
    let mut book = match reader::xlsx::read(path) {
        Ok(b) => b,
        Err(e) => {
            eprintln!("Errore durante la lettura: {}", e);
            return;
        }
    };

    // 2. take sheet
    let sheet = book.get_sheet_mut(&0).expect("Foglio non trovato");

    // 3. Write "test" in B7
    sheet.get_cell_mut("B7").set_value("test");

    // 4. Save file
    if let Err(e) = writer::xlsx::write(&book, path) {
        eprintln!("Errore durante il salvataggio: {}", e);
    } else {
        println!("File salvato correttamente.");
    }
}

The new resulting excel file will not have comment in B2 anymore.

MarcoBelluDev avatar Jun 25 '25 13:06 MarcoBelluDev

As a work around I suspect you can save the comment before and set it after. I don't know much about the structure and if it's necessary to overwrite. Just a quick check gave me that ideas a workaround and mentioned it in case it helpful https://docs.rs/umya-spreadsheet/latest/umya_spreadsheet/structs/struct.Comment.html

c-git avatar Jun 25 '25 23:06 c-git

Yes but working with big files with many comments will be complicated. It would be great if this could be fixed directly in umya 🙂

MarcoBelluDev avatar Jul 01 '25 07:07 MarcoBelluDev

@ROMA96x Thank you for contacting us. We will investigate the cause.

MathNya avatar Jul 03 '25 00:07 MathNya

@ROMA96x Fixed a bug. Please get the latest version.

MathNya avatar Aug 05 '25 09:08 MathNya

Hi @MathNya, I updated to version umya-spreadsheet = "2.3.2" but I still see the issue.

Image

Best regards, Marco

MarcoBelluDev avatar Aug 05 '25 18:08 MarcoBelluDev