import { appContext } from '../base/AppContext'; import { Ajax } from '../base/ajax'; export interface IXLSXColumn { name: string; type: 'string' | 'float' | 'int' | 'date' | 'boolean'; } export interface IXLSXSheet { title: string; columns: IXLSXColumn[]; rows: { [key: string]: string | number | Date | boolean | null }[]; } export interface IXLSXJSONFile { sheets: IXLSXSheet[]; } export class XlsxUtils { static xlsx2json(file: File): Promise { const data = new FormData(); data.set('file', file); return appContext.sendAPI('/xlsx/to_json/', data, 'POST'); } static xlsx2jsonArray(file: File): Promise { const data = new FormData(); data.set('file', file); return appContext.sendAPI('/xlsx/to_json_array/', data, 'POST'); } static json2xlsx(file: IXLSXJSONFile): Promise { return Ajax.send(appContext.api2absURL('/xlsx/from_json/'), file, 'POST', 'blob', 'application/json'); } static jsonArray2xlsx(file: any[][]): Promise { return Ajax.send(appContext.api2absURL('/xlsx/from_json_array/'), file, 'POST', 'blob', 'application/json'); } }