Hi,
I have a couple of queries regarding excel export of the grid...
Firstly, Is there a way to autofit or at least set the column widths as they appear in an excel export?
Secondly, is there a way to strip out html from the cell content?
thanks
Adam Toone
|
// Grid’s excelQueryCellInfo event
function exportQueryCellInfo(args: ExcelQueryCellInfoEventArgs): any { if (args.column.field === 'FirstName') {
args.value = (args.value as any).replace(/(<([^>]+)>)/gi, ''); //here we strip out html tags from the cell content using replace() function.
}
} |
Hi,
Thanks for the reply.
Query 2 has been succesfully resolved, thanks. However, for query 1 the width of the columns is already set in the grid yet when exported expanded (as there are also 2 levels of child grid) all the columns show squashed up. Below shows the grid in the web page with the column widths as required and then the excel import.
I have even tried setting the args.column.width value in the exportQueryCellInfo function as above yet this takes no effect either.
Do ,you have any more advice on this?
Adam
Look at the Title column. The width of the column is NOT large enough to accommodate the data!
Hi Brain,
Thanks for your update
We have checked your shared information and we could see that the Title column was not large enough to accommodate the data. In excelQueryCellInfo event we have defined the wrapText style property as true then text content will wrap to the next line. Please refer the below code example and sample for more information.
|
excelQueryCellInfo: function(args) { args.style = { wrapText:true }; },
|
Sample: https://stackblitz.com/edit/snx3pj?file=index.ts
API: https://ej2.syncfusion.com/documentation/api/grid/#excelquerycellinfo
Regards,
Rajapandi R
Hi
I have similar problem. Wraped text does not look good in the excel. Is three any chance to autofit to column content not to the column header?
Kind regards
Ela
Hi Elzbieta,
Thanks for the update
Based on your requirement, you want to autofit the columns based on the content value in the exported file. In Excel Export, we don’t have the support to autofit the columns when exporting the grid into a Excel file. The exported column’s width is applied based on the width provided in the Grid Columns Settings. Since this is the behavior of EJ2 Grid.
Regards,
Rajapandi R