UNPKG

@mescius/dspdfviewer

Version:
107 lines (106 loc) 5.25 kB
import { TableDefClientModel, TableDataExportFormat } from "../SupportApi/types"; /** * A utility class to handle the export of extracted table data to different file formats. * Supported formats include CSV, JSON, XLSX (Excel), and XML. */ export declare class TableDataExporter { private static xlsxLoaded; /** * Exports the given table data to the specified format and triggers a download of the generated file. * * @param data - The table data to be exported. It should follow the `TableDefClientModel` format. * @param format - The export format, one of "csv", "json", "xlsx", or "xml". * @param fileName - The name of the file to be downloaded (default is "exported_data"). * @throws {Error} If the provided format is unsupported. */ static exportAndDownload(data: TableDefClientModel[], format: TableDataExportFormat, fileName?: string): Promise<void>; static exportAndCopyToClipboard(data: TableDefClientModel[], format: TableDataExportFormat, fileName?: string): Promise<void>; /** * Exports table data in the specified format (CSV, TSV, JSON, XLSX, XML, or HTML). * Supports downloading the file or copying the result to clipboard. * * @param {TableDefClientModel[]} data - The table data to export. * @param {TableDataExportFormat} format - The export format ('csv', 'tsv', 'json', 'xlsx', 'xml', 'html'). * @param {string} [fileName="exported_data"] - The base filename (without extension). * @param {Object} [args] - Export behavior options. * @param {boolean} [args.copyToClipboard] - If true, copies the result to clipboard instead of downloading. * @param {boolean} [args.download=true] - If true (default), triggers file download where applicable. * @returns {Promise<void>} * @throws {Error} If the specified format is unsupported. */ static export(data: TableDefClientModel[], format: TableDataExportFormat, fileName?: string, args?: { copyToClipboard?: boolean; download?: boolean; }): Promise<void>; /** * Exports the table data to a TSV file and triggers the download. * This method ensures that data is properly formatted and technical attributes are excluded. * * @param data - The table data to be exported, following the `TableDefClientModel` format. * @param fileName - The name of the resulting TSV file. */ private static exportToTSV; /** * Exports the table data to a CSV file and triggers the download. * This method ensures that data is properly formatted and technical attributes are excluded. * * @param data - The table data to be exported, following the `TableDefClientModel` format. * @param fileName - The name of the resulting CSV file. */ private static exportToCSV; /** * Exports the table data to a JSON file and triggers the download. * * @param {TableDefClientModel[]} data - The table data to be exported. * @param {string} fileName - The name of the resulting JSON file. * @returns {string} The exported JSON string containing filtered cell data. */ private static exportToJSON; /** * Exports the table data to an HTML file and triggers the download. * * @param data - The table data to be exported, following the `TableDefClientModel` format. * @param fileName - The name of the resulting HTML file. */ private static exportToHTML; /** * Exports the table data to an XLSX (Excel) file and triggers the download. * Loads the XLSX library dynamically from a CDN if not already loaded. * * @param data - The table data to be exported, following the `TableDefClientModel` format. * @param fileName - The name of the resulting XLSX file. */ private static exportToXLSX; /** * Loads the XLSX library from a CDN (cdnjs) asynchronously. * This is used for exporting data to XLSX format. * * @returns A promise that resolves when the XLSX library is successfully loaded. * @throws {Error} If the library fails to load. */ private static loadXlsxFromCDN; /** * Exports the table data to an XML file and triggers the download. * * @param data - The table data to be exported, following the `TableDefClientModel` format. * @param fileName - The name of the resulting XML file. */ private static exportToXML; /** * Triggers the download of the given content as a file with the specified MIME type. * * @param content - The content of the file to be downloaded. * @param fileName - The name of the downloaded file. * @param mimeType - The MIME type of the file. * @param useUtf8Bom - If true, adds UTF-8 BOM to the content (helps with Excel compatibility). */ private static downloadFile; } /** * Normalizes text content based on the specified format. * * @param {string} text - The text to be normalized. * @param {string} format - The format type ('csv', 'tsv', 'html', 'xml', 'xls', 'json'). * @returns {string} The normalized text. */ export declare function normalizeCellText(text: string, format: TableDataExportFormat): string;