Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/dash-table/components/Export/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import XLSX from 'xlsx';
import React from 'react';
import { IDerivedData, Columns, ExportHeaders, ExportFormat, ExportColumns } from 'dash-table/components/Table/props';
import { IDerivedData, Columns, Data, Datum, ExportHeaders, ExportFormat, ExportColumns } from 'dash-table/components/Table/props';
import { createWorkbook, createHeadings, createWorksheet } from './utils';
import getHeaderRows from 'dash-table/derived/header/headerRows';

Expand All @@ -14,6 +14,21 @@ interface IExportButtonProps {
merge_duplicate_headers: boolean;
}

export function filterData(data: Data, columnID: string[]) {

let filteredData: Data = [];

data.forEach(data_row => {
let filtered_row: Datum = {};
columnID.forEach(column => {
filtered_row[column] = data_row[column];
});
filteredData.push(filtered_row);
});

return filteredData;
}

export default React.memo((props: IExportButtonProps) => {

const { columns, export_columns, export_format, virtual_data, export_headers, visibleColumns, merge_duplicate_headers } = props;
Expand All @@ -27,12 +42,12 @@ export default React.memo((props: IExportButtonProps) => {

const maxLength = getHeaderRows(columns);
const heading = (export_headers !== ExportHeaders.None) ? createHeadings(columnHeaders, maxLength) : [];
const ws = createWorksheet(heading, virtual_data.data, columnID, export_headers, merge_duplicate_headers);
const ws = createWorksheet(heading, filterData(virtual_data.data, columnID), columnID, export_headers, merge_duplicate_headers);
const wb = createWorkbook(ws);
if (export_format === ExportFormat.Xlsx) {
XLSX.writeFile(wb, 'Data.xlsx', {bookType: 'xlsx', type: 'buffer'});
XLSX.writeFile(wb, 'Data.xlsx', { bookType: 'xlsx', type: 'buffer' });

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These diffs come from the linter -- I can remove them if necessary.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this PR is redundant with what's been done here #592. See https://github.com/plotly/dash-table/blame/dev/src/dash-table/components/Export/utils.tsx#L59 for column filtering.

} else if (export_format === ExportFormat.Csv) {
XLSX.writeFile(wb, 'Data.csv', {bookType: 'csv', type: 'buffer'});
XLSX.writeFile(wb, 'Data.csv', { bookType: 'csv', type: 'buffer' });
}
};

Expand Down