@@ -25,7 +25,7 @@ import (
25
25
26
26
// StreamWriter defined the type of stream writer.
27
27
type StreamWriter struct {
28
- File * File
28
+ file * File
29
29
Sheet string
30
30
SheetID int
31
31
sheetWritten bool
@@ -107,7 +107,7 @@ func (f *File) NewStreamWriter(sheet string) (*StreamWriter, error) {
107
107
return nil , newNoExistSheetError (sheet )
108
108
}
109
109
sw := & StreamWriter {
110
- File : f ,
110
+ file : f ,
111
111
Sheet : sheet ,
112
112
SheetID : sheetID ,
113
113
}
@@ -169,7 +169,7 @@ func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error {
169
169
}
170
170
171
171
// Correct table reference range, such correct C1:B3 to B1:C3.
172
- ref , err := sw .File .coordinatesToRangeRef (coordinates )
172
+ ref , err := sw .file .coordinatesToRangeRef (coordinates )
173
173
if err != nil {
174
174
return err
175
175
}
@@ -187,7 +187,7 @@ func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error {
187
187
}
188
188
}
189
189
190
- tableID := sw .File .countTables () + 1
190
+ tableID := sw .file .countTables () + 1
191
191
192
192
name := options .TableName
193
193
if name == "" {
@@ -220,17 +220,17 @@ func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error {
220
220
tableXML := strings .ReplaceAll (sheetRelationshipsTableXML , ".." , "xl" )
221
221
222
222
// Add first table for given sheet.
223
- sheetPath := sw .File .sheetMap [trimSheetName (sw .Sheet )]
223
+ sheetPath := sw .file .sheetMap [trimSheetName (sw .Sheet )]
224
224
sheetRels := "xl/worksheets/_rels/" + strings .TrimPrefix (sheetPath , "xl/worksheets/" ) + ".rels"
225
- rID := sw .File .addRels (sheetRels , SourceRelationshipTable , sheetRelationshipsTableXML , "" )
225
+ rID := sw .file .addRels (sheetRels , SourceRelationshipTable , sheetRelationshipsTableXML , "" )
226
226
227
227
sw .tableParts = fmt .Sprintf (`<tableParts count="1"><tablePart r:id="rId%d"></tablePart></tableParts>` , rID )
228
228
229
- if err = sw .File .addContentTypePart (tableID , "table" ); err != nil {
229
+ if err = sw .file .addContentTypePart (tableID , "table" ); err != nil {
230
230
return err
231
231
}
232
232
b , _ := xml .Marshal (table )
233
- sw .File .saveFileList (tableXML , b )
233
+ sw .file .saveFileList (tableXML , b )
234
234
return err
235
235
}
236
236
@@ -243,7 +243,7 @@ func (sw *StreamWriter) getRowValues(hRow, hCol, vCol int) (res []string, err er
243
243
return nil , err
244
244
}
245
245
246
- dec := sw .File .xmlNewDecoder (r )
246
+ dec := sw .file .xmlNewDecoder (r )
247
247
for {
248
248
token , err := dec .Token ()
249
249
if err == io .EOF {
@@ -269,7 +269,7 @@ func (sw *StreamWriter) getRowValues(hRow, hCol, vCol int) (res []string, err er
269
269
if col < hCol || col > vCol {
270
270
continue
271
271
}
272
- res [col - hCol ], _ = c .getValueFrom (sw .File , nil , false )
272
+ res [col - hCol ], _ = c .getValueFrom (sw .file , nil , false )
273
273
}
274
274
return res , nil
275
275
}
@@ -438,6 +438,14 @@ func (sw *StreamWriter) SetColWidth(min, max int, width float64) error {
438
438
return nil
439
439
}
440
440
441
+ // InsertPageBreak create a page break to determine where the printed page
442
+ // ends and where begins the next one by given worksheet name and cell
443
+ // reference, so the content before the page break will be printed on one page
444
+ // and after the page break on another.
445
+ func (sw * StreamWriter ) InsertPageBreak (cell string ) error {
446
+ return sw .worksheet .insertPageBreak (cell )
447
+ }
448
+
441
449
// SetPanes provides a function to create and remove freeze panes and split
442
450
// panes by given worksheet name and panes options for the StreamWriter. Note
443
451
// that you must call the 'SetPanes' function before the 'SetRow' function.
@@ -475,15 +483,15 @@ func setCellFormula(c *xlsxC, formula string) {
475
483
// setCellTime provides a function to set number of a cell with a time.
476
484
func (sw * StreamWriter ) setCellTime (c * xlsxC , val time.Time ) error {
477
485
var date1904 , isNum bool
478
- wb , err := sw .File .workbookReader ()
486
+ wb , err := sw .file .workbookReader ()
479
487
if err != nil {
480
488
return err
481
489
}
482
490
if wb != nil && wb .WorkbookPr != nil {
483
491
date1904 = wb .WorkbookPr .Date1904
484
492
}
485
493
if isNum , err = c .setCellTime (val , date1904 ); err == nil && isNum && c .S == 0 {
486
- style , _ := sw .File .NewStyle (& Style {NumFmt : 22 })
494
+ style , _ := sw .file .NewStyle (& Style {NumFmt : 22 })
487
495
c .S = style
488
496
}
489
497
return nil
@@ -643,10 +651,10 @@ func (sw *StreamWriter) Flush() error {
643
651
return err
644
652
}
645
653
646
- sheetPath := sw .File .sheetMap [trimSheetName (sw .Sheet )]
647
- sw .File .Sheet .Delete (sheetPath )
648
- delete (sw .File .checked , sheetPath )
649
- sw .File .Pkg .Delete (sheetPath )
654
+ sheetPath := sw .file .sheetMap [trimSheetName (sw .Sheet )]
655
+ sw .file .Sheet .Delete (sheetPath )
656
+ delete (sw .file .checked , sheetPath )
657
+ sw .file .Pkg .Delete (sheetPath )
650
658
651
659
return nil
652
660
}
0 commit comments