File tree 1 file changed +29
-2
lines changed
1 file changed +29
-2
lines changed Original file line number Diff line number Diff line change
1
+ import fs from 'fs'
1
2
import * as ExcelJS from 'exceljs'
3
+ import excelToJson from 'convert-excel-to-json'
2
4
3
- class ExcelHelper {
5
+ interface OptionConvert {
6
+ header ?: any
7
+ columnToKey ?: any
8
+ }
9
+
10
+ class Excel {
4
11
/**
5
12
*
6
13
* @param headers
@@ -35,6 +42,26 @@ class ExcelHelper {
35
42
} )
36
43
} )
37
44
}
45
+
46
+ /**
47
+ *
48
+ * @param path
49
+ * @param options
50
+ * options is used when there is only 1 sheet
51
+ */
52
+ public static convertToJson ( path : string | Buffer , options ?: OptionConvert ) {
53
+ const resultConvert = excelToJson ( {
54
+ source : fs . readFileSync ( path ) , // fs.readFileSync return a Buffer
55
+ header : options ?. header || {
56
+ rows : 1 ,
57
+ } ,
58
+ columnToKey : options ?. columnToKey || {
59
+ '*' : '{{columnHeader}}' ,
60
+ } ,
61
+ } )
62
+
63
+ return resultConvert
64
+ }
38
65
}
39
66
40
- export default ExcelHelper
67
+ export default Excel
You can’t perform that action at this time.
0 commit comments