Author Topic: pqGrid Excel Export – replace parameter  (Read 642 times)

luckduck

  • Pro OEM
  • Jr. Member
  • *
  • Posts: 60
    • View Profile
pqGrid Excel Export – replace parameter
« on: April 20, 2026, 12:55:50 pm »
I have an additional question regarding the exportData function in pqGrid.

The `replace` option does not seem to work as expected. I’m not sure if I am using the syntax incorrectly or if there is another issue.

Here is a sample of my code:

Code: [Select]
var blob = await grid.exportData({
    // url: "exportData.do",
    format: format,
    nopqdata: true, // applicable for JSON export
    render: false,
    sheetName: "Example",
    replace: [/<br\/>/g, '\r\n']
});

if (typeof blob === "string") {
    blob = new Blob([blob]);
}

saveAs(blob, excelNm + "." + format);

The goal is to replace <br/> tags with line breaks (\r\n) in the exported file, but it does not seem to be applied.

Could you please confirm whether:
1. The `replace` option syntax is correct?
2. There are any limitations or conditions where `replace` does not work?
3. There is an alternative way to handle line breaks during export?

Any help would be appreciated.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6552
    • View Profile
Re: pqGrid Excel Export – replace parameter
« Reply #1 on: April 20, 2026, 07:14:21 pm »
  • The replace option is specifically designed for xlsx exports only; it will not function for other file formats.
  • The replace process occurs at a late stage where HTML content has already been escaped. Because of this, the string
Code: [Select]
<br>
    no longer exists in its original form when the regex runs, causing the replacement to fail.
  • The recommended alternative is to use the eachCell callback. This allows you to intercept and modify the cell value directly during the data iteration phase before any escaping or final formatting takes place.
Code: [Select]
var blob = await grid.exportData({
  format: format,
  nopqdata: true,
  render: false,
  sheetName: "Example",
  eachCell: function(cell) {
     //examine cell.value
  }
});