xlsx.d.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import XLSX from 'xlsx';
  2. import { ExcelImportDialog } from "./ExcelImportDialog";
  3. import { Scope } from "./Scope";
  4. declare const XLSX_EXPORT: any;
  5. export { XLSX };
  6. export { XLSX_EXPORT };
  7. export declare function readExcel(file: File): Promise<any>;
  8. export declare interface ErrorMsgDataItem {
  9. /** 错误id 由allData 的__importID__字段值 + "_" + field的值 表示哪一行的哪一列出错,行校验错误时候直接为allData 的__importID__ + "" */
  10. errorId: string;
  11. /** 对应数据行 allData 的__importID__字段值 */
  12. importID: number;
  13. /** 字段 */
  14. dataIndex: string;
  15. /** 字段值 */
  16. header: string;
  17. /** 字段值 */
  18. value: string;
  19. /** 错误信息 */
  20. errormessage: string;
  21. }
  22. export declare interface ImportResult {
  23. /** 所有导入的数据,如果有字典会格式化到字典,格式化错误的保持原始值 */
  24. allData: any[];
  25. /** 导入正确的数据 */
  26. okData: any[];
  27. /** 导入错误的数据 */
  28. errorData: any[];
  29. /** 导入错误数据的错误明细 */
  30. errorMsgData: ErrorMsgDataItem[];
  31. }
  32. /** 定义参数列 */
  33. export declare interface Column {
  34. /** 字段 */
  35. dataIndex: string;
  36. /** 字段名 */
  37. header: string;
  38. /** 校验方法,校验通过返回true, 否则返回错误信息 会记录到错误列表里面 errorMsgData */
  39. validate?: ((v: ValidateObject) => true | string) | string;
  40. /** 格式化,表格显示 兼容默认弹出框表格的formatter */
  41. fix?: ((v: any) => any) | string;
  42. /** 导入格式化 返回null或者undefined 表示格式化错误,会记录到错误列表里面 errorMsgData */
  43. importFormatter?: ((v: ValidateObject) => null | undefined | string | number) | string;
  44. /** 字典, 参与数据校验和表格显示格式化, 校验不通过的,会记录到错误列表里面 errorMsgData 同时兼容默认弹出框表格的字典 */
  45. data?: any | {
  46. id: string | number;
  47. text: string;
  48. };
  49. }
  50. /** 格式化及校验的参数 */
  51. export declare interface ValidateObject {
  52. column: Column;
  53. ov: any;
  54. nv: any;
  55. rowIndex: number;
  56. data: any;
  57. rowDatas: any[];
  58. }
  59. /** 行数据校验的参数 */
  60. export declare interface RowValidateObject {
  61. columns: Column[];
  62. data: any;
  63. rowIndex: number;
  64. rowDatas: any[];
  65. }
  66. /**
  67. * 定义切口,可以在外部修改数据
  68. */
  69. export declare type AfterClientValidate = ((importResult: ImportResult, resolve: (value?: (ImportResult | PromiseLike<ImportResult> | undefined)) => void) => ImportResult) | undefined;
  70. export declare function readExcelWithColumnsSet(topScope: Scope, file: File, columnsSet: any[], dataStartRow?: number, titleRowNumber?: number, rowValidate?: ((rv: RowValidateObject) => true | string) | undefined, otherValidate?: AfterClientValidate, fieldValidate?: ((columns: Column[], columnTitles: string[]) => boolean) | undefined): Promise<ImportResult>;
  71. export declare interface ImportExcelOption {
  72. columns: Column[];
  73. fieldValidate?: ((columns: Column[], columnTitles: string[]) => boolean) | string | undefined;
  74. rowValidate?: ((rv: RowValidateObject) => true | string) | string | undefined;
  75. afterClientValidate?: AfterClientValidate | string;
  76. dataStartRow?: number;
  77. titleRowNumber?: number;
  78. onImportAfter?: ((result: ImportResult) => {}) | string | undefined;
  79. hidAllDataGrid?: boolean;
  80. hidOKDataGrid?: boolean;
  81. hidErrorDataGrid?: boolean;
  82. hidErrorMsgGrid?: boolean;
  83. dataGridPageSize?: 0 | 10 | 20 | 50 | 100 | 200 | 500 | 1000;
  84. errorMsgGridPageSize?: 0 | 10 | 20 | 50 | 100 | 200 | 500 | 1000;
  85. templateName?: string;
  86. dowLoadUrl?: string;
  87. title?: string;
  88. height?: string;
  89. width?: string;
  90. defaultShowData?: "allData" | "okData" | "errorData";
  91. errMsgGridColWidths?: number[];
  92. toolBar?: any[];
  93. onClose?: string | (() => void);
  94. tQButtonText?: string | null | undefined;
  95. }
  96. /**
  97. * 打开excel导入的方法
  98. * @param option 参数配置
  99. * @param sender
  100. */
  101. export declare function importExcel(option: ImportExcelOption, sender: any): ExcelImportDialog;