t-comm
Version:
专业、稳定、纯粹的工具库
62 lines (61 loc) • 1.62 kB
TypeScript
export declare function getJsonFromSheet(dataPath: string): any;
/**
* excel 转 json
* @param {object} params 参数
* @returns jsonData
* @example
*
* const options = {
* header: ['id', 'name', 'age'], // 可选:自定义表头
* range: 1, // 可选:跳过第一行(标题行)
* defval: null, // 可选:空单元格的默认值
* raw: false, // 可选:是否保留原始数据格式
* };
*
* excelToJson({
* filePath: CONFIG.xlsxPath,
* sheetIndex: 1,
* options,
* });
*
* // [
* // { id: 1, name: '2', age: '3' },
* // { id: 1, name: '2', age: '3' }
* // ];
*
*/
export declare function excelToJson({ filePath, sheetIndex, options, }: {
filePath: string;
sheetIndex?: number;
options?: Record<string, any>;
}): any;
/**
* json 转 excel
* @param {object} params 参数
* @example { workbook, worksheet }
*
* const jsonData = [
* { id: 1, name: '2', age: '3' },
* { id: 1, name: '2', age: '3' },
* ];
*
* jsonToExcel({
* jsonData,
* outputPath: CONFIG.outputFilePath,
* options: {
* header: ['id', 'name', 'age'], // 可选:自定义表头顺序
* skipHeader: false, // 可选:是否跳过表头行
* },
* sheetName: 'addedData',
* });
*/
export declare function jsonToExcel({ jsonData, outputPath, options, sheetName, overwrite, }: {
jsonData: Array<Record<string, string>>;
outputPath: string;
options?: Record<string, any>;
sheetName?: string;
overwrite?: boolean;
}): {
workbook: any;
worksheet: any;
};