@progress/kendo-react-excel-export
Version:
React Excel export helps you export and save data to Excel files and customize or filter the output. KendoReact Excel Export package
120 lines (119 loc) • 4.8 kB
JavaScript
/**
* @license
*-------------------------------------------------------------------------------------------
* Copyright © 2025 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the package root for more information
*-------------------------------------------------------------------------------------------
*/
import * as i from "react";
import r from "prop-types";
import { saveAs as d } from "@progress/kendo-file-saver";
import { isWorkbookOptions as c, toDataURL as m, workbookOptions as y } from "./ooxml/workbook.mjs";
import { validatePackage as g, getLicenseMessage as u, WatermarkOverlay as f } from "@progress/kendo-react-common";
import { packageMetadata as p } from "./package-metadata.mjs";
const a = class a extends i.Component {
constructor(o) {
super(o), this.showLicenseWatermark = !1, this.saveFile = (t) => {
d(t, this.props.fileName, {
forceProxy: this.props.forceProxy,
proxyURL: this.props.proxyURL
});
}, this.extractColumns = (t, s = 0) => Array.isArray(t) ? t.map((e) => this.extractChild(e, s)) : [t, this.extractChild(t, s)], this.extractChild = (t, s = 0) => i.isValidElement(t) ? {
...t.props,
width: t.props.width && parseInt(`${t.props.width}`, 10),
level: s,
children: t.props.children && this.extractColumns(t.props.children, s + 1)
} : {
...t,
level: s,
children: t.children && this.extractColumns(t.children, s + 1)
}, this.getExportData = (t) => {
let s;
return t ? Array.isArray(t) ? s = {
data: t
} : s = t : s = {
data: this.props.data,
group: this.props.group
}, s;
}, this.showLicenseWatermark = !g(p, { component: "ExcelExport" }), this.licenseMessage = u(p), this.save = this.save.bind(this), this.toDataURL = this.toDataURL.bind(this), this.workbookOptions = this.workbookOptions.bind(this);
}
/**
* Saves the data to Excel.
*
* @param exportData - An optional parameter. Can be the data that will be exported or the [`WorkbookOptions`]({% slug api_excel-export_kendoooxml %}#toc-workbookoptions).
* @param columns - An optional parameter. If present, it will be used instead of the columns prop or the child column components.
*/
save(o, t) {
this.toDataURL(o, t).then((...s) => {
this.props.onExportComplete && this.props.onExportComplete.call(void 0, { target: this }), this.saveFile(...s);
});
}
/**
* Returns a promise which will be resolved with the file data URI.
*
* @param exportData - The optional data or the [`WorkbookOptions`]({% slug api_excel-export_kendoooxml %}#toc-workbookoptions) that will be used to generate the data URI.
* @param externalColumns - The optional columns that will be used.
* @returns {Promise<string>} - The promise that will be resolved by the file data URI.
*/
toDataURL(o, t) {
const s = c(o) ? o : this.workbookOptions(o, t);
return m(s);
}
/**
* Based on the specified columns and data, returns [`WorkbookOptions`]({% slug api_excel-export_kendoooxml %}#toc-workbookoptions).
*
* @param exportData - The optional data that will be exported.
* @param externalColumns - The optional columns that will be used.
* @returns {WorkbookOptions} - The workbook options.
*/
// tslint:enable:max-line-length
workbookOptions(o, t) {
const s = this.getExportData(o), e = this.props.children, h = e && e.type && e.type.displayName === "KendoReactGrid" && e.props && i.Children.toArray(e.props.children), l = this.extractColumns(
h || t || this.props.columns || i.Children.toArray(e)
);
return y({
columns: l,
data: s.data,
group: s.group,
filterable: this.props.filterable,
creator: this.props.creator,
date: this.props.date,
dir: this.props.dir,
hierarchy: this.props.hierarchy,
paddingCellOptions: this.props.paddingCellOptions,
headerPaddingCellOptions: this.props.headerPaddingCellOptions,
collapsible: this.props.collapsible
});
}
/**
* @hidden
*/
render() {
return /* @__PURE__ */ i.createElement(i.Fragment, null, this.props.children || null, this.showLicenseWatermark && /* @__PURE__ */ i.createElement(f, { message: this.licenseMessage }));
}
};
a.propTypes = {
children: r.any,
columns: r.arrayOf(r.any),
creator: r.string,
data: r.any,
date: r.any,
filterable: r.bool,
fileName: r.string,
forceProxy: r.bool,
group: r.any,
headerPaddingCellOptions: r.any,
paddingCellOptions: r.any,
proxyURL: r.string,
dir: r.string,
hierarchy: r.bool,
collapsible: r.bool
}, a.defaultProps = {
fileName: "Export.xlsx",
forceProxy: !1,
collapsible: !1
};
let n = a;
export {
n as ExcelExport
};