Hi
I have multiple Pivot tables, tree grids and textboxes on a page. and want to export all of them into single excel file. how do i achieve this ?
|
onClick(e: Event): void {
let excelExportProperties = {
multipleExport: { type: 'AppendToSheet', blankRows: 2 }
};
let firstGridExport: Promise<any> = this.pivotObj.grid.excelExport(excelExportProperties, true);
firstGridExport.then((fData: any) => {
this.treegrid.grid.excelExport(excelExportProperties, false, fData);
});
}
|
it works fine for 2 based on the example in stackblitz. but if i add another pivot then it creates 2 export files. On my page i have more than 6 pivot tables. and said code is not working.
Is. there something i am missing ?
I dont know there is something not right.....
as I mentioned earlier I have TreeGrid also on the page.....
Here is what i am doing on the page. on html side i have div. which i am appending my treegrid into the div. as mentioned in below snippet.
while using export to excel functionality, Below line is giving me null error and it's not exporting data into excel even for normal treegrid view...
What am i doing wrong... ???
Additionally, I am also getting this error
ERROR Error: Uncaught (in promise): Error: Style name _gridcontrolcolumn1 is already existed
please note that i have tried with 2 treegirds. (single grid export was successful)
|
Index.ts
let treegrid: TreeGrid = new TreeGrid({
dataSource: sampleData,
childMapping: 'subtasks',
treeColumnIndex: 1,
. . .
});
treegrid.appendTo('#TreeGrid'); // Render First TreeGrid
let treegrid1: TreeGrid = new TreeGrid({
dataSource: sampleData.slice(0, 3),
childMapping: 'subtasks',
treeColumnIndex: 1,
height: 220,
. . .
});
treegrid1.appendTo('#TreeGrid2'); // Render Second TreeGrid
treegrid.toolbarClick = (args?: ClickEventArgs) => {
if (args.item.id === treegrid.grid.element.id + '_excelexport') {
let excelExportProperties: TreeGridExcelExportProperties = {
multipleExport: { type: 'AppendToSheet', blankRows: 2 },
isCollapsedStatePersist: collapsedStatePersist
};
var treegridObj = document.getElementsByClassName('e-treegrid')[0]
.ej2_instances;
let treegrid: Promise<any> = treegridObj[0].grid.excelExport(
excelExportProperties,
true
);
treegrid.then((fData: any) => {
treegrid1.grid.excelExport(excelExportProperties, false, fData);
});
}
};
|
|
App.component.html
<ejs-treegrid id="treegrid1" #treegrid1 [dataSource]='data' childMapping='subtasks' height='350' [treeColumnIndex]='1' allowExcelExport='true'>
<e-columns>
<e-column field='taskID' headerText='Task ID' width='70' textAlign='Right'></e-column>
<e-column field='taskName' headerText='Task Name' width='200'></e-column>
. . .
</e-columns>
</ejs-treegrid>
<ejs-treegrid id="treegrid2" #treegrid2 [dataSource]='data' childMapping='subtasks' height='350' [treeColumnIndex]='1' allowExcelExport='true'>
<e-columns>
<e-column field='taskID' headerText='Task ID' width='70' textAlign='Right'></e-column>
. . .
</e-columns>
</ejs-treegrid> |
Thanks this seems to be solving the issue.
one more request, how do i export Textboxe values into Excel ? is there some example i can follow ?
|
export class AppComponent {
@ViewChild('default')
public textareaObj: TextBoxComponent;
// set the placeholder to DropDownList input element
public waterMark: string = 'Select float type';
// set the value to select an item based on mapped value at initial rendering
onclick() {
$.ajax({
type: 'POST',
url: { respective controller method in server} ',
data: { 'inputText' : this.textareaObj.value },
success: data => {
console.log("success")
},
error: function(response) {
console.log ('Error');
}
});
}
}
|
Hi,
Is there any possibilities to export two tree grid in single excel sheet side-by-side instead of up-down without grouping
| Task ID | Task Name | Start Date | End Date | Duration | Progress | Priority | Task ID | Task Name | Start Date | End Date | Duration | Progress | Priority | |
| 1 | Planning | 2/3/2017 | 2/7/2017 | 5 | 100 | Normal | 1 | Planning | 2/3/2017 | 2/7/2017 | 5 | 100 | Normal | |
| 2 | Plan timeline | 2/3/2017 | 2/7/2017 | 5 | 100 | Normal | 2 | Plan timeline | 2/3/2017 | 2/7/2017 | 5 | 100 | Normal | |
| 3 | Plan budget | 2/3/2017 | 2/7/2017 | 5 | 100 | Low | 3 | Plan budget | 2/3/2017 | 2/7/2017 | 5 | 100 | Low | |
| 4 | Allocate resources | 2/3/2017 | 2/7/2017 | 5 | 100 | Critical | 4 | Allocate resources | 2/3/2017 | 2/7/2017 | 5 | 100 | Critical | |
| 5 | Planning complete | 2/7/2017 | 2/7/2017 | 0 | 0 | Low | 5 | Planning complete | 2/7/2017 | 2/7/2017 | 0 | 0 | Low | |
| 6 | Design | 2/10/2017 | 2/14/2017 | 3 | 86 | High | 6 | Design | 2/10/2017 | 2/14/2017 | 3 | 86 | High | |
| 7 | Software Specification | 2/10/2017 | 2/12/2017 | 3 | 60 | Normal | 7 | Software Specification | 2/10/2017 | 2/12/2017 | 3 | 60 | Normal | |
| 8 | Develop prototype | 2/10/2017 | 2/12/2017 | 3 | 100 | Critical | 8 | Develop prototype | 2/10/2017 | 2/12/2017 | 3 | 100 | Critical | |
| 9 | Get approval from customer | 2/13/2017 | 2/14/2017 | 2 | 100 | Low | 9 | Get approval from customer | 2/13/2017 | 2/14/2017 | 2 | 100 | Low | |
| 10 | Design Documentation | 2/13/2017 | 2/14/2017 | 2 | 100 | High | 10 | Design Documentation | 2/13/2017 | 2/14/2017 | 2 | 100 | High | |
| 11 | Design complete | 2/14/2017 | 2/14/2017 | 0 | 0 | Normal | 11 | Design complete | 2/14/2017 | 2/14/2017 | 0 | 0 | Normal | |
| 12 | Implementation Phase | 2/17/2017 | 2/27/2017 | 11 | 66 | Normal | 12 | Implementation Phase | 2/17/2017 | 2/27/2017 | 11 | 66 | Normal | |
| 13 | Phase 1 | 2/17/2017 | 2/27/2017 | 11 | 50 | High | 13 | Phase 1 | 2/17/2017 | 2/27/2017 | 11 | 50 | High | |
| 14 | Implementation Module 1 | 2/17/2017 | 2/27/2017 | 11 | 10 | Normal | 14 | Implementation Module 1 | 2/17/2017 | 2/27/2017 | 11 | 10 | Normal | |
| 15 | Development Task 1 | 2/17/2017 | 2/19/2017 | 3 | 50 | High | 15 | Development Task 1 | 2/17/2017 | 2/19/2017 | 3 | 50 | High | |
| 16 | Development Task 2 | 2/17/2017 | 2/19/2017 | 3 | 50 | Low | 16 | Development Task 2 | 2/17/2017 | 2/19/2017 | 3 | 50 | Low | |
| 17 | Testing | 2/20/2017 | 2/21/2017 | 2 | 0 | Normal | 17 | Testing | 2/20/2017 | 2/21/2017 | 2 | 0 | Normal | |
| 18 | Bug fix | 2/24/2017 | 2/25/2017 | 2 | 0 | Critical | 18 | Bug fix | 2/24/2017 | 2/25/2017 | 2 | 0 | Critical | |
| 19 | Customer review meeting | 2/26/2017 | 2/27/2017 | 2 | 0 | High | 19 | Customer review meeting | 2/26/2017 | 2/27/2017 | 2 | 0 | High | |
| 20 | Phase 1 complete | 2/27/2017 | 2/27/2017 | 0 | 50 | Low | 20 | Phase 1 complete | 2/27/2017 | 2/27/2017 | 0 | 50 | Low | |
| 21 | Phase 2 | 2/17/2017 | 2/28/2017 | 12 | 60 | High | 21 | Phase 2 | 2/17/2017 | 2/28/2017 | 12 | 60 | High | |
| 22 | Implementation Module 2 | 2/17/2017 | 2/28/2017 | 12 | 90 | Critical | 22 | Implementation Module 2 | 2/17/2017 | 2/28/2017 | 12 | 90 | Critical | |
| 23 | Development Task 1 | 2/17/2017 | 2/20/2017 | 4 | 50 | Normal | 23 | Development Task 1 | 2/17/2017 | 2/20/2017 | 4 | 50 | Normal | |
| 24 | Development Task 2 | 2/17/2017 | 2/20/2017 | 4 | 50 | Critical | 24 | Development Task 2 | 2/17/2017 | 2/20/2017 | 4 | 50 | Critical |
Hi Nagendra Gupta,
We have forwarded this query to our dependent team and let you know further details by on or before 21st September 2022. Until then we appreciate your patience.
Regards,
Farveen sulthana T
Hi Nagendra Gupta,
Query#:-Is there
any possibilities to export two tree grid in single excel sheet side-by-side
Further analyzing, in
our TreeGrid, it is not feasible to achieve this requirement Export
multiple TreeGrids side by side. Please get back to us if you need any
further assistance.
Regards,
Farveen sulthana T
Hi Farveen,
Thanks for timely update, I can understand the issues. I really appreciate if is there any custom code available to create excel file with two grid data (plain grid or tree), so that I will create manual file for same.
Or Is there any possibilities to mention start column for exporting the data from grid or tree grid.
Lastly, What is the use of isCollapsedStatePersist property in TreeGridExcelExportProperties
Regards
Nagendra Gupta
Hi Nagendra Gupta,
Query#:- I can understand the issues. I really appreciate if is there any custom code available to create excel file with two grid data (plain grid or tree), so that I will create manual file for same.
Or Is there any possibilities to mention start column for exporting the data from grid or tree grid.
We will check the feasibility of this requirement in Grid component and we will let you know further details by on or before 26th September 2022
Query#:- What is the use of isCollapsedStatePersist property in TreeGridExcelExportProperties
When we enable isCollapsedStatePersist property, it specifies the collapsed state persistence in exported file. Refer to the documentation link:-
https://ej2.syncfusion.com/angular/demos/#/bootstrap5/treegrid/exporting-default
isCollapsedStatePersist propertyà true
isCollapsedStatePersist property à false (collapsed state not persisted)
Regards,
Farveen sulthana T
Hi Farveen,
Any update on this?
Hi Nagendra Gupta,
We appreciate your patience.
Query#:-I can understand the issues. I really appreciate if is there any custom code available to create excel file with two grid data (plain grid or tree), so that I will create manual file for same.
Or Is there any possibilities to mention start column for exporting the data from grid or tree grid.
We have achieved your requirement using Grid component. We have override the processInnerRecords method from our source and we have exported the Two grids side by side by using the customized solution. Please refer the below code example and sample for more information.
By default when we exporting multiple Grids it will exported in up and down, because we have generated the index for the rows and cells based on up and down alignment. Please refer the below screenshot for more information.
Screenshot:
To export the Grids as side by side we have to update the organisedRows cells index and set it to the this.rows cells with using load event of the second Grid. Please refer the below screenshot for more information.
Screenshot:
Updated cells index to render the Grids as side by side
Note:- You can use the below way and based on your requirement you can create your own logic to update your organizedRows cells index to the this.rows to achieve your requirement.
|
App.Component.html:- <ejs-grid #grid [dataSource]="data" allowExcelExport="true" [toolbar]='toolbar' (toolbarClick)="toolbarClick($event)"> </ejs-grid> <ejs-grid #gridtwo [dataSource]="datatwo" allowExcelExport="true" (load)="loadtwo()" (toolbarClick)="toolbarClick($event)"> . . . </ejs-grid>
App.Component.ts:-
loadtwo() { //load event of second grid this.gridtwo.excelExportModule.processInnerRecords = function(gObj: any, exportProperties: any, isMultipleExport: any, workbook: any, r: any) { //by overriding the existing method this.groupedColLength = gObj.groupSettings.columns.length; let blankRows: number = 5; let separator: string; let rows: any = []; const colDepth: number = measureColumnDepth(gObj.columns as any); const isExportPropertiesPresent: boolean = !isNullOrUndefined(exportProperties); if (isExportPropertiesPresent && !isNullOrUndefined(exportProperties.multipleExport)) { this.expType = (!isNullOrUndefined(exportProperties.multipleExport.type) ? exportProperties.multipleExport.type : 'AppendToSheet'); if (!isNullOrUndefined(exportProperties.multipleExport.blankRows)) { blankRows = exportProperties.multipleExport.blankRows; } } if (isNullOrUndefined(workbook)) { this.workSheet = []; this.rows = []; this.columns = []; this.styles = []; } else if (this.expType === 'NewSheet') { this.workSheet = workbook.worksheets; this.rows = []; this.columns = []; this.styles = workbook.styles; } else { this.workSheet = []; this.rows = workbook.worksheets[0].rows; this.columns = workbook.worksheets[0].columns; this.styles = workbook.styles; this.rowLength = (this.rows[this.rows.length - 1].index + blankRows); this.rowLength++; }
if (isExportPropertiesPresent) { if (!isNullOrUndefined(isMultipleExport)) { if (!isNullOrUndefined(exportProperties.header) && (isMultipleExport || this.expType === 'NewSheet')) { this.processExcelHeader(JSON.parse(JSON.stringify(exportProperties.header))); } if (!isNullOrUndefined(exportProperties.footer)) { if (this.expType === 'AppendToSheet') { if (!isMultipleExport) { this.footer = JSON.parse(JSON.stringify(exportProperties.footer)); } } else { this.footer = JSON.parse(JSON.stringify(exportProperties.footer)); } } } else { if (!isNullOrUndefined(exportProperties.header)) { this.processExcelHeader(JSON.parse(JSON.stringify(exportProperties.header))); } if (!isNullOrUndefined(exportProperties.footer)) { this.footer = JSON.parse(JSON.stringify(exportProperties.footer)); } } } this.includeHiddenColumn = (isExportPropertiesPresent ? exportProperties.includeHiddenColumn : false); // eslint-disable-next-line @typescript-eslint/no-unused-vars return new Promise((resolve: Function, reject: Function) => { (<{childGridLevel?: number}>gObj).childGridLevel = 0; rows = this.processGridExport(gObj, exportProperties, r); this.globalResolve = resolve; this.gridPool[gObj.id] = true; this.helper.checkAndExport(this.gridPool, this.globalResolve); }).then(() => { const organisedRows: any = []; this.organiseRows(rows, rows[0].index, organisedRows); for (var i = 0; i < this.rows.length; i++) { var index = this.rows[i].cells[this.rows[i].cells.length-1].index; for(var j = 0; j < organisedRows[i].cells.length; j++) { organisedRows[i].cells[j].index = (index++) + 2; } } for(var i = 0; i < this.rows.length; i++) { this.rows[i].cells = this.rows[i].cells.concat(organisedRows[i].cells) } console.log(this.rows); if (!isNullOrUndefined(this.footer)) { if ((this.expType === 'AppendToSheet' && !isMultipleExport) || (this.expType === 'NewSheet')) { this.processExcelFooter(this.footer); } }
if (this.columns.length > 0) { this.sheet.columns = this.columns; } // eslint-disable-next-line @typescript-eslint/no-explicit-any this.sheet.rows = this.rows as any; this.sheet.enableRtl = this.parent.enableRtl; if (this.parent.allowFiltering && gObj.getVisibleColumns().length && isExportPropertiesPresent && exportProperties.enableFilter) { const headerRowLen: number = exportProperties.header ? exportProperties.header.headerRows || exportProperties.header.rows.length : 0; const autoFilters: any = { row: colDepth + headerRowLen, column: this.groupedColLength ? this.groupedColLength + 1 : this.sheet.columns[0].index, lastRow: this.sheet.rows.length, lastColumn: this.sheet.columns.length }; this.sheet.autoFilters = autoFilters; } this.workSheet.push(this.sheet);
this.book.worksheets = this.workSheet; this.book.styles = this.styles; gObj.notify('finalPageSetup', this.book);
if (!isMultipleExport) { if (this.isCsvExport) { if (isExportPropertiesPresent && !isNullOrUndefined(exportProperties.separator) && exportProperties.separator !== ',') { separator = exportProperties.separator; } const book: Workbook = new Workbook( this.book, 'csv', gObj.locale, (<{ currencyCode?: string }>gObj).currencyCode, separator ); if (!this.isBlob) { if (isExportPropertiesPresent && exportProperties.fileName) { book.save(exportProperties.fileName); } else { book.save('Export.csv'); } } else { this.blobPromise = book.saveAsBlob('text/csv'); } } else { const book: Workbook = new Workbook(this.book, 'xlsx', gObj.locale, (<{currencyCode?: string}>gObj).currencyCode); if (!this.isBlob) { if (isExportPropertiesPresent && exportProperties.fileName) { book.save(exportProperties.fileName); } else { book.save('Export.xlsx'); } } else { this.blobPromise = book.saveAsBlob('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); } } if (this.isElementIdChanged) { gObj.element.id = ''; } delete gObj.expandedRows; } return workbook; }); } } |
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/sidebyside840740909.zip
Screenshot
Regards,
Farveen sulthana T
If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.
Hi Farveen,
Thanks for your kind support, its tricky code and you have given example for normal grid i need this for tree grid.
Unable to find processInnerRecords in excelExportModule
Hi Nagendra Gupta,
We have achieved your requirement in Grid component. You can access the Grid Export methods from Grid Instance from treegrid.
this.treegrid2.grid.excelExportModule.processInnerRecords
Regards,
Farveen sulthana T
Hi Farveen,
I have tried treegrid2.grid.excelExportModule but its undefined, excelExportModule is only available in treegrid not in treegrid.grid;
Hi Nagendra Gupta,
We are able to replicate the replicate the problem when we access processInnerRecords with load event of the TreeGrid. We suggest to access the processInnerRecords method of Grid from Treegrid Instance using dataBound event of the TreeGrid.
Refer to the code below:-
|
App.Component.html:-
<ejs-treegrid id="treegrid2" #treegrid2 [dataSource]="data2" childMapping="subtasks" height="350" [treeColumnIndex]="1" allowExcelExport="true" (dataBound)="dataBound($event)" > <e-columns> <e-column field="taskID" headerText="Task ID" width="70" textAlign="Right" ></e-column>
</e-columns> </ejs-treegrid>
App.Component.ts:-
public dataBound(args) { this.treegrid2.grid.excelExportModule.processInnerRecords = function (gObj: any,exportProperties: any, isMultipleExport: any,workbook: any, r: any) { //do your customized action here }; }
|
Please get back to us if you need any further assistance.
Regards,
Farveen sulthana T
Hi Farveen,
Thanks for you update, have you checked same code with tree grid. Still didn't get expected output. Also after implementing this code ExcelQueryCellInfo Events are not executing.
WHAT COMES OUT AFTER IMPLEMENTING PROVIDED CODE
WHAT IS MY REQUIREMENT.
| CBO ERP LTD | |||
| Profit & Loss | |||
| From Date : 01/04/2022 To Date : 06/10/2022 Company : CBO ERP LTD,Steadfast Medishield (CWH),PARTYAPP CHECK | |||
| Print Date & Time: 06/10/2022 19:01 | |||
| Particulars | Debit Amt | Particulars | Credit Amt |
| Expense | 668,867,663.12 | Income | 271,619,894,248.83 |
| Direct Expenses | 6,094,462.57 | Indirect Incomes | (142,881.00) |
| NA | 85,032.00 | Other Income | (142,881.00) |
| Sample | 6,015,494.57 | Sales Accounts | 271,620,037,129.83 |
| Indirect Expenses | 1,991,325.07 | SGST/CGST SALES 12% | 19,396.77 |
| Salary & Expenses | 1,986,722.00 | IGST SALES 12% | 271,619,094,110.07 |
| Salary | 1,986,722.00 | SGST/CGST SALES 5% | 4,200.00 |
| Repair & Maintenance | 4,700.00 | IGST SALES 5% | 1,775,379.48 |
| Office Repair & Maintenance | 4,700.00 | IGST SALES 18% | (596,918.94) |
| Office Expenses | 4,700.00 | SGST/CGST SALES 0% | 2,304.00 |
| Miscellanious Expenses | 1,200.00 | IGST SALES 0% | 43,819.50 |
| Advertisements Expenses | 100.00 | IGST SALES 28% | (310,499.71) |
| Purchase Accounts | 660,781,875.48 | IGST SALES 48% | 157.30 |
| IGST PURCHASE 12% | 527,417.94 | STI 18% (SALE) | 5,181.36 |
| IGST PURCHASE 5% | 156,220.20 | CLOSING STOCK | 9,946,098,458,084.95 |
| IGST PURCHASE 18% | 660,017,969.64 | INCOME (REVENUE) | (142,881.00) |
| IGST PURCHASE 28% | 50,332.45 | ||
| IGST PURCHASE 48% | 19,608.00 | ||
| IGST PURCHASE 30% | 10,527.25 | ||
| GROSS PROFIT | 10,217,051,618,876.70 | ||
| NET PROFIT | 10,217,049,484,670.70 | ||
| Total | 1,02,17,71,84,95,214.75 | Total | 1,02,17,71,84,95,214.78 |
Hi Nagendra Gupta,
As we have mentioned earlier, in our TreeGrid, it is not feasible to achieve this requirement Export multiple TreeGrids side by side. So that we have provided solution in Grid component as per your request.
Regards,
Farveen sulthana T