UNPKG

@progress/kendo-react-excel-export

Version:
139 lines (138 loc) 6.08 kB
import * as React from 'react'; import * as PropTypes from 'prop-types'; import { WorkbookOptions } from '@progress/kendo-ooxml'; import { CellOptions } from './ooxml/CellOptionsInterface'; import { ExcelExportData } from './ExcelExportData'; import { ExcelExportColumnProps } from './ExcelExportColumn'; /** * Represents the props of the KendoReact ExcelExport component. */ export interface ExcelExportProps { /** * @hidden */ children?: any; /** * You can pass the columns through the props of the component. If both the columns prop and the child column components are presented, the columns from props will be used. */ columns?: ExcelExportColumnProps[]; /** * The creator of the workbook. */ creator?: string; /** * The exported data. If grouped, the data must be structured as described by the [`GroupResult`]({% slug api_kendo-data-query_groupresult %}) option of the Kendo UI Data Query component. */ data?: any[]; /** * The date on which the workbook is created. The default value is `new Date()`. */ date?: Date; /** * Enables or disables the column filtering in the Excel file. */ filterable?: boolean; /** * Specifies the name of the file that is exported to Excel. Defaults to `Export.xlsx`. */ fileName?: string; /** * If set to `true`, the content is forwarded to `proxyURL` even if the browser supports the saving of files locally. */ forceProxy?: boolean; /** * The exported data groups. The groups must be compatible with the [`GroupDescriptor`]({% slug api_kendo-data-query_groupdescriptor %}) option of the Kendo UI Data Query component. */ group?: any[]; /** * The options of the cells that are inserted before the header cells to align the headers and the column values (when the data is grouped). */ headerPaddingCellOptions?: CellOptions; /** * The options of the cells that are inserted before the data, group, and footer cells to indicate the group hierarchy (when the data is grouped). */ paddingCellOptions?: CellOptions; /** * The URL of the server-side proxy which will stream the file to the end user. When the browser is not capable of saving files locally&mdash;for example, Internet Explorer 9 and earlier, and Safari&mdash;a proxy is used. The implementation of the server-side proxy has to be done by you. * * The proxy receives a `POST` request with the following parameters in the request body: * - `contentType`&mdash;The MIME type of the file. * - `base64`&mdash;The base-64 encoded file content. * - `fileName`&mdash;The file name, as requested by the caller. The proxy is expected to return the decoded file with the **Content-Disposition** header set to `attachment; filename="<fileName.xslx>"`. */ proxyURL?: string; /** * If set to `rtl`, the Excel file will be rendered in the right-to-left mode. */ dir?: string; /** * If set to true the data will be exported as a tree based on the `level` property of each data record. */ hierarchy?: boolean; /** * Enables or disables collapsible (grouped) rows in the exported file. */ collapsible?: boolean; } export default class ExcelExport extends React.Component<ExcelExportProps> { /** * @hidden */ static propTypes: { children: PropTypes.Requireable<any>; columns: PropTypes.Requireable<any[]>; creator: PropTypes.Requireable<string>; data: PropTypes.Requireable<any>; date: PropTypes.Requireable<any>; filterable: PropTypes.Requireable<boolean>; fileName: PropTypes.Requireable<string>; forceProxy: PropTypes.Requireable<boolean>; group: PropTypes.Requireable<any>; headerPaddingCellOptions: PropTypes.Requireable<any>; paddingCellOptions: PropTypes.Requireable<any>; proxyURL: PropTypes.Requireable<string>; dir: PropTypes.Requireable<string>; hierarchy: PropTypes.Requireable<boolean>; collapsible: PropTypes.Requireable<boolean>; }; /** * @hidden */ static defaultProps: { fileName: string; forceProxy: boolean; collapsible: boolean; }; constructor(props: ExcelExportProps); /** * 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_workbookoptions %}). * @param columns - An optional parameter. If present, it will be used instead of the columns prop or the child column components. */ save(exportData?: any[] | ExcelExportData | WorkbookOptions, columns?: ExcelExportColumnProps[] | React.ReactElement<ExcelExportColumnProps>[]): void; /** * Returns a promise which will be resolved with the file data URI. * * @param exportData - The optional data or the [`WorkbookOptions`]({% slug api_excel-export_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(exportData?: any[] | ExcelExportData | WorkbookOptions, columns?: any[]): Promise<string>; /** * Based on the specified columns and data, returns [`WorkbookOptions`]({% slug api_excel-export_workbookoptions %}). * * @param exportData - The optional data that will be exported. * @param externalColumns - The optional columns that will be used. * @returns {WorkbookOptions} - The workbook options. */ workbookOptions(exportData?: any[] | ExcelExportData, externalColumns?: ExcelExportColumnProps[] | React.ReactElement<ExcelExportColumnProps>[]): WorkbookOptions; /** * @hidden */ render(): any; protected saveFile: (dataURL: string) => void; private extractColumns; private extractChild; private getExportData; }