File tree Expand file tree Collapse file tree 3 files changed +54
-8
lines changed Expand file tree Collapse file tree 3 files changed +54
-8
lines changed Original file line number Diff line number Diff line change @@ -365,6 +365,9 @@ worksheet.pageSetup.margins = {
365
365
// Set Print Area for a sheet
366
366
worksheet .pageSetup .printArea = ' A1:G20' ;
367
367
368
+ // Set multiple Print Areas by separating print areas with '&&'
369
+ worksheet .pageSetup .printArea = ' A1:G10&&A11:G20' ;
370
+
368
371
// Repeat specific rows on every printed page
369
372
worksheet .pageSetup .printTitlesRow = ' 1:3' ;
370
373
Original file line number Diff line number Diff line change @@ -34,14 +34,17 @@ class WorkbookXform extends BaseXform {
34
34
let index = 0 ; // sheets is sparse array - calc index manually
35
35
model . sheets . forEach ( sheet => {
36
36
if ( sheet . pageSetup && sheet . pageSetup . printArea ) {
37
- const printArea = sheet . pageSetup . printArea . split ( ':' ) ;
38
- const definedName = {
39
- name : '_xlnm.Print_Area' ,
40
- ranges : [ `'${ sheet . name } '!$${ printArea [ 0 ] } :$${ printArea [ 1 ] } ` ] ,
41
- localSheetId : index ,
42
- } ;
43
- printAreas . push ( definedName ) ;
44
- }
37
+ sheet . pageSetup . printArea . split ( '&&' ) . forEach ( printArea => {
38
+ const printAreaComponents = printArea . split ( ':' ) ;
39
+ const definedName = {
40
+ name : '_xlnm.Print_Area' ,
41
+ ranges : [ `'${ sheet . name } '!$${ printAreaComponents [ 0 ] } :$${ printAreaComponents [ 1 ] } ` ] ,
42
+ localSheetId : index ,
43
+ } ;
44
+ printAreas . push ( definedName ) ;
45
+ } ) ;
46
+ }
47
+
45
48
if ( sheet . pageSetup && ( sheet . pageSetup . printTitlesRow || sheet . pageSetup . printTitlesColumn ) ) {
46
49
const ranges = [ ] ;
47
50
Original file line number Diff line number Diff line change
1
+ const Excel = require ( '../excel' ) ;
2
+
3
+ const { Workbook} = Excel ;
4
+
5
+ const [ , , filename ] = process . argv ;
6
+
7
+ const wb = new Workbook ( ) ;
8
+ const ws = wb . addWorksheet ( 'test sheet' ) ;
9
+
10
+ for ( let row = 1 ; row <= 10 ; row ++ ) {
11
+ const values = [ ] ;
12
+ if ( row === 1 ) {
13
+ values . push ( '' ) ;
14
+ for ( let col = 2 ; col <= 10 ; col ++ ) {
15
+ values . push ( `Col ${ col } ` ) ;
16
+ }
17
+ } else {
18
+ for ( let col = 1 ; col <= 10 ; col ++ ) {
19
+ if ( col === 1 ) {
20
+ values . push ( `Row ${ row } ` ) ;
21
+ } else {
22
+ values . push ( `${ row } -${ col } ` ) ;
23
+ }
24
+ }
25
+ }
26
+ ws . addRow ( values ) ;
27
+ }
28
+
29
+ ws . pageSetup . printTitlesColumn = 'A:A' ;
30
+ ws . pageSetup . printTitlesRow = '1:1' ;
31
+ ws . pageSetup . printArea = 'A1:B5&&A6:B10' ;
32
+
33
+ wb . xlsx
34
+ . writeFile ( filename )
35
+ . then ( ( ) => {
36
+ console . log ( 'Done.' ) ;
37
+ } )
38
+ . catch ( error => {
39
+ console . log ( error . message ) ;
40
+ } ) ;
You can’t perform that action at this time.
0 commit comments