This lib seems very promising and quite complete. I've added a little function in WorkBook.h:
CWorksheet * GetSheetByName(std::string title)
{
for ( size_t i = 0; i < m_worksheets.size(); i++ )
if ( title == m_worksheets[ i ]->GetTitle().toStdString() )
return m_worksheets[ i ];
}
Without it, I didn't find any way to create a wrapper class with a constructor that build the workbook, a functions that add a sheet and another that add data.
All provided samples are monolithic code bloc, which seems to me not enough close to the usage I plan to do.
It could be helpful to have a set of functions to handle sheets easily.
Regards
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
Thank you for your offer. Can you explain in more detail what is difficult about creating your wrapper class?
Now you can create a worksheet using the CWorkbook::AddSheet method and get a reference to the new CWorksheet (you can get a pointer from this reference). This reference to the CWorksheet (and the pointer obtained from it) is correct until the end of the life of the CWorkbook object or the save of the workbook.
This library was originally designed to fast save large amounts of data. Because of this, when creating a CWorksheet object, an XML file is immediately created for it with information that cannot be changed. This creates a number of restrictions on manipulations with worksheets.
Because of this, when using the library, you need to know the structure of the workbook in advance.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
// create a sheet
AddSheet(std::string sheetTitle);
// add data to the created sheet
AddData(std::string sheetTitle, std::map<std::string, std::vector\<std::string="">> data);
// to close and save the file
saveFile(std::string fileName);</std::string,>
But doing this, it was impossible due to compiler error that requires some default constructor for CWorksheet. I am using VS 2022 and impossible to find any way to do this done.
"Now you can create a worksheet using the CWorkbook::AddSheet method and get a reference to the new CWorksheet (you can get a pointer from this reference). This reference to the CWorksheet (and the pointer obtained from it) is correct until the end of the life of the CWorkbook object or the save of the workbook."
That is what I tried to do, but the compiler did not accept this way of doing without an existing CWorksheet public default constructor. May be there is no issue with gcc.
I did compile example samples, and they work.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I apologize for taking a long time to answer - I had problems with free time. You probably need a solution something like this:
#include<map>#include<string>#include<Xlsx/Workbook.h>usingnamespaceSimpleXlsx;classCWrapper{public:// create a sheetvoidAddSheet(conststd::string&sheetTitle){CWorksheet&Sheet=m_book.AddSheet(sheetTitle);m_Sheets[sheetTitle]=&Sheet;}// add data to the created sheetvoidAddData(conststd::string&sheetTitle,intdata){std::map<std::string,CWorksheet*>::iteratorit=m_Sheets.find(sheetTitle);if(it==m_Sheets.end())// Or assert( it != m_Sheets.end() ) if it is correct for your situationreturn;it->second->BeginRow().AddCell(data).EndRow();}// to close and save the filevoidsaveFile(conststd::string&fileName){m_book.Save(fileName);}private:CWorkbookm_book;std::map<std::string,CWorksheet*>m_Sheets;// Name and pointer};intmain(){CWrapperW;W.AddSheet("Test");W.AddData("Test",123);W.saveFile("WrapperTest.xlsx");return0;}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
This lib seems very promising and quite complete. I've added a little function in WorkBook.h:
CWorksheet * GetSheetByName(std::string title)
{
for ( size_t i = 0; i < m_worksheets.size(); i++ )
if ( title == m_worksheets[ i ]->GetTitle().toStdString() )
return m_worksheets[ i ];
}
Without it, I didn't find any way to create a wrapper class with a constructor that build the workbook, a functions that add a sheet and another that add data.
All provided samples are monolithic code bloc, which seems to me not enough close to the usage I plan to do.
It could be helpful to have a set of functions to handle sheets easily.
Regards
Hi,
Thank you for your offer. Can you explain in more detail what is difficult about creating your wrapper class?
Now you can create a worksheet using the CWorkbook::AddSheet method and get a reference to the new CWorksheet (you can get a pointer from this reference). This reference to the CWorksheet (and the pointer obtained from it) is correct until the end of the life of the CWorkbook object or the save of the workbook.
This library was originally designed to fast save large amounts of data. Because of this, when creating a CWorksheet object, an XML file is immediately created for it with information that cannot be changed. This creates a number of restrictions on manipulations with worksheets.
Because of this, when using the library, you need to know the structure of the workbook in advance.
Hi,
I've tried to create a wrapper class with
// create a sheet
AddSheet(std::string sheetTitle);
// add data to the created sheet
AddData(std::string sheetTitle, std::map<std::string, std::vector\<std::string="">> data);
// to close and save the file
saveFile(std::string fileName);</std::string,>
But doing this, it was impossible due to compiler error that requires some default constructor for CWorksheet. I am using VS 2022 and impossible to find any way to do this done.
"Now you can create a worksheet using the CWorkbook::AddSheet method and get a reference to the new CWorksheet (you can get a pointer from this reference). This reference to the CWorksheet (and the pointer obtained from it) is correct until the end of the life of the CWorkbook object or the save of the workbook."
That is what I tried to do, but the compiler did not accept this way of doing without an existing CWorksheet public default constructor. May be there is no issue with gcc.
I did compile example samples, and they work.
Hi,
I apologize for taking a long time to answer - I had problems with free time. You probably need a solution something like this: