rapid-spreadjs 1.0.5 → 1.0.6

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.
@@ -0,0 +1,188 @@
1
+ // 导出Excel文件所需的第三方包
2
+ import { saveAs } from "file-saver";
3
+
4
+ /**
5
+ * SpreadJS工作簿工具函数
6
+ */
7
+ export const WorkbookUtils = {
8
+ /**
9
+ * 打印所有工作表
10
+ * @param GC GC对象
11
+ * @param spread 工作簿实例
12
+ */
13
+ print: (GC: any, spread: any) => {
14
+ // 得到Sheet个数
15
+ const sheetCount = spread.getSheetCount();
16
+
17
+ for (let i = 0; i < sheetCount; i++) {
18
+ const sheet = spread.getSheet(i);
19
+
20
+ // 获取每个工作表的打印信息
21
+ let printInfo = sheet.printInfo();
22
+
23
+ // 隐藏行和列的头部信息
24
+ printInfo.showRowHeader(
25
+ GC.Spread.Sheets.Print.PrintVisibilityType.hide
26
+ );
27
+ printInfo.showColumnHeader(
28
+ GC.Spread.Sheets.Print.PrintVisibilityType.hide
29
+ );
30
+
31
+ // // 显示和隐藏打印区域的辅助线
32
+ // spread.getSheet(0).isPrintLineVisible(true);
33
+ // spread.getSheet(0).isPrintLineVisible(!true);
34
+
35
+ // 设置打印区域,这里是固定的,在业务应用中需要根据实际情况修改打印区域
36
+ printInfo.rowStart(0);
37
+ printInfo.rowEnd(sheet.getRowCount()); //printInfo.rowEnd(41);
38
+ printInfo.columnStart(0);
39
+ printInfo.columnEnd(76);
40
+
41
+ // 设置SpreadJS自身的边距为合适的距离
42
+ printInfo.margin({
43
+ /**
44
+ * 设置默认边距
45
+ * 单位是:以百分之一英寸为单位
46
+ * 也就是,如果我们需要设置左边距为25mm,需要将25mm先转换为英寸,然后再用这个英寸*100就是要设置的边距
47
+ * 即:(25mm转换为英寸的结果)*100
48
+ *
49
+ * 参考文档:
50
+ * https://demo.grapecity.com.cn/spreadjs/help/api/classes/GC.Spread.Sheets.Print.PrintInfo#margin
51
+ * https://www.67tool.com/converter/length
52
+ */
53
+ // 纵表
54
+ top: 0.5905511999999999 * 100,
55
+ bottom: 0.5905511999999999 * 100,
56
+ left: 0.9842520000000001 * 100,
57
+ right: 0.5905511999999999 * 100,
58
+
59
+ // // 横表
60
+ // top: 0.9842520000000001 * 100,
61
+ // bottom: 0.5905511999999999 * 100,
62
+ // left: 0.5905511999999999 * 100,
63
+ // right: 0.5905511999999999 * 100,
64
+
65
+ // top: 0,
66
+ // bottom: 0,
67
+ // left: 0,
68
+ // right: 0,
69
+ header: 0,
70
+ footer: 0,
71
+ });
72
+
73
+ // 设置打印的纸张
74
+ printInfo.paperSize(
75
+ new GC.Spread.Sheets.Print.PaperSize(
76
+ GC.Spread.Sheets.Print.PaperKind.a4
77
+ )
78
+ );
79
+
80
+ sheet.printInfo(printInfo);
81
+ }
82
+
83
+ // 调用打印方法
84
+ spread.print();
85
+ },
86
+
87
+ /**
88
+ * 导出为Excel文件
89
+ * 如支持导出自定义公式的值等功能
90
+ * @param GC Spread的GC对象
91
+ * @param spread 原始Spread对象
92
+ * @param fileName 导出的文件名称,不传则为第一个工作表的名称
93
+ */
94
+ exportToExcel: (GC: any, spread: any, fileName: string = "") => {
95
+ // 导出模板为JSON对象,此处设置了参数includeBindingSource,改参数代表包含数据绑定的值
96
+ const json = spread.toJSON({ includeBindingSource: true });
97
+
98
+ // 需要移除的自定义公式名称集合(该变量的作用是,在导出Excel前,将工作簿中所有的自定义公式移除掉,其他内置的公式保留)
99
+ const removeCustomFormulas = [
100
+ "YJMAX",
101
+ "YJMIN",
102
+ "YJMID",
103
+ "YJGETNUM",
104
+ "YJGETS",
105
+ "YJGETCV",
106
+ "YJINTERPOLATIONMETHOD",
107
+ "YJINTERPOLATIONMETHOD_Y",
108
+ ];
109
+
110
+ // 临时工作簿
111
+ const tempSpread = new GC.Spread.Sheets.Workbook();
112
+ tempSpread.fromJSON(json);
113
+
114
+ // 暂停绘制
115
+ tempSpread.suspendPaint();
116
+
117
+ // 获取Sheet数量
118
+ const sheetCount = tempSpread.getSheetCount();
119
+
120
+ for (let iSheet = 0; iSheet < sheetCount; iSheet++) {
121
+ // 当前工作表
122
+ const sheet = tempSpread.getSheet(iSheet);
123
+
124
+ // 暂停公式的计算,提高性能
125
+ sheet.suspendCalcService();
126
+
127
+ for (var i = 0; i < sheet.getRowCount(); i++) {
128
+ for (var j = 0; j < sheet.getColumnCount(); j++) {
129
+ // 获取单元格的公式
130
+ const cellFormula = sheet.getFormula(i, j);
131
+
132
+ // 如果cellFormula不为null或undefined,则说明该单元格引用了公式
133
+ if (
134
+ cellFormula != null &&
135
+ cellFormula != undefined &&
136
+ removeCustomFormulas.some(
137
+ (item) => cellFormula.indexOf(item) > -1
138
+ )
139
+ ) {
140
+ // 获取单元格的值
141
+ const cellVal = sheet.getValue(i, j);
142
+
143
+ // 移除单元格引用的公式
144
+ sheet.getCell(i, j).formula(undefined);
145
+
146
+ // 设置单元格的值
147
+ sheet.setValue(i, j, cellVal);
148
+ }
149
+ }
150
+ }
151
+
152
+ // 恢复计算
153
+ sheet.resumeCalcService(false);
154
+ }
155
+
156
+ // 恢复绘制
157
+ tempSpread.resumePaint();
158
+
159
+ if (fileName == "") {
160
+ fileName = tempSpread.getSheet(0).name();
161
+ }
162
+
163
+ let options = {
164
+ fileType: GC.Spread.Sheets.FileType.excel,
165
+ includeBindingSource: true,
166
+ includeStyles: true,
167
+ includeFormulas: true,
168
+ saveAsView: false,
169
+ rowHeadersAsFrozenColumns: false,
170
+ columnHeadersAsFrozenRows: false,
171
+ includeAutoMergedCells: false,
172
+ includeCalcModelCache: false,
173
+ includeUnusedNames: true,
174
+ includeEmptyRegionCells: true,
175
+ };
176
+
177
+ tempSpread.export(
178
+ (blob: any) => {
179
+ saveAs(blob, `${fileName}.xlsx`);
180
+ },
181
+ () => {},
182
+ options
183
+ );
184
+
185
+ // 销毁临时工作簿
186
+ tempSpread.destroy();
187
+ },
188
+ };
package/tsconfig.json CHANGED
@@ -11,9 +11,10 @@
11
11
  // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
12
12
 
13
13
  /* Language and Environment */
14
- "target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
14
+ "target": "es6" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
15
15
  // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
16
16
  // "jsx": "preserve", /* Specify what JSX code is generated. */
17
+ // "libReplacement": true, /* Enable lib replacement. */
17
18
  // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
18
19
  // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
19
20
  // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
@@ -25,10 +26,9 @@
25
26
  // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
26
27
 
27
28
  /* Modules */
28
- "module": "commonjs" /* Specify what module code is generated. */,
29
+ "module": "esnext" /* Specify what module code is generated. */,
29
30
  // "rootDir": "./", /* Specify the root folder within your source files. */
30
31
  // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
31
- "moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */,
32
32
  // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
33
33
  // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
34
34
  // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
@@ -47,19 +47,19 @@
47
47
  // "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
48
48
 
49
49
  /* JavaScript Support */
50
- "allowJs": true /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */,
50
+ // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
51
51
  // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
52
52
  // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
53
53
 
54
54
  /* Emit */
55
55
  "declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */,
56
56
  // "declarationMap": true, /* Create sourcemaps for d.ts files. */
57
- "emitDeclarationOnly": true /* Only output d.ts files and not JavaScript files. */,
57
+ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
58
58
  // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
59
59
  // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
60
60
  // "noEmit": true, /* Disable emitting files from a compilation. */
61
61
  // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
62
- "outDir": "dist/types" /* Specify an output folder for all emitted files. */,
62
+ "outDir": "./dist" /* Specify an output folder for all emitted files. */,
63
63
  // "removeComments": true, /* Disable emitting comments. */
64
64
  // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
65
65
  // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
@@ -72,12 +72,13 @@
72
72
  // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
73
73
  // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
74
74
  // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
75
- // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
75
+ "declarationDir": "./dist" /* Specify the output directory for generated declaration files. */,
76
76
 
77
77
  /* Interop Constraints */
78
78
  // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
79
79
  // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
80
80
  // "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */
81
+ // "erasableSyntaxOnly": true, /* Do not allow runtime constructs that are not part of ECMAScript. */
81
82
  // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
82
83
  "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
83
84
  // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
package/.babelrc DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "presets": ["@babel/preset-env"]
3
- }
package/dist/index.js DELETED
@@ -1,27 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _sheet = require("./utils/sheet");
7
- Object.keys(_sheet).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _sheet[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function get() {
13
- return _sheet[key];
14
- }
15
- });
16
- });
17
- var _wookbook = require("./utils/wookbook");
18
- Object.keys(_wookbook).forEach(function (key) {
19
- if (key === "default" || key === "__esModule") return;
20
- if (key in exports && exports[key] === _wookbook[key]) return;
21
- Object.defineProperty(exports, key, {
22
- enumerable: true,
23
- get: function get() {
24
- return _wookbook[key];
25
- }
26
- });
27
- });
@@ -1 +0,0 @@
1
- export * from "./utils/sheet";
File without changes
@@ -1,24 +0,0 @@
1
- import { CellModel } from "../types/sheet";
2
- /**
3
- * SpreadJS工作表工具函数
4
- */
5
- export declare const SheetUtils: {
6
- /**
7
- * 获取当前活动工作表选中的单元格集合
8
- * @param spread 工作簿对象
9
- * @returns 返回选中单元格的集合,格式如:[{row:,col:,rowCount:,colCount:}]
10
- */
11
- getActiveSheetSelectCells: (spread: any) => any;
12
- /**
13
- * 设置当前活动工作表某个单元格范围为选中状态
14
- * @param spread 工作簿对象
15
- * @param cellObj 设置选中的单元格,格式如:{row:0,col:0,rowCount:1,colCount:1}
16
- */
17
- setActiveSheetSelectCells: (spread: any, cellObj: CellModel) => void;
18
- };
19
- /**
20
- * 测试的函数
21
- * @param num 传入的参数
22
- * @returns 返回传入的参数+1
23
- */
24
- export declare const TestFunc: (num: number) => number;
File without changes
package/src/index.js DELETED
@@ -1,2 +0,0 @@
1
- export * from "./utils/sheet";
2
- export * from "./utils/wookbook";
File without changes