UNPKG

@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.72 kB
/** * @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 e from "react"; import s from "prop-types"; import { saveAs as h } from "@progress/kendo-file-saver"; import { isWorkbookOptions as d, toDataURL as c, workbookOptions as m } from "./ooxml/workbook.mjs"; import { validatePackage as y, WatermarkOverlay as u } from "@progress/kendo-react-common"; import { packageMetadata as f } from "./package-metadata.mjs"; const a = class a extends e.Component { constructor(o) { super(o), this.showLicenseWatermark = !1, this.saveFile = (t) => { h(t, this.props.fileName, { forceProxy: this.props.forceProxy, proxyURL: this.props.proxyURL }); }, this.extractColumns = (t, r = 0) => Array.isArray(t) ? t.map((i) => this.extractChild(i, r)) : [t, this.extractChild(t, r)], this.extractChild = (t, r = 0) => e.isValidElement(t) ? { ...t.props, width: t.props.width && parseInt(`${t.props.width}`, 10), level: r, children: t.props.children && this.extractColumns(t.props.children, r + 1) } : { ...t, level: r, children: t.children && this.extractColumns(t.children, r + 1) }, this.getExportData = (t) => { let r; return t ? Array.isArray(t) ? r = { data: t } : r = t : r = { data: this.props.data, group: this.props.group }, r; }, this.showLicenseWatermark = !y(f, { component: "ExcelExport" }), 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((...r) => { this.props.onExportComplete && this.props.onExportComplete.call(void 0, { target: this }), this.saveFile(...r); }); } /** * 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 r = d(o) ? o : this.workbookOptions(o, t); return c(r); } /** * 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 r = this.getExportData(o), i = this.props.children, n = i && i.type && i.type.displayName === "KendoReactGrid" && i.props && e.Children.toArray(i.props.children), l = this.extractColumns( n || t || this.props.columns || e.Children.toArray(i) ); return m({ columns: l, data: r.data, group: r.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__ */ e.createElement(e.Fragment, null, this.props.children || null, this.showLicenseWatermark && /* @__PURE__ */ e.createElement(u, null)); } }; a.propTypes = { children: s.any, columns: s.arrayOf(s.any), creator: s.string, data: s.any, date: s.any, filterable: s.bool, fileName: s.string, forceProxy: s.bool, group: s.any, headerPaddingCellOptions: s.any, paddingCellOptions: s.any, proxyURL: s.string, dir: s.string, hierarchy: s.bool, collapsible: s.bool }, a.defaultProps = { fileName: "Export.xlsx", forceProxy: !1, collapsible: !1 }; let p = a; export { p as ExcelExport };