The igGridExcelExport permits exporting a grid to a new Excel file. Is it possible to add the data as a worksheet to an existing Excel file?
This last technique works very well, although the header columns for the worksheet created do not have the grid header names. I assume the headerArr was going to be used to correct this, but it wasn't shown how in the sample. However, I was able to call a function we already had to set the header exactly as required.
Thank you for your assistance.
I will take a look at this last technique.
We currently were implementing something similar to the first technique recommended, which was extremely slow when the grid contained many rows. So we switched to using igGridExcelExporter, which was must faster, but always created a separate workbook.
So I tried the second technique, to use the exportEnding event handler, but iterating through the whole worksheet was again very time consuming and much slower than creating a separate workbook.
So I will try this last technique to see whether or not the speed is acceptable.
Hi Ray,
I found another more clean approach for exporting the grid to an existing excel file, without iterating through the whole worksheet.You can bind to the headerCellExporting event of the igGridExcelExporter and add the following code snippet:
headerCellExporting: function(sender, args) { var headerArr = []; // We will save all the headers coming to our array for retrieval later on headerArr.push(args.headerText); if (args.columnIndex === 0) { sender._workbook = workbook; sender._worksheet = sender._workbook.worksheets(1); } }
Here is a sample for your reference:
igGridExcelExportToExistingFile (2).zip
Please, let me know if you have any questions.
Best regards,Hristo Popov
Hello Ray,
Thank you for your patience!
I have created two samples, whose approaches you can follow for achieving the desired behavior.The first sample demonstrates how to import Data from excel, create a workbook from the imported data, add new worksheet to the workbook and initialize this worksheet with grid data (which is described in this help topic).igExcelExportToExistingFile.zip
The second sample demonstrates how you can use igGridExcelExporter's exportEnding event to export grid data to an existing excel file. It is similar to the first approach with the difference that you have to populate the new worksheet with the igGridExcelExporter's generated worksheet and switch the igGridExcelExporter's workbook with the one, generated from the imported excel file. The event handler looks like this:
exportEnding: function (sender, args) { for (let rowIndex = 0; rowIndex < args.worksheet.rows() .count(); rowIndex++) { let row = args.worksheet.rows(rowIndex) for (let cellIndex = 0; cellIndex < row.cells() .count(); cellIndex++) { worksheet.rows(rowIndex).setCellValue(row.cells(cellIndex) .columnIndex(), row.cells(cellIndex).value()) } } sender._workbook = workbook; }
Here is the second sample for your reference:
igGridExcelExportToExistingFile.zip
Please, take a look at the two samples, import your excel files to test them and let me know if you have any questions. Best regards,
Hristo Popov
I am currently working on two samples, which I am going to provide you tomorrow.
Each sample demonstrates a different approach for achieving the desired functionality.
Thank you for your patience.