ming_node 3.0.2 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +7 -0
- package/extlib/MingExcelTool.js +75 -0
- package/index.js +4 -10
- package/package.json +1 -1
package/README.md
CHANGED
@@ -220,3 +220,10 @@ https://minglie.github.io/os/ming_node/
|
|
220
220
|
# ming_node使用文档
|
221
221
|
|
222
222
|
https://www.yuque.com/docs/share/e1f16015-0719-4ffd-9464-a35610389153?# 《ming_node》
|
223
|
+
|
224
|
+
|
225
|
+
# ming_node使用文档
|
226
|
+
|
227
|
+
https://www.yuque.com/docs/share/e1f16015-0719-4ffd-9464-a35610389153?# 《ming_node》
|
228
|
+
|
229
|
+
https://unpkg.com/minglitlie-test/h5/index.html
|
@@ -0,0 +1,75 @@
|
|
1
|
+
const ExcelJS = require('exceljs');
|
2
|
+
|
3
|
+
class MingExcelTool {
|
4
|
+
worksheet;
|
5
|
+
constructor(path,indexOrName) {
|
6
|
+
this.path=path;
|
7
|
+
this.indexOrName=indexOrName;
|
8
|
+
}
|
9
|
+
async init(){
|
10
|
+
const workbook = new ExcelJS.Workbook();
|
11
|
+
this.workbook=workbook;
|
12
|
+
await workbook.xlsx.readFile(this.path);
|
13
|
+
this.worksheet = workbook.getWorksheet(this.indexOrName);
|
14
|
+
}
|
15
|
+
|
16
|
+
getCell(cellName){
|
17
|
+
const cell =this.worksheet.getCell(cellName);
|
18
|
+
return cell.value;
|
19
|
+
}
|
20
|
+
|
21
|
+
getColumn(indexOrKey){
|
22
|
+
const col =this.worksheet.getColumn(indexOrKey);
|
23
|
+
let r=[];
|
24
|
+
col.eachCell((cell, rowNumber) => {
|
25
|
+
if( "object"==typeof cell.value ){
|
26
|
+
if(cell.value==null){
|
27
|
+
r.push("");
|
28
|
+
}else{
|
29
|
+
r.push(cell.value.result);
|
30
|
+
}
|
31
|
+
}else {
|
32
|
+
r.push(cell.value);
|
33
|
+
}
|
34
|
+
});
|
35
|
+
return r;
|
36
|
+
}
|
37
|
+
|
38
|
+
getRow(indexOrKey){
|
39
|
+
const col =this.worksheet.getRow(indexOrKey);
|
40
|
+
let r=[];
|
41
|
+
col.eachCell((cell, rowNumber) => {
|
42
|
+
if( "object"==typeof cell.value ){
|
43
|
+
r.push(cell.value.result);
|
44
|
+
}else {
|
45
|
+
r.push(cell.value);
|
46
|
+
}
|
47
|
+
});
|
48
|
+
return r;
|
49
|
+
}
|
50
|
+
|
51
|
+
setCell(cellName,val){
|
52
|
+
this.worksheet.getCell(cellName).value = val;
|
53
|
+
}
|
54
|
+
|
55
|
+
async save(fileName){
|
56
|
+
await this.workbook.xlsx.writeFile(fileName);
|
57
|
+
}
|
58
|
+
|
59
|
+
}
|
60
|
+
|
61
|
+
|
62
|
+
function test(){
|
63
|
+
const me= new MingExcelTool('hq.xlsx',1 );
|
64
|
+
async function main(){
|
65
|
+
await me.init();
|
66
|
+
let c= me.getColumn(3);
|
67
|
+
me.setCell("H4","wer")
|
68
|
+
await me.save("D:/ming.xlsx")
|
69
|
+
console.log(c);
|
70
|
+
}
|
71
|
+
main()
|
72
|
+
}
|
73
|
+
|
74
|
+
test()
|
75
|
+
module.exports = MingExcelTool;
|
package/index.js
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
* By : Minglie
|
4
4
|
* QQ: 934031452
|
5
5
|
* Date :2021.12.01
|
6
|
-
* version :3.0.
|
6
|
+
* version :3.0.3
|
7
7
|
*/
|
8
8
|
const http = require('http');
|
9
9
|
const https = require('https');
|
@@ -189,8 +189,6 @@ M.get = function (url, callback, data, headers) {
|
|
189
189
|
});
|
190
190
|
req.on('error', function (err) {
|
191
191
|
reject(err);
|
192
|
-
console.error(err);
|
193
|
-
|
194
192
|
});
|
195
193
|
req.end();
|
196
194
|
})
|
@@ -276,8 +274,7 @@ M._request = function (url, callback, data, headers,methed) {
|
|
276
274
|
});
|
277
275
|
|
278
276
|
req.on('error', function (err) {
|
279
|
-
|
280
|
-
throw err;
|
277
|
+
reject(err);
|
281
278
|
});
|
282
279
|
if(methed !="GET") req.write(postData);
|
283
280
|
req.end();
|
@@ -361,8 +358,7 @@ M.postJson = function (url, callback, data, headers) {
|
|
361
358
|
});
|
362
359
|
|
363
360
|
req.on('error', function (err) {
|
364
|
-
|
365
|
-
throw err;
|
361
|
+
reject(err);
|
366
362
|
});
|
367
363
|
req.write(postData);
|
368
364
|
req.end();
|
@@ -393,7 +389,6 @@ M.require =async function (url,noCache) {
|
|
393
389
|
console.log("req require remote url:", url);
|
394
390
|
let promise = new Promise(function (reslove, reject) {
|
395
391
|
require(ht).get(url, function (req, res) {
|
396
|
-
res.setEncoding('utf-8');
|
397
392
|
let d = '';
|
398
393
|
req.on('data', (data) => {
|
399
394
|
d += data;
|
@@ -2112,8 +2107,7 @@ M.axios = function (axiosConfig) {
|
|
2112
2107
|
|
2113
2108
|
});
|
2114
2109
|
req.on('error', function (err) {
|
2115
|
-
|
2116
|
-
throw err;
|
2110
|
+
reject(err);
|
2117
2111
|
});
|
2118
2112
|
req.write(axiosConfig.body);
|
2119
2113
|
req.end();
|
package/package.json
CHANGED