pp-robot-module 0.2.14

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.
Files changed (84) hide show
  1. package/README.md +34 -0
  2. package/dist/MR/Ai.d.ts +8 -0
  3. package/dist/MR/Ai.js +24 -0
  4. package/dist/MR/Clipboard.d.ts +20 -0
  5. package/dist/MR/Clipboard.js +60 -0
  6. package/dist/MR/Csv.d.ts +20 -0
  7. package/dist/MR/Csv.js +56 -0
  8. package/dist/MR/Date.d.ts +60 -0
  9. package/dist/MR/Date.js +94 -0
  10. package/dist/MR/DbClient.d.ts +97 -0
  11. package/dist/MR/DbClient.js +269 -0
  12. package/dist/MR/Dialog.d.ts +0 -0
  13. package/dist/MR/Dialog.js +40 -0
  14. package/dist/MR/Excel.d.ts +110 -0
  15. package/dist/MR/Excel.js +316 -0
  16. package/dist/MR/File.d.ts +162 -0
  17. package/dist/MR/File.js +399 -0
  18. package/dist/MR/Hash.d.ts +12 -0
  19. package/dist/MR/Hash.js +21 -0
  20. package/dist/MR/Html.d.ts +38 -0
  21. package/dist/MR/Html.js +163 -0
  22. package/dist/MR/Http.d.ts +33 -0
  23. package/dist/MR/Http.js +121 -0
  24. package/dist/MR/Imap.d.ts +15 -0
  25. package/dist/MR/Imap.js +52 -0
  26. package/dist/MR/Ini.d.ts +31 -0
  27. package/dist/MR/Ini.js +55 -0
  28. package/dist/MR/Keyboard.d.ts +59 -0
  29. package/dist/MR/Keyboard.js +515 -0
  30. package/dist/MR/Log.d.ts +7 -0
  31. package/dist/MR/Log.js +52 -0
  32. package/dist/MR/Mouse.d.ts +51 -0
  33. package/dist/MR/Mouse.js +152 -0
  34. package/dist/MR/Net.d.ts +17 -0
  35. package/dist/MR/Net.js +74 -0
  36. package/dist/MR/Pdf.d.ts +113 -0
  37. package/dist/MR/Pdf.js +197 -0
  38. package/dist/MR/Process.d.ts +46 -0
  39. package/dist/MR/Process.js +106 -0
  40. package/dist/MR/QRcode.d.ts +13 -0
  41. package/dist/MR/QRcode.js +37 -0
  42. package/dist/MR/RedisClient.d.ts +40 -0
  43. package/dist/MR/RedisClient.js +183 -0
  44. package/dist/MR/Regex.d.ts +16 -0
  45. package/dist/MR/Regex.js +20 -0
  46. package/dist/MR/Robot.d.ts +19 -0
  47. package/dist/MR/Robot.js +31 -0
  48. package/dist/MR/Screen.d.ts +20 -0
  49. package/dist/MR/Screen.js +79 -0
  50. package/dist/MR/Smtp.d.ts +21 -0
  51. package/dist/MR/Smtp.js +83 -0
  52. package/dist/MR/String.d.ts +104 -0
  53. package/dist/MR/String.js +166 -0
  54. package/dist/MR/System.d.ts +31 -0
  55. package/dist/MR/System.js +201 -0
  56. package/dist/MR/Validator.d.ts +30 -0
  57. package/dist/MR/Validator.js +104 -0
  58. package/dist/MR/WebBrowser.d.ts +210 -0
  59. package/dist/MR/WebBrowser.js +484 -0
  60. package/dist/MR/WebBrowser2.d.ts +0 -0
  61. package/dist/MR/WebBrowser2.js +504 -0
  62. package/dist/MR/WebElement.d.ts +123 -0
  63. package/dist/MR/WebElement.js +172 -0
  64. package/dist/MR/WebKeyboard.d.ts +21 -0
  65. package/dist/MR/WebKeyboard.js +48 -0
  66. package/dist/MR/WebMouse.d.ts +46 -0
  67. package/dist/MR/WebMouse.js +79 -0
  68. package/dist/MR/Window.d.ts +8 -0
  69. package/dist/MR/Window.js +34 -0
  70. package/dist/MR/Word.d.ts +56 -0
  71. package/dist/MR/Word.js +220 -0
  72. package/dist/MR/Zip.d.ts +25 -0
  73. package/dist/MR/Zip.js +89 -0
  74. package/dist/bin/inputting-method.exe +0 -0
  75. package/dist/bin/keyboard-password.exe +0 -0
  76. package/dist/bin/lock-window.exe +0 -0
  77. package/dist/bin/printer-pdf.exe +0 -0
  78. package/dist/dotenv.d.ts +0 -0
  79. package/dist/dotenv.js +2 -0
  80. package/dist/index.d.ts +54 -0
  81. package/dist/index.js +63 -0
  82. package/dist/util.d.ts +17 -0
  83. package/dist/util.js +41 -0
  84. package/package.json +120 -0
@@ -0,0 +1,316 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MR = void 0;
4
+ const xlsx = require("xlsx");
5
+ const path = require("path");
6
+ const File_1 = require("./File");
7
+ const Log_1 = require("./Log");
8
+ var MR;
9
+ (function (MR) {
10
+ class Excel {
11
+ constructor() { }
12
+ static get instance() {
13
+ if (!this.excel) {
14
+ this.excel = new Excel();
15
+ }
16
+ return this.excel;
17
+ }
18
+ load(filePath) {
19
+ this._filename = filePath;
20
+ this._workbook = xlsx.readFile(filePath);
21
+ }
22
+ open(params) {
23
+ Log_1.default.debug("Excel.open", params);
24
+ this.load(params._filename);
25
+ let sheetName = this._workbook.SheetNames[0];
26
+ if (params._sheetname) {
27
+ sheetName = this._workbook.SheetNames.find((name) => name === params._sheetname);
28
+ }
29
+ this._sheet = this._workbook.Sheets[sheetName];
30
+ return this._workbook;
31
+ }
32
+ sheetNames() {
33
+ Log_1.default.debug("Excel.sheetNames");
34
+ return this._workbook.SheetNames;
35
+ }
36
+ getData(params) {
37
+ Log_1.default.debug("Excel.sheet", params);
38
+ if (params._sheetname) {
39
+ let sheetName = this._workbook.SheetNames.find((name) => name === params._sheetname);
40
+ this._sheet = this._workbook.Sheets[sheetName];
41
+ }
42
+ if (params._type) {
43
+ let res = undefined;
44
+ switch (params._type) {
45
+ case 'json':
46
+ res = xlsx.utils.sheet_to_json(this._sheet);
47
+ break;
48
+ case 'csv':
49
+ res = xlsx.utils.sheet_to_csv(this._sheet);
50
+ break;
51
+ case 'txt':
52
+ res = xlsx.utils.sheet_to_txt(this._sheet);
53
+ break;
54
+ case 'html':
55
+ res = xlsx.utils.sheet_to_html(this._sheet);
56
+ break;
57
+ case 'formulae':
58
+ res = xlsx.utils.sheet_to_formulae(this._sheet);
59
+ break;
60
+ }
61
+ return res;
62
+ }
63
+ else {
64
+ return xlsx.utils.sheet_to_json(this._sheet);
65
+ }
66
+ }
67
+ ec(row, column) {
68
+ return xlsx.utils.encode_cell({ r: row, c: column });
69
+ }
70
+ buildStyle(params = { _fontname: '宋体', _fontsize: 12, _fontrgb: 'FFFFAA00', _fontbold: false }) {
71
+ return {
72
+ // set the style for target cell
73
+ font: {
74
+ name: params._fontsize,
75
+ sz: params._fontsize,
76
+ bold: params._fontbold,
77
+ color: {
78
+ rgb: params._fontrgb,
79
+ }
80
+ },
81
+ };
82
+ }
83
+ //清空列
84
+ clearColumn(params) {
85
+ Log_1.default.debug("Excel.clearColumn", params);
86
+ const columnIndex = xlsx.utils.decode_col(params._column);
87
+ const range = xlsx.utils.decode_range(this._sheet['!ref']);
88
+ for (let r = range.s.r; r <= range.e.r; r++) {
89
+ const cellRef = xlsx.utils.encode_cell({ r, c: columnIndex });
90
+ delete this._sheet[cellRef];
91
+ }
92
+ xlsx.writeFile(this._workbook, this._filename);
93
+ }
94
+ //删除列
95
+ deleteColumn(params) {
96
+ Log_1.default.debug("Excel.deleteColumn", params);
97
+ const columnIndex = xlsx.utils.decode_col(params._column);
98
+ let range = xlsx.utils.decode_range(this._sheet["!ref"]);
99
+ for (let r = range.s.r; r <= range.e.r; r++) {
100
+ for (var C = columnIndex; C <= range.e.c; ++C) {
101
+ this._sheet[this.ec(r, C)] = this._sheet[this.ec(r, C + 1)];
102
+ }
103
+ }
104
+ range.e.c--;
105
+ this._sheet["!ref"] = xlsx.utils.encode_range(range.s, range.e);
106
+ xlsx.writeFile(this._workbook, this._filename);
107
+ }
108
+ //清空行
109
+ clearRow(params) {
110
+ Log_1.default.debug("Excel.clearRow", params);
111
+ let row = params._row < 0 ? 0 : params._row - 1;
112
+ const range = xlsx.utils.decode_range(this._sheet['!ref']);
113
+ for (var C = range.s.c; C <= range.e.c; ++C) {
114
+ const cellRef = xlsx.utils.encode_cell({ r: row, c: C });
115
+ delete this._sheet[cellRef];
116
+ }
117
+ xlsx.writeFile(this._workbook, this._filename);
118
+ }
119
+ //删除行
120
+ deleteRow(params) {
121
+ Log_1.default.debug("Excel.deleteRow", params);
122
+ let row = params._row < 0 ? 0 : params._row - 1;
123
+ let range = xlsx.utils.decode_range(this._sheet["!ref"]);
124
+ for (let r = row; r <= range.e.r; r++) {
125
+ for (var C = range.s.c; C <= range.e.c; ++C) {
126
+ this._sheet[this.ec(r, C)] = this._sheet[this.ec(r + 1, C)];
127
+ }
128
+ }
129
+ range.e.r--;
130
+ this._sheet["!ref"] = xlsx.utils.encode_range(range.s, range.e);
131
+ xlsx.writeFile(this._workbook, this._filename);
132
+ }
133
+ //行列 长度
134
+ size(params = {}) {
135
+ Log_1.default.debug("Excel.range", params);
136
+ if (params._sheetname) {
137
+ this.posSheet({ _sheetname: params._sheetname });
138
+ }
139
+ return this._sheet['!ref'];
140
+ }
141
+ //添加公式
142
+ formula(params) {
143
+ Log_1.default.debug("Excel.formula", params);
144
+ if (params._sheetname) {
145
+ this.posSheet({ _sheetname: params._sheetname });
146
+ }
147
+ //xlsx.utils.sheet_set_array_formula(this._sheet, "C1", "SUM(A1:A3*B1:B3)");
148
+ xlsx.utils.sheet_set_array_formula(this._sheet, params._range, params._formula);
149
+ xlsx.writeFile(this._workbook, this._filename);
150
+ }
151
+ //行列对象
152
+ range(params = {}) {
153
+ Log_1.default.debug("Excel.range", params);
154
+ if (params._sheetname) {
155
+ this.posSheet({ _sheetname: params._sheetname });
156
+ }
157
+ var range = xlsx.utils.decode_range(this._sheet['!ref']);
158
+ return range;
159
+ }
160
+ //获取某一行数据
161
+ row(params) {
162
+ Log_1.default.debug("Excel.row", params);
163
+ let row = params._row < 0 ? 0 : params._row - 1;
164
+ let range = xlsx.utils.decode_range(this._sheet["!ref"]);
165
+ let data = [];
166
+ for (var C = range.s.c; C <= range.e.c; ++C) {
167
+ const cell = this._sheet[this.ec(row, C)];
168
+ if (cell) {
169
+ data.push(cell.v);
170
+ }
171
+ else {
172
+ data.push('');
173
+ }
174
+ }
175
+ return data;
176
+ }
177
+ //获取某一列数据
178
+ column(params) {
179
+ Log_1.default.debug("Excel.column", params);
180
+ let data = [];
181
+ const columnIndex = xlsx.utils.decode_col(params._column);
182
+ let range = xlsx.utils.decode_range(this._sheet["!ref"]);
183
+ for (let r = range.s.r; r <= range.e.r; r++) {
184
+ const cell = this._sheet[this.ec(r, columnIndex)];
185
+ if (cell) {
186
+ data.push(cell.v);
187
+ }
188
+ else {
189
+ data.push('');
190
+ }
191
+ }
192
+ return data;
193
+ }
194
+ cell(params) {
195
+ Log_1.default.debug("Excel.cell", params);
196
+ var desired_cell = this._sheet[params._pos];
197
+ if (params._value) {
198
+ let oriData = desired_cell.v;
199
+ desired_cell.v = params._value;
200
+ xlsx.writeFile(this._workbook, this._filename);
201
+ return oriData;
202
+ }
203
+ else {
204
+ var desired_value = (desired_cell ? desired_cell.v : undefined);
205
+ return desired_value;
206
+ }
207
+ }
208
+ /**
209
+ * Convert to CSV/other and export file.
210
+ */
211
+ convert(params) {
212
+ Log_1.default.debug("Excel.convert", params);
213
+ let outFilename = `${params._filename}.${params._type}`;
214
+ if (params._filename) {
215
+ this.load(params._filename);
216
+ outFilename = `${path.parse(params._filename).name}_${params._sheetname}.${params._type}`;
217
+ }
218
+ const res = this.getData({ _type: params._type, _sheetname: params._sheetname });
219
+ File_1.default.write({ _filename: outFilename, _data: res });
220
+ return outFilename;
221
+ }
222
+ //定位sheet
223
+ posSheet(params) {
224
+ Log_1.default.debug("Excel.posSheet", params);
225
+ const sheetName = this._workbook.SheetNames.find((name) => name === params._sheetname);
226
+ this._sheet = this._workbook.Sheets[sheetName];
227
+ }
228
+ addSheet(params) {
229
+ Log_1.default.debug("Excel.addSheet", params._sheetname, params._type);
230
+ let workSheet;
231
+ if (params._type === 'aoa') {
232
+ workSheet = xlsx.utils.aoa_to_sheet(params._data);
233
+ }
234
+ else {
235
+ workSheet = xlsx.utils.json_to_sheet(params._data);
236
+ }
237
+ xlsx.utils.book_append_sheet(this._workbook, workSheet, params._sheetname);
238
+ }
239
+ //sheet上追加数据
240
+ put(params) {
241
+ Log_1.default.debug("Excel.put", params._data);
242
+ if (params._sheetname) {
243
+ this.posSheet({ _sheetname: params._sheetname });
244
+ }
245
+ if (params._type === 'json') {
246
+ let tmpSheetJson = xlsx.utils.sheet_to_json(this._sheet);
247
+ tmpSheetJson.push(params._data);
248
+ xlsx.utils.sheet_add_json(this._sheet, tmpSheetJson);
249
+ }
250
+ else {
251
+ xlsx.utils.sheet_add_aoa(this._sheet, params._data);
252
+ }
253
+ xlsx.writeFile(this._workbook, this._filename);
254
+ }
255
+ //覆盖数据
256
+ cover(params) {
257
+ Log_1.default.debug("Excel.cover", params._data);
258
+ if (params._sheetname) {
259
+ this.posSheet({ _sheetname: params._sheetname });
260
+ }
261
+ const workBook = xlsx.utils.book_new();
262
+ let workSheet;
263
+ if (params._type === 'aoa') {
264
+ workSheet = xlsx.utils.aoa_to_sheet(params._data);
265
+ }
266
+ else {
267
+ workSheet = xlsx.utils.json_to_sheet(params._data);
268
+ }
269
+ xlsx.utils.book_append_sheet(workBook, workSheet);
270
+ xlsx.writeFile(workBook, this._filename);
271
+ }
272
+ write(params) {
273
+ Log_1.default.debug("Excel.write", params._filename);
274
+ const workBook = xlsx.utils.book_new();
275
+ const workSheet = xlsx.utils.json_to_sheet(params._data);
276
+ xlsx.utils.book_append_sheet(workBook, workSheet);
277
+ xlsx.writeFile(workBook, params._filename);
278
+ }
279
+ /**
280
+ * Convert to CSV and export file.
281
+ */
282
+ toCSV(params) {
283
+ Log_1.default.debug("Excel.toCSV", params);
284
+ const workbook = xlsx.readFile(params._filename);
285
+ let outFilename = `${params._filename}.csv`;
286
+ //转换指定的sheetname
287
+ if (params._sheetname) {
288
+ outFilename = `${path.parse(params._filename).name}_${params._sheetname}.csv`;
289
+ const sheetName = workbook.SheetNames.find((name) => name === params._sheetname);
290
+ const sheet = workbook.Sheets[sheetName];
291
+ if (sheet) {
292
+ const csv = xlsx.utils.sheet_to_csv(sheet);
293
+ File_1.default.write({ _filename: outFilename, _data: csv });
294
+ }
295
+ return outFilename;
296
+ }
297
+ else {
298
+ //转换全部的sheet
299
+ const sheetNames = workbook.SheetNames;
300
+ let csvNames = [];
301
+ for (let sheetName of sheetNames) {
302
+ outFilename = `${path.parse(params._filename).name}_${sheetName}.csv`;
303
+ const sheet = workbook.Sheets[sheetName];
304
+ if (sheet) {
305
+ const csv = xlsx.utils.sheet_to_csv(sheet);
306
+ File_1.default.write({ _filename: outFilename, _data: csv });
307
+ csvNames.push(outFilename);
308
+ }
309
+ }
310
+ return csvNames;
311
+ }
312
+ }
313
+ }
314
+ MR.Excel = Excel;
315
+ })(MR = exports.MR || (exports.MR = {}));
316
+ exports.default = MR.Excel.instance;
@@ -0,0 +1,162 @@
1
+ /// <reference types="node" />
2
+ import fs = require("fs");
3
+ declare enum SortType {
4
+ Name = "name",
5
+ Birthtime = "birthtime",
6
+ Ctime = "ctime",
7
+ Mtime = "mtime",
8
+ Size = "size"
9
+ }
10
+ declare enum OrderBy {
11
+ ASC = 0,
12
+ DESC = 1
13
+ }
14
+ export declare namespace MR {
15
+ class File {
16
+ static readonly SortType: typeof SortType;
17
+ static readonly OrderBy: typeof OrderBy;
18
+ private constructor();
19
+ static copy(params: {
20
+ _srcFile: string;
21
+ _destFile: string;
22
+ _options?: any;
23
+ }): Promise<any>;
24
+ static emptyDir(params: {
25
+ _dir: string;
26
+ }): Promise<boolean>;
27
+ static ensureFile(params: {
28
+ _filename: string;
29
+ }): Promise<any>;
30
+ static ensureDir(params: {
31
+ _dir: string;
32
+ _options: any;
33
+ }): Promise<boolean>;
34
+ static mkdirp(params: {
35
+ _dir: string;
36
+ _options: any;
37
+ }): Promise<any>;
38
+ static move(params: {
39
+ _srcFile: string;
40
+ _destFile: string;
41
+ }): Promise<void>;
42
+ static pathExists(params: {
43
+ _filename: string;
44
+ }): Promise<any>;
45
+ static outputFile(params: {
46
+ _filename: string;
47
+ _data: string;
48
+ _encoding?: string;
49
+ }): Promise<any>;
50
+ static readFile(params: {
51
+ _filename: string;
52
+ _encoding?: string;
53
+ }): Promise<any>;
54
+ static outputJson(params: {
55
+ _filename: string;
56
+ _data: string;
57
+ _encoding?: string;
58
+ }): Promise<void>;
59
+ static readJson(params: {
60
+ _filename: string;
61
+ _encoding?: string;
62
+ }): Promise<any>;
63
+ static remove(params: {
64
+ _filename: string;
65
+ }): Promise<any>;
66
+ static detail(params: {
67
+ _filename: string;
68
+ }): Promise<{
69
+ isFile: boolean;
70
+ isDirectory: boolean;
71
+ sizeForamt: string;
72
+ size: number;
73
+ birthtime: Date;
74
+ modifytime: Date;
75
+ filename: string;
76
+ extname: string;
77
+ dirname: string;
78
+ fullpath: string;
79
+ }>;
80
+ private static formatFileSize;
81
+ static folderSize(params: {
82
+ _dir: string;
83
+ }): Promise<string>;
84
+ private static getFolderSize;
85
+ static getLastedFile(params: {
86
+ _dir: string;
87
+ }): Promise<any>;
88
+ private static getNewestFileInDirectory;
89
+ /**
90
+ * Change the name or location of a file or directory.
91
+ * @param params
92
+ */
93
+ static rename(params: {
94
+ /** A relative path to a file from {@link outDir}. */
95
+ _oldFile: string;
96
+ /** A relative path to a file from {@link outDir}. */
97
+ _newFile: string;
98
+ }): void;
99
+ /**
100
+ * Write data to a file, replacing the file if it already exists.
101
+ * @param params
102
+ */
103
+ static write(params: {
104
+ /** A relative path to a file from {@link outDir}. */
105
+ _filename: string;
106
+ _data: any;
107
+ }): void;
108
+ /**
109
+ * Create a directory.
110
+ * @param params
111
+ */
112
+ static makeDir(params: {
113
+ /** A relative path to the new directory from {@link outDir}. */
114
+ _dir: string;
115
+ }): void;
116
+ /**
117
+ * Get file status.
118
+ * @param params
119
+ */
120
+ static getStats(params: {
121
+ /** A relative path to a file from {@link outDir}. */
122
+ _filename: string;
123
+ }): fs.Stats;
124
+ /**
125
+ * Lists files or directories in a directory.
126
+ * @param params
127
+ */
128
+ static list(params?: {
129
+ /** A relative path to a directory from {@link outDir}. */
130
+ _dir?: string;
131
+ /** If specified, sorts by sortType */
132
+ sortType?: SortType;
133
+ /** Whether the sort order is descending or ascending. The default is ascending. */
134
+ orderBy?: OrderBy;
135
+ }): string[];
136
+ /**
137
+ * Lists only files in a directory.
138
+ * @param params
139
+ */
140
+ static listFiles(params?: {
141
+ /** A relative path to a directory from {@link outDir}. */
142
+ _dir?: string;
143
+ /** If specified, sorts by sortType */
144
+ sortType?: SortType;
145
+ /** Whether the sort order is descending or ascending. The default is ascending. */
146
+ orderBy?: OrderBy;
147
+ }): string[];
148
+ /**
149
+ * Tests whether the given path is a file.
150
+ * @param params
151
+ */
152
+ static isFile(params: {
153
+ /** A relative path to a file from {@link outDir}. */
154
+ _filename: string;
155
+ }): boolean;
156
+ static isDir(params: {
157
+ _filename: string;
158
+ }): boolean;
159
+ }
160
+ }
161
+ declare const _default: typeof MR.File;
162
+ export default _default;