We have updated Flexmonster Software License Agreement, effective as of September 30, 2025 (list of changes)

How to set fields separately from the screen when exporting Excel files

Answered
jhshin asked on September 22, 2025

Regardless of the data content on the grid, I would like to export to excel file with specific field. Please guide me if there is a way.

3 answers

Public
Nadia Khodakivska Nadia Khodakivska Flexmonster September 23, 2025

Hello,

Thank you for reaching out to us.

We recommend using one of the following approaches for exporting Flexmonster to Excel with the additional field:

  1. It is possible to add a specific column while exporting the report using the reportcomplete and exportcomplete events. The idea is to add the necessary column to the slice object and set a new slice via runQuery API call before export. After the export is completed, you can remove the added column from the slice. Please check the following example for reference: https://jsfiddle.net/flexmonster/btjhyn08/.
  2. Alternatively, you can have a remote Flexmonster instance that would generate Excel and other export files based on some saved reports. Next, these files can be, for example, saved to your server. Please check out our documentation dedicated to export to the server without using a browser. The described approach implies using Puppeteer — a JavaScript library for working with headless browsers. We prepared a sample GitHub project with Flexmonster and Puppeteer.

Please let us know if it works for you. Looking forward to hearing from you.

Kind regards,
Nadia

Public
jhshin September 24, 2025

In method 1, Is it possible to make two export buttons, one to export what is seen inside the grid, and the other to export a specific field (which may or may not be on the grid in some cases)?

 

Public
Nadia Khodakivska Nadia Khodakivska Flexmonster September 24, 2025

Hello,

Thank you for the response.

It is possible to create two separate functions:

1) To export what is seen inside the grid, you can use the exportTo("excel") API call without additional logic:

function excelCurrentGrid() {
pivot.exportTo("excel");
}

2) To export a specific field:

function excelOneField() {
let oldSlice = pivot.getReport().slice
// slice with only a specific field
let newSlice = {
columns: [{ uniqueName: "Country" }],
}
// return a previous grid state
pivot.on("reportcomplete", function () {
pivot.off("reportcomplete")
pivot.exportTo("excel")
pivot.on("exportcomplete", function () {
pivot.off("exportcomplete")
pivot.runQuery(oldSlice)
})
})

pivot.runQuery(newSlice)
}

Please let us know if it works for you. Looking forward to hearing your feedback.

Kind regards,
Nadia

Please login or Register to Submit Answer