Hi I have AdvstringGrid installed as a part of my TMS component pack. When I installed TMS Grid Filters, it said that "TMS Advstringgrid is not installed....". Is it anything I missed? Thanks!
For some reason, only the second the grid is exported. I use the same logic for GridExcelIO component. It was ok. I think I must have something wrong when I set up AdvGridExcelExport. Please help!
The logic in AdvGridExcelExport is indeed a little different. The original AdvExcelIO wasn't originally designed to save to multiple sheets, so we had to come out with many ugly workarounds, which weren't very intuitive or performant (each ->Export has to open the existing file, and save it to disk. If you have to export 100 sheets, there is a lot of opening and saving the same file)
AdvGridExcelIO is built around a trimmed version of FlexCel 3 engine, while in AdvGridExcelExport we use the real FlexCel engine. This means that you can use all of FlexCel objects together with AdvGridExcelExport and this makes a lot of stuff much simpler (like for example if you wanted to password protect the file, or do any manual customizations to the output).
Basically, for everything more advanced than just saving a grid or AdvWorkbook to a file, you should use the FlexCel objects directly. This is how you could do this for this example:
//create a file with 2 sheets
std::unique_ptr<TXlsFile> xls(new TXlsFile(2, TExcelFileFormat::v2019, true));
//select first sheet
xls->ActiveSheet = 1;
xls->SheetName = "Sheet1";
AdvGridExcelExport->AdvStringGrid = MyAdvStringGrid1;
AdvGridExcelExport->Export(xls.get(), TInsertInSheet::Clear);
//select second sheet
xls->ActiveSheet = 2;
xls->SheetName = "Sheet2";
AdvGridExcelExport->AdvStringGrid = MyAdvStringGrid2;
AdvGridExcelExport->Export(xls.get(), TInsertInSheet::Clear);
//finaly save the full file with all the sheets.
xls->Save("test.xlsx");
As said, the main advantage here is that you have a full TXlsFile object, which you can use to customize the output as much as you like, using xls->Command() before saving. Remember also that FlexCel comes with an APIMate tool (search for it in the start menu) that will give you the commands you need to do to create some specific task. There is a button in APIMate to return C++ code too.
No, you don't have to manually write out all the cells, that's the idea.
The code I posted above does what you were doing in with AdvExceIO: Exports grid1 to sheet1 and grid2 to sheet2, and it is about the same number of lines of code.
Is the one that writes out the cells. Conceptually, this is doing the same as before, only that before you could only export to a file. I pseudocode, when you wrote in AdvGridExcelIO:
It is just that you didn't had control over the XlsFile object. Everytime you added a sheet with that method, you would read and existing file, add a sheet, export the sheet and save it, which resulted in lots of extra opening and saving.
Now, as AdvGridExcelExport relies in you having a real version of FlexCel installed, we can give you control over the XlsFile object itself, and you can export to that object instead of a file. But the component is doing the same work as before, taking care of manually writing all cells to the file.