Issue Renaming Excel Sheet/Tab Names

Hi,

I was trying to customize the sheet/tab names on the Excel exported document. I currently have two vue-grids with separate data and a single toolbar working at the top. I have the following toolbarClick method shown in the New Sheet example code in the Excel Export documentation and can export both grids to Excel successfully with one sheet renamed but cannot figure out how to rename any other sheets after that. 

Thanks in advance.

toolbarClick code:

toolbarClick : function (args) {
          if (args.item.id === 'FirstGrid_excelexport') { // 'Grid_excelexport' -> Grid component id + _ + toolbar item name
            let appendExcelExportProperties = {
                multipleExport: { type: 'NewSheet' },
                fileName: "Custom File Name.xlsx"
            };
            let firstGridExport = this.$refs.grid1.excelExport(appendExcelExportPropertiestrue);
            firstGridExport.then((fData=> {
              fData.worksheets[0].name = "Renamed First Sheet"// Success changing the sheet name to "Renamed First Sheet"
                this.$refs.grid2.excelExport(appendExcelExportPropertiesfalsefData);
            });
        }
      }




3 Replies 1 reply marked as answer

SK Sujith Kumar Rajkumar Syncfusion Team February 19, 2021 08:18 AM UTC

Hi Andrew, 
 
Greetings from Syncfusion support. 
 
You can achieve your requirement of renaming multiple sheets(for multiple Grids exported in new sheets) by accessing the second Grid’s then function(by setting multiple export argument as true while calling the excel export method on the second Grid), renaming the second worksheet name and then performing the excel file save action in the sample level. This is demonstrated in the below code snippet, 
 
import { Workbook } from "@syncfusion/ej2-excel-export"; 
 
toolbarClick : function (args) { 
          if (args.item.id === 'FirstGrid_excelexport') { 
            let appendExcelExportProperties = { 
                multipleExport: { type: 'NewSheet' } 
            }; 
            let firstGridExport = this.$refs.grid1.excelExport(appendExcelExportProperties, true); 
            firstGridExport.then((fData) => { 
                // First sheet is renamed 
                fData.worksheets[0].name = "Renamed First Sheet";  
                // Multiple export is enabled in the excel export of the second Grid 
                let secondGridExport = this.$refs.grid2.excelExport(appendExcelExportProperties, true, fData); 
                secondGridExport.then((sData) => { 
                  // Second sheet is renamed 
                  sData.worksheets[1].name = "Renamed Second Sheet";  
                  // A new excel workbook is created with the argument data 
                  const book = new Workbook(sData, "xlsx");  
                  // The excel sheet is saved(downloaded) using the created workbook 
                  book.save("NewFile.xlsx");  
                }); 
            }); 
        } 
} 
 
We have prepared a sample based on this for your reference. You can find it below, 
 
 
Please get back to us if you require any further assistance. 
 
Regards, 
Sujith R 


Marked as answer

AI Andrew I March 4, 2021 09:15 PM UTC

This worked for me, thank you for your help.



SK Sujith Kumar Rajkumar Syncfusion Team March 5, 2021 10:54 AM UTC

Hi Andrew, 
 
You’re welcome. We are glad to hear that the provided solution helped resolve your query. 
 
Please get back to us if you require any further assistance. 
 
Regards, 
Sujith R 


Loader.
Up arrow icon