I'm using:
pubLink: function(field, data, column){
let link = "<a rel='nofollow' href='" + data["link"] + "' target='_blank'>" + data['title'] + "</a><br>" + data['authors'] + "<br>" + data['publication'] ;
return link
}
To display multi line information in a grid column. The data looks fine but I was wondering is there a way to show multi lines when exporting to Excel? When I do it now the <br>'s are removed but the data is all on one line. I have also used
excelQueryCellInfo: function (args) {
if(args.column.field === "title"){
args.style = { wrapText:true };
}
},
That will allow text wrapping but it still does not line break in the correct location. Is there a way to replace the BR with something that Excel will read as a line feed? I've tried adding vbCrLf but it is showing as text
I ended up doing
excelQueryCellInfo: function (args) {
if(args.column.field === "title"){
args.style = { wrapText:true };
var regex = /<br\s*[\/]?>/gi;
args.value = args.value.replace(regex, "\n");
}
},
Do you think this is the best way to do it?-- it seems to work
Has anyone come up with a way to replace the HTML
tag <br> with an Excel line feed that will work?
I read an article at CodeSnip:Export DataTable to Excel: ASP Alliance that is interesting, but I can't dig that far into the Excel output
I can remove the
's but that then just removes the line feed and it seems that I can't put chr(10) or vbClLf and still have the JavaScript to work.
Thanks
Bill
Hi William,
Currently, we are validating your query at our end. We will provide further details on or before June 16th, 2022.
We appreciate your patience until then.
Regards,
Rajapandiyan S
Hi William,
Thanks for your patience.
By default Excel export does not support <br/> HTML element for adding new line. We suggest to replace the <br/> element with ‘\n’ and set the cell style's WrapText as TRUE in the `excelQueryCellInfo` event of the EJ2 Grid. This will achieve the new line in Excel worksheet.
Please refer the below code example.
|
function excelQueryCellInfo(args) { if (args.column.field == 'FirstName') { args.style = { wrapText: true }; var regex = /<br\s*[\/]?>/gi; args.value = args.value.replace(regex, '\n'); } debugger; }
|
Sample: https://stackblitz.com/edit/zg2yyc-mlki9n?file=index.js,index.html
Please let us know if you need further assistance.
Regards,
Joseph I.
I've using that code for the last year and a half and maybe I'm using it wrong. Are you saying that if I have HTML code that is being created in code of:
"See the dog <br> jump" or "See the dog <br/> jump" I should see in Excel that there is a line break between dog and jump. Or only that the text will wrap. Text wrapping is not the issue. Creating a Professional document is the issue I need to produce the out put so it looks like the image
It is possible because I can do it with another product. This needs to be escalated
Hi William,
Thanks for your update.
Currently we are working on your query, we will provide further details on or before 21st June, 2022. We appreciate your patience until then.
Regards,
Joseph I.
Hi William,
Sorry for the inconvenience caused.
We are still validating your query, we will provide further details on or before 23rd June, 2022. We appreciate your patience until then.
Regards,
Joseph I.
Just checking in-- any additional thoughts on line breaks?
Hi William,
Sorry for the late response.
We have analyzed this and it is not feasible to replace <br/> tag while excel exporting as it might break other users who are already using it. As we have updated earlier, we suggest you replace the <br/> text with “\n” by using the code “args.value = args.value.replace(regex, '\n');” in the excelQueryCellInfo event of the EJ2 Grid.
Please get back to us for further details.
Regards,
Joseph I.
Let me be 100% clean with what you are saying. You are saying replace a HTML tag of <br/> or <br> with an empty string?
So I line that looks like this in the Datagrid
Tuesday, June 7th 2022
Schedule for:
Robert Smith
Meeting with XXX
Lunch with YYY
Will look like:
Tuesday, June 7th 2022 Schedule for: Robert Smith Meeting with XXX Lunch with YYY
If that's the answer, then honestly that is not a solution.
Are you saying that there is no way possible for a Syncfusion Excel Export to show separate lines unless it is the standard text wrap? If this is the case, then I would say that this is a bug or a missing feature
Hi William,
Sorry for the inconvenience caused.
In our last updates
we were intending to say to replace the <br> or <br/> tag with the and not the empty string. Please use
the following code line
in the excelQueryCellInfo event of the EJ2
Grid which will display the content in the new line. Due to some issues the new
line symbol was not displayed in the update.
Sample: https://stackblitz.com/edit/zg2yyc-mlki9n?file=index.js,index.html
Please get back to us for further details.
Regards,
Joseph I.
NOW THIS IS PERFECT. Honestly from a business point of view this can now export beautiful Excel Reports.
Hi William,
Thanks for your update.
We are happy to hear that issue has been resolved.
Please get back to us if you need further assistance on this.
Regards,
Vinitha Balasubramanian