@visactor/vtable-export 1.5.4-beta.0 → 1.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/es/csv/index.d.ts CHANGED
@@ -3,6 +3,7 @@ import type { CellInfo } from '../excel';
3
3
  type IVTable = VTable.ListTable | VTable.PivotTable | VTable.PivotChart;
4
4
  export type ExportVTableToCsvOptions = {
5
5
  formatExportOutput?: (cellInfo: CellInfo) => string | undefined;
6
+ escape?: boolean;
6
7
  };
7
8
  export declare function exportVTableToCsv(tableInstance: IVTable, option?: ExportVTableToCsvOptions): string;
8
9
  export {};
package/es/csv/index.js CHANGED
@@ -20,8 +20,8 @@ export function exportVTableToCsv(tableInstance, option) {
20
20
  function getCopyCellValue(col, row, tableInstance, option) {
21
21
  if (null == option ? void 0 : option.formatExportOutput) {
22
22
  const cellInfo = {
23
- cellType: "",
24
- cellValue: "",
23
+ cellType: tableInstance.getCellType(col, row),
24
+ cellValue: tableInstance.getCellValue(col, row),
25
25
  table: tableInstance,
26
26
  col: col,
27
27
  row: row
@@ -30,7 +30,14 @@ function getCopyCellValue(col, row, tableInstance, option) {
30
30
  }
31
31
  const cellRange = tableInstance.getCellRange(col, row), copyStartCol = cellRange.start.col, copyStartRow = cellRange.start.row;
32
32
  if (copyStartCol !== col || copyStartRow !== row) return "";
33
- const value = tableInstance.getCellValue(col, row);
34
- return "string" == typeof value ? '"' + value + '"' : value;
33
+ let value = tableInstance.getCellValue(col, row);
34
+ return (null == option ? void 0 : option.escape) ? value = escapeForCSV(value) : "string" == typeof value && (value = '"' + value + '"'),
35
+ value;
36
+ }
37
+
38
+ function escapeForCSV(str) {
39
+ if ("string" != typeof str) return str;
40
+ let escapedStr = str.replace(/"/g, '""');
41
+ return /[,"\r\n]/.test(escapedStr) && (escapedStr = `"${escapedStr}"`), escapedStr;
35
42
  }
36
43
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["csv/index.ts"],"names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E,GAAG,EAAE,CAAC;QACjF,MAAM,cAAc,GAAG,MAAM,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC;QAC3D,IAAI,cAAc,KAAK,SAAS,EAAE;YAChC,IAAI,OAAO,cAAc,KAAK,QAAQ,EAAE;gBACtC,OAAO,GAAG,GAAG,cAAc,GAAG,GAAG,CAAC;aACnC;YACD,OAAO,cAAc,CAAC;SACvB;KACF;IACD,MAAM,SAAS,GAAc,aAAa,CAAC,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAClE,MAAM,YAAY,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC;IACzC,MAAM,YAAY,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC;IAEzC,IAAI,YAAY,KAAK,GAAG,IAAI,YAAY,KAAK,GAAG,EAAE;QAChD,OAAO,EAAE,CAAC;KACX;IAED,MAAM,KAAK,GAAG,aAAa,CAAC,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAEnD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC7B,OAAO,GAAG,GAAG,KAAK,GAAG,GAAG,CAAC;KAC1B;IACD,OAAO,KAAK,CAAC;AACf,CAAC","file":"index.js","sourcesContent":["import type * as VTable from '@visactor/vtable';\nimport type { CellInfo } from '../excel';\n\ntype IVTable = VTable.ListTable | VTable.PivotTable | VTable.PivotChart;\ntype CellRange = VTable.TYPES.CellRange;\n\nconst newLine = '\\r\\n';\nconst separator = ',';\n\nexport type ExportVTableToCsvOptions = {\n formatExportOutput?: (cellInfo: CellInfo) => string | undefined;\n};\n\nexport function exportVTableToCsv(tableInstance: IVTable, option?: ExportVTableToCsvOptions): string {\n const minRow = 0;\n const maxRow = tableInstance.rowCount - 1;\n const minCol = 0;\n const maxCol = tableInstance.colCount - 1;\n\n let copyValue = '';\n for (let row = minRow; row <= maxRow; row++) {\n for (let col = minCol; col <= maxCol; col++) {\n const copyCellValue = getCopyCellValue(col, row, tableInstance, option);\n if (typeof Promise !== 'undefined' && copyCellValue instanceof Promise) {\n // not support async\n } else {\n const strCellValue = `${copyCellValue}`;\n if (/^\\[object .*\\]$/.exec(strCellValue)) {\n // ignore object\n } else {\n copyValue += strCellValue;\n }\n }\n copyValue += separator;\n }\n copyValue += newLine;\n }\n return copyValue;\n}\n\nfunction getCopyCellValue(\n col: number,\n row: number,\n tableInstance: IVTable,\n option?: ExportVTableToCsvOptions\n): string | Promise<string> | void {\n if (option?.formatExportOutput) {\n const cellInfo = { cellType: '', cellValue: '', table: tableInstance, col, row };\n const formattedValue = option.formatExportOutput(cellInfo);\n if (formattedValue !== undefined) {\n if (typeof formattedValue === 'string') {\n return '\"' + formattedValue + '\"';\n }\n return formattedValue;\n }\n }\n const cellRange: CellRange = tableInstance.getCellRange(col, row);\n const copyStartCol = cellRange.start.col;\n const copyStartRow = cellRange.start.row;\n\n if (copyStartCol !== col || copyStartRow !== row) {\n return '';\n }\n\n const value = tableInstance.getCellValue(col, row);\n\n if (typeof value === 'string') {\n return '\"' + value + '\"';\n }\n return value;\n}\n"]}
1
+ {"version":3,"sources":["csv/index.ts"],"names":[],"mappings":"AAMA,MAAM,OAAO,GAAG,MAAM,CAAC;AACvB,MAAM,SAAS,GAAG,GAAG,CAAC;AAOtB,MAAM,UAAU,iBAAiB,CAAC,aAAsB,EAAE,MAAiC;IACzF,MAAM,MAAM,GAAG,CAAC,CAAC;IACjB,MAAM,MAAM,GAAG,aAAa,CAAC,QAAQ,GAAG,CAAC,CAAC;IAC1C,MAAM,MAAM,GAAG,CAAC,CAAC;IACjB,MAAM,MAAM,GAAG,aAAa,CAAC,QAAQ,GAAG,CAAC,CAAC;IAE1C,IAAI,SAAS,GAAG,EAAE,CAAC;IACnB,KAAK,IAAI,GAAG,GAAG,MAAM,EAAE,GAAG,IAAI,MAAM,EAAE,GAAG,EAAE,EAAE;QAC3C,KAAK,IAAI,GAAG,GAAG,MAAM,EAAE,GAAG,IAAI,MAAM,EAAE,GAAG,E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;IACzC,MAAM,YAAY,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC;IAEzC,IAAI,YAAY,KAAK,GAAG,IAAI,YAAY,KAAK,GAAG,EAAE;QAChD,OAAO,EAAE,CAAC;KACX;IAED,IAAI,KAAK,GAAG,aAAa,CAAC,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACjD,IAAI,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,EAAE;QAClB,KAAK,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;KAC7B;SAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QACpC,KAAK,GAAG,GAAG,GAAG,KAAK,GAAG,GAAG,CAAC;KAC3B;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAOD,SAAS,YAAY,CAAC,GAAQ;IAC5B,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;QAC3B,OAAO,GAAG,CAAC;KACZ;IAGD,IAAI,UAAU,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAGzC,IAAI,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE;QAC/B,UAAU,GAAG,IAAI,UAAU,GAAG,CAAC;KAChC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC","file":"index.js","sourcesContent":["import type * as VTable from '@visactor/vtable';\nimport type { CellInfo } from '../excel';\n\ntype IVTable = VTable.ListTable | VTable.PivotTable | VTable.PivotChart;\ntype CellRange = VTable.TYPES.CellRange;\n\nconst newLine = '\\r\\n';\nconst separator = ',';\n\nexport type ExportVTableToCsvOptions = {\n formatExportOutput?: (cellInfo: CellInfo) => string | undefined;\n escape?: boolean;\n};\n\nexport function exportVTableToCsv(tableInstance: IVTable, option?: ExportVTableToCsvOptions): string {\n const minRow = 0;\n const maxRow = tableInstance.rowCount - 1;\n const minCol = 0;\n const maxCol = tableInstance.colCount - 1;\n\n let copyValue = '';\n for (let row = minRow; row <= maxRow; row++) {\n for (let col = minCol; col <= maxCol; col++) {\n const copyCellValue = getCopyCellValue(col, row, tableInstance, option);\n if (typeof Promise !== 'undefined' && copyCellValue instanceof Promise) {\n // not support async\n } else {\n const strCellValue = `${copyCellValue}`;\n if (/^\\[object .*\\]$/.exec(strCellValue)) {\n // ignore object\n } else {\n copyValue += strCellValue;\n }\n }\n copyValue += separator;\n }\n copyValue += newLine;\n }\n return copyValue;\n}\n\nfunction getCopyCellValue(\n col: number,\n row: number,\n tableInstance: IVTable,\n option?: ExportVTableToCsvOptions\n): string | Promise<string> | void {\n if (option?.formatExportOutput) {\n const cellType = tableInstance.getCellType(col, row);\n const cellValue = tableInstance.getCellValue(col, row);\n const cellInfo = { cellType, cellValue, table: tableInstance, col, row };\n const formattedValue = option.formatExportOutput(cellInfo);\n if (formattedValue !== undefined) {\n if (typeof formattedValue === 'string') {\n return '\"' + formattedValue + '\"';\n }\n return formattedValue;\n }\n }\n const cellRange: CellRange = tableInstance.getCellRange(col, row);\n const copyStartCol = cellRange.start.col;\n const copyStartRow = cellRange.start.row;\n\n if (copyStartCol !== col || copyStartRow !== row) {\n return '';\n }\n\n let value = tableInstance.getCellValue(col, row);\n if (option?.escape) {\n value = escapeForCSV(value);\n } else if (typeof value === 'string') {\n value = '\"' + value + '\"';\n }\n return value;\n}\n\n/**\n * 将字符串中的特殊符号进行转义,以避免干扰CSV解析\n * @param {string} str - 需要处理的字符串\n * @return {string} - 已处理的字符串\n */\nfunction escapeForCSV(str: any) {\n if (typeof str !== 'string') {\n return str;\n }\n\n // 替换双引号为两个双引号\n let escapedStr = str.replace(/\"/g, '\"\"');\n\n // 如果字符串中包含逗号、换行符或双引号,则需要用双引号包裹\n if (/[,\"\\r\\n]/.test(escapedStr)) {\n escapedStr = `\"${escapedStr}\"`;\n }\n\n return escapedStr;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visactor/vtable-export",
3
- "version": "1.5.4-beta.0",
3
+ "version": "1.5.4",
4
4
  "description": "The export util of VTable",
5
5
  "author": {
6
6
  "name": "VisActor",
@@ -30,14 +30,14 @@
30
30
  "access": "public"
31
31
  },
32
32
  "dependencies": {
33
- "@visactor/vtable": "1.5.4-beta.0",
34
33
  "@visactor/vutils": "~0.18.9",
35
34
  "file-saver": "2.0.5",
36
35
  "@types/file-saver": "2.0.7",
37
- "exceljs": "4.4.0"
36
+ "exceljs": "4.4.0",
37
+ "@visactor/vtable": "1.5.4"
38
38
  },
39
39
  "devDependencies": {
40
- "@visactor/vchart": "1.11.4",
40
+ "@visactor/vchart": "1.11.10",
41
41
  "@rushstack/eslint-patch": "~1.1.4",
42
42
  "react": "^18.0.0",
43
43
  "react-dom": "^18.0.0",
@@ -78,9 +78,9 @@
78
78
  "axios": "^1.4.0",
79
79
  "@types/react-is": "^17.0.3",
80
80
  "rollup-plugin-node-resolve": "5.2.0",
81
- "@internal/bundler": "0.0.1",
82
81
  "@internal/ts-config": "0.0.1",
83
- "@internal/eslint-config": "0.0.1"
82
+ "@internal/eslint-config": "0.0.1",
83
+ "@internal/bundler": "0.0.1"
84
84
  },
85
85
  "scripts": {
86
86
  "compile": "tsc --noEmit",