tfussell / xlnt

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

Create my first sheet not working, #462

Closed barthoukes closed 4 years ago

barthoukes commented 4 years ago

I'm migrating from xlsxwriter to your program because I also need to read xlsx. My first attempt already crashes in the second line of code at create_sheet. What is wrong with my code? I'm using 1.5.0, which builds perfect on Ubuntu.

xlnt::workbook  m_workbook;

void CexcelWriter::createWorkSheet(const std::string &worksheetName)
{
 if ( m_workbook.contains(worksheetName))
    {
        m_worksheet = m_workbook.sheet_by_title(worksheetName);
    }
    else
    {
        xlnt::worksheet worksheet = m_workbook.create_sheet();  <== throw error ????
        worksheet.title(worksheetName);
    }

ERROR, which does not ring a bell:

terminate called after throwing an instance of 'xlnt::key_not_found'
  what():  xlnt::exception : key not found in container
barthoukes commented 4 years ago

Somehow, if I create the worksheet when I need it ( std::shared_ptr ) instead of adding a class member, then it's working and I see the excel sheet.