tfussell / xlnt

:bar_chart: Cross-platform user-friendly xlsx library for C++11+
Other
1.5k stars 423 forks source link

file created in debug model has header error when unzipped #103

Closed hongnod closed 7 years ago

hongnod commented 7 years ago

using following code to create a sample xlsx file, if this code compiled in debug model, the output xlsx file reports header error when it is in the process of unzipping.

xlnt::workbook wb;
xlnt::worksheet ws = wb.active_sheet();
ws.cell("A1").value(5);
ws.cell("B2").value("string data");
ws.cell("C3").formula("=RAND()");
ws.merge_cells("C3:C4");
ws.freeze_panes("B2");
wb.save("test.xlsx");
hongnod commented 7 years ago

one more question: for the test.xlsx file(debug & release), if I modified the B2 cell content to "99", then save it , the value_type lost.(win10 ,office 2013 64 bit)

tfussell commented 7 years ago

Thanks for all the contributions @topillar. I'll get to work on these soon.

hongnod commented 7 years ago

more info, following code will crash, I guess there bug relates to data_type(), or I have made something wrong.

xlnt::workbook wb1; wb1.load("test.xlsx"); qDebug()<<"wbload"; auto sht = wb1.active_sheet(); qDebug()<< "activesheet"; auto cl = sht.cell(2,2); auto typ = cl.data_type(); if(typ == xlnt::cell_type::string) { QMessageBox::about(NULL, "ok", "the cell A1 is string");

 }else
 {
    QMessageBox::about(NULL, "ok", "the cell A1 is not string");
 }
hongnod commented 7 years ago

if (has_type && (type == "inlineStr" || type == "str")) { cell.value(value_string); } else if (has_type && type == "s" && !has_formula) { auto shared_string_index = static_cast(std::stoull(value_string)); auto shared_string = shared_strings.at(shared_string_index); cell.value(shared_string); } else if (has_type && type == "b") // boolean { cell.value(value_string != "0"); } else if (has_value && !value_string.empty()) { if (!value_string.empty() && value_string[0] == '#') { cell.error(value_string); } else { cell.value(std::stold(valuestring)); **// the attach will crash this line, it satisfies !has_type && has_value && !value_string.empty() && valuestring[0] != '#'** } }

sheet1.zip

tfussell commented 7 years ago

For the header issue, I'm assuming you were seeing that warning when unzipping test.xlsx using 7-zip? If so, that problem has been fixed. I'm afraid I couldn't reproduce the second problem you reported. I did clean up the corresponding code so maybe it will be fixed for you. Could you try it again and close this issue if it's working?

tfussell commented 7 years ago

Closing for now. Please comment here if you're still seeing a problem with the headers and otherwise open a new issue if you find any other problems.

hongnod commented 7 years ago

Thanks for your fixes. I tested with the result of : Issue 1 is fixed as desired Issue 2 is still there. flowing is the changing of the "sheet1.xml"

before:

`

5 0 RAND()

`

after: `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

5 999 RAND() 0.56774262335374837 ` Best regards and happy new year!