# Export pivot table

**URL:** <https://forums.knack.com/t/export-pivot-table/19043>\
**Category:** Get Answers\
**Created:** [March 21, 2025, 2:01pm UTC](https://forums.knack.com/t/export-pivot-table/19043 "2025-03-21T14:01:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joshua3](https://avatars.discourse-cdn.com/v4/letter/j/d6d6ee/32.png) [@Joshua3](https://forums.knack.com/u/Joshua3)\
**Post date:** [March 21, 2025, 2:01pm UTC](https://forums.knack.com/t/export-pivot-table/19043/1 "2025-03-21T14:01:11Z")

</div>

Is there a way to export a pivot table? I have a great report, I just need to export it and print it.

---

<div class="post-metadata">

**Author:** ![CarlHolmes](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/carlholmes/32/2814_2.png) [@CarlHolmes](https://forums.knack.com/u/CarlHolmes)\
**Post date:** [March 22, 2025, 6:53am UTC](https://forums.knack.com/t/export-pivot-table/19043/2 "2025-03-22T06:53:17Z")

</div>

Hi @Joshua3 - welcome to the forum 👋

Unfortunately there is no native way to export the values in a Pivot Table. I’m sure it could be achieved with custom code, if there is a developer out there who can help 🧑‍💻

---

<div class="post-metadata">

**Author:** ![BradStevens](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/bradstevens/32/140_2.png) [@BradStevens](https://forums.knack.com/u/BradStevens)\
**Post date:** [March 23, 2025, 4:21am UTC](https://forums.knack.com/t/export-pivot-table/19043/3 "2025-03-23T04:21:10Z")

</div>

@Joshua3 @CarlHolmes is right and we have used a Javacript plugin (table2excel) to download the table as an Excel file.

I can’t lay my hands on that code right now but see [How to Convert HTML to Excel using table2excel | Medium](https://medium.com/@techsolutionstuff/how-to-convert-html-to-excel-using-table2excel-50c2a6fd6caf)

Having said that does printing the webpage not work for you given the report is well formatted already? Can the report be shared with users another way?

---

<div class="post-metadata">

**Author:** ![Erik](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/erik/32/982_2.png) [@Erik](https://forums.knack.com/u/Erik)\
**Post date:** [March 29, 2025, 9:54pm UTC](https://forums.knack.com/t/export-pivot-table/19043/4 "2025-03-29T21:54:59Z")

</div>

I copy/paste them into emails and such.

I always start the copy function outside the table and it paste as a Table in email or word.  
If I start the copy completely inside the table, it just pastes the text. 🤷‍♂️

Works pretty well to copy paste to excel too. I start the copy fully inside the table for that.  
Spruce it up a little by Formatting the Data as a Table (CTRL + T) and you have a pretty nice report.

---

<div class="post-metadata">

**Author:** ![Dean2](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@Dean2](https://forums.knack.com/u/Dean2)\
**Post date:** [April 1, 2025, 8:20pm UTC](https://forums.knack.com/t/export-pivot-table/19043/5 "2025-04-01T20:20:33Z")

</div>

Hi

Here’s some code Claude quickly generated re-purposing an old Exporting function.

Just click the “Export Pivot Table” button and then double-click the downloaded CSV file and it will open in Excel.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/knack/original/2X/5/57e4b4ca9813e72516de91df90552bce4b32f200.png)

 ![image](https://us1.discourse-cdn.com/flex020/uploads/knack/original/2X/c/c201a54cb29d3d7c3dcc6db9181e1b3ccfdb3254.png)

 ![image](https://us1.discourse-cdn.com/flex020/uploads/knack/original/2X/7/7197ae827348d2a18e48db23883025bb64040b32.png)

Just change the view#.

// \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* Function to export pivot table in CSV format \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* //  
$(document).on(‘knack-view-render.view\_XXXX’, function(event, view) {  
// Create a container for the export button and notification  
var containerHtml = ‘

’ +  
‘Export Pivot Table’ +  
‘
CSV file has been downloaded successfully.
’ +  
‘
’;

// Add the container above the pivot table  
$(‘#’ + view.key).prepend(containerHtml);

// Event listener for “Export Pivot Table” button  
$(‘#export-pivot-button’).click(function() {  
exportPivotTable(view.key);  
});  
});

// Function to export the pivot table data to CSV  
function exportPivotTable(viewKey) {  
// Find the pivot table  
var pivotTable = $(‘#’ + viewKey + ’ .kn-pivot-table’);  
if (pivotTable.length === 0) {  
// If .kn-pivot-table selector doesn’t work, try other possible selectors  
pivotTable = $(‘#’ + viewKey + ’ table’);  
}

if (pivotTable.length === 0) {  
alert(“No pivot table found in this view. Please check the table structure.”);  
return;  
}

// Capture all data from the pivot table  
var csvContent = “”;  
var headers = ;

// Get the headers - first find the header row  
var headerRow = pivotTable.find(‘thead tr’).last(); // Get the last row in the thead which should contain all column headers

// Extract headers  
headerRow.find(‘th’).each(function() {  
headers.push($(this).text().trim());  
});

// Add headers to CSV  
csvContent += headers.join(“,”) + “\n”;

// Get the data rows  
var dataRows = pivotTable.find(‘tbody tr’);

dataRows.each(function() {  
var rowData = ;  
var rowCells = $(this).find(‘td, th’); // Include th for row headers

```
rowCells.each(function() {
  // Handle thousands separators and other formatting
  let cellText = $(this).text().trim();
  
  // If it's a number with commas, remove the commas
  if(!isNaN(cellText.replace(/,/g, ''))) {
    cellText = cellText.replace(/,/g, '');
  }
  
  // Escape commas and quotes for CSV format
  if(cellText.includes(',') || cellText.includes('"')) {
    cellText = '"' + cellText.replace(/"/g, '""') + '"';
  }
  
  rowData.push(cellText);
});

csvContent += rowData.join(",") + "\n";

```

});

// Check if we have data  
if (csvContent.trim() === headers.join(“,”)) {  
alert(“No data was found in the pivot table. Please check the structure.”);  
return;  
}

// Add a BOM (Byte Order Mark) for Excel to interpret the file correctly  
var BOM = “\uFEFF”;  
csvContent = BOM + csvContent;

// Create a blob for the CSV file  
var blob = new Blob([csvContent], { type: ‘text/csv;charset=utf-8’ });  
var url = URL.createObjectURL(blob);

// Create and click a link to download the file  
var a = document.createElement(‘a’);  
a.href = url;  
a.download = ‘pivot\_table\_export.csv’;  
document.body.appendChild(a);  
a.click();  
document.body.removeChild(a);  
}

// END \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* Function to export pivot table in CSV format \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* //

Regards  
Dean

---

<div class="post-metadata">

**Author:** ![Joshua3](https://avatars.discourse-cdn.com/v4/letter/j/d6d6ee/32.png) [@Joshua3](https://forums.knack.com/u/Joshua3)\
**Post date:** [April 4, 2025, 7:43pm UTC](https://forums.knack.com/t/export-pivot-table/19043/6 "2025-04-04T19:43:31Z")

</div>

That’s what I’ve been doing. I need something simple for my non-tech savvy boss so he can run the report when I’m on vacation next month.

---

<div class="post-metadata">

**Author:** ![Joshua3](https://avatars.discourse-cdn.com/v4/letter/j/d6d6ee/32.png) [@Joshua3](https://forums.knack.com/u/Joshua3)\
**Post date:** [April 4, 2025, 7:45pm UTC](https://forums.knack.com/t/export-pivot-table/19043/7 "2025-04-04T19:45:37Z")

</div>

This is perfect! Thanks for sharing it.
