QXlsx
QXlsx copied to clipboard
Problem with sheet selection when writing in file
Hello,
I have an existing excel file with several worksheets. I use QXlsx library to read/write from/in this file.
I open the Excel file with Excel, select the sheet 3, save, close it. Then I run my program to write in sheet 2. Finally if I open again the file with Excel, the 2 sheets (2 and 3) are selected and this can cause problem in future use. The existing method isSelected from Worksheet class does not return the good state.
The code to write in :
QXlsx::Document resultDocument("myFile.xlsx");
resultDocument.selectSheet("2");
QXlsx::Format hFmt;
resultDocument.write(1, 1, 1502, hFmt);
resultDocument.saveAs("myFile.xlsx");
The code to get "state" of worksheets :
QStringList sheetList = document.sheetNames();
for (int i = 0; i < sheetList.size(); i++)
{
bool isSelected = ((QXlsx::Worksheet *)(resultDocument.sheet(sheetList[i])))->isSelected();
qDebug() << "Sheet " << sheetList[i] << " selected = " << isSelected;
}