@@ -16,6 +16,7 @@ export interface ConvertOptions {
16
16
openAsDownload ?: boolean ,
17
17
format : ( 'csv' | 'xls' | 'xlsx' ) ,
18
18
filename ?: string ,
19
+ rtl ?: boolean ,
19
20
}
20
21
export interface FromOptions {
21
22
table ?: ( string | HTMLTableElement ) ,
@@ -28,6 +29,7 @@ export interface SheetOptions {
28
29
filterRowFn ?( row :any [ ] ) : boolean ,
29
30
fixValue ?( value :any , row :number , column :number ) : any ,
30
31
fixArray ?( array :any [ ] [ ] ) : any [ ] [ ] ,
32
+ rtl ?: boolean
31
33
}
32
34
33
35
@@ -43,7 +45,8 @@ const ExcellentExport = function() {
43
45
anchor: String or HTML Element,
44
46
openAsDownload: boolean, // Use this options if not using an anchor tag
45
47
format: 'xlsx' or 'xls' or 'csv',
46
- filename: String
48
+ filename: String,
49
+ rtl: boolean (optional), specify if all the workbook has text in RTL mode
47
50
}
48
51
49
52
Sheets must be an array of sheet configuration objects. Sheet description:
@@ -58,6 +61,7 @@ const ExcellentExport = function() {
58
61
filterRowFn: function(row) {return true}, // Function to decide which rows are returned
59
62
fixValue: function(value, row, column) {return fixedValue} // Function to fix values, receiving value, row num, column num
60
63
fixArray: function(array) {return array} // Function to manipulate the whole data array
64
+ rtl: boolean // optional: specify if the sheet has text in RTL mode
61
65
...
62
66
},
63
67
{
@@ -68,7 +72,8 @@ const ExcellentExport = function() {
68
72
const convert = function ( options :ConvertOptions , sheets :SheetOptions [ ] ) {
69
73
const workbook = {
70
74
SheetNames : [ ] ,
71
- Sheets : { }
75
+ Sheets : { } ,
76
+ Views : [ ]
72
77
} ;
73
78
74
79
if ( ! options . format ) {
@@ -85,7 +90,7 @@ const ExcellentExport = function() {
85
90
}
86
91
87
92
// Select data source
88
- let dataArray ;
93
+ let dataArray : any [ ] [ ] ;
89
94
if ( sheetConf . from && sheetConf . from . table ) {
90
95
dataArray = utils . tableToArray ( utils . getTable ( sheetConf . from . table ) ) ;
91
96
} else if ( sheetConf . from && sheetConf . from . array ) {
@@ -107,7 +112,7 @@ const ExcellentExport = function() {
107
112
utils . removeColumns ( dataArray , sheetConf . removeColumns ) ;
108
113
}
109
114
110
- // Convert data, by value
115
+ // Convert data. Function applied to each value independently, receiving ( value, rownum, colnum)
111
116
if ( sheetConf . fixValue && typeof sheetConf . fixValue === 'function' ) {
112
117
const fn = sheetConf . fixValue ;
113
118
dataArray . map ( ( r , rownum ) => {
@@ -127,6 +132,7 @@ const ExcellentExport = function() {
127
132
workbook . SheetNames . push ( name ) ;
128
133
const worksheet = XLSX . utils . aoa_to_sheet ( dataArray , { sheet : name } as XLSX . AOA2SheetOpts ) ;
129
134
workbook . Sheets [ name ] = worksheet ;
135
+ workbook . Views . push ( { RTL : options . rtl || sheetConf . rtl || false } ) ;
130
136
} ) ;
131
137
132
138
const wbOut :string = XLSX . write ( workbook , { bookType : options . format , bookSST :true , type : 'binary' } ) ;
0 commit comments