- 
                Notifications
    
You must be signed in to change notification settings  - Fork 377
 
Closed
Labels
bugSomething isn't workingSomething isn't workingresolvedThis issue has been resolved.This issue has been resolved.
Description
The issue example:
OpenXLSX::XLDocument doc; // this is used to create and save the workbook
std::vector<std::vector<std::string>> data; // this contains the data to be saved in 2D matrix for easy insertion into excel
doc.create(workbook1, true);
OpenXLSX::XLWorksheet wks = doc.workbook().worksheet("Sheet1");
// Inserting data into the workbook
for (std::size_t i = 0; i < data.size(); ++i) 
{
    for (std::size_t j = 0; j < data[i].size(); ++j)
    {
        wks.cell(OpenXLSX::XLCellReference(static_cast<uint16_t>(i) + 1, static_cast<uint16_t>(j) + 1)).value() = data[i][j];
    }
}
doc.save()
doc.close()
doc.create(workbook2, true);
wks = doc.workbook().worksheet("Sheet1");
// Inserting data into the workbook
for (std::size_t i = 0; i < data.size(); ++i) 
{
    for (std::size_t j = 0; j < data[i].size(); ++j)
    {
        wks.cell(OpenXLSX::XLCellReference(static_cast<uint16_t>(i) + 1, static_cast<uint16_t>(j) + 1)).value() = data[i][j];
    }
}
doc.save()
doc.close()
In the above example the second workbook does not contain any data, but if I change some data in the std::vector<std::vector<std::string>> data matrix then the changed data is inserted into the second matrix but not anything else
Currently the workaround is to create a new OpenXLSX::XLDocument doc like this:
OpenXLSX::XLDocument doc; // this is used to create and save the workbook
std::vector<std::vector<std::string>> data; // this contains the data to be saved in 2D matrix for easy insertion into excel
doc.create(workbook1, true);
OpenXLSX::XLWorksheet wks = doc.workbook().worksheet("Sheet1");
// Inserting data into the workbook
for (std::size_t i = 0; i < data.size(); ++i) 
{
    for (std::size_t j = 0; j < data[i].size(); ++j)
    {
        wks.cell(OpenXLSX::XLCellReference(static_cast<uint16_t>(i) + 1, static_cast<uint16_t>(j) + 1)).value() = data[i][j];
    }
}
doc.save()
doc.close()
OpenXLSX::XLDocument doc2;
doc2.create(workbook2, true);
wks = doc2.workbook().worksheet("Sheet1");
// Inserting data into the workbook
for (std::size_t i = 0; i < data.size(); ++i) 
{
    for (std::size_t j = 0; j < data[i].size(); ++j)
    {
        wks.cell(OpenXLSX::XLCellReference(static_cast<uint16_t>(i) + 1, static_cast<uint16_t>(j) + 1)).value() = data[i][j];
    }
}
doc2.save()
doc2.close()
then everything works as expected.
Is the first way not correct?
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingresolvedThis issue has been resolved.This issue has been resolved.