From c02346bafc6e098406f32ee0a183d45f3038c619 Mon Sep 17 00:00:00 2001 From: Harrison Date: Mon, 10 Oct 2022 13:05:02 -0300 Subject: This closes #1047, stream writer support set panes (#1123) - New exported error `ErrStreamSetPanes` has been added --- stream.go | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'stream.go') diff --git a/stream.go b/stream.go index 66c0fda..9f47762 100644 --- a/stream.go +++ b/stream.go @@ -119,7 +119,7 @@ func (f *File) NewStreamWriter(sheet string) (*StreamWriter, error) { f.streams[sheetXMLPath] = sw _, _ = sw.rawData.WriteString(xml.Header + ` 0 { - _, _ = sw.rawData.WriteString("" + sw.cols + "") - } - _, _ = sw.rawData.WriteString(``) - sw.sheetWritten = true - } + sw.writeSheetData() options := parseRowOpts(opts...) attrs, err := options.marshalAttrs() if err != nil { @@ -415,6 +409,16 @@ func (sw *StreamWriter) SetColWidth(min, max int, width float64) error { return nil } +// SetPanes provides a function to create and remove freeze panes and split +// panes by given worksheet name and panes options for the StreamWriter. Note +// that you must call the 'SetPanes' function before the 'SetRow' function. +func (sw *StreamWriter) SetPanes(panes string) error { + if sw.sheetWritten { + return ErrStreamSetPanes + } + return sw.worksheet.setPanes(panes) +} + // MergeCell provides a function to merge cells by a given range reference for // the StreamWriter. Don't create a merged cell that overlaps with another // existing merged cell. @@ -507,6 +511,7 @@ func setCellIntFunc(c *xlsxC, val interface{}) (err error) { return } +// writeCell constructs a cell XML and writes it to the buffer. func writeCell(buf *bufferedWriter, c xlsxC) { _, _ = buf.WriteString(``) } -// Flush ending the streaming writing process. -func (sw *StreamWriter) Flush() error { +// writeSheetData prepares the element preceding sheetData and writes the +// sheetData XML start element to the buffer. +func (sw *StreamWriter) writeSheetData() { if !sw.sheetWritten { + bulkAppendFields(&sw.rawData, sw.worksheet, 4, 5) + if len(sw.cols) > 0 { + _, _ = sw.rawData.WriteString("" + sw.cols + "") + } _, _ = sw.rawData.WriteString(``) sw.sheetWritten = true } +} + +// Flush ending the streaming writing process. +func (sw *StreamWriter) Flush() error { + sw.writeSheetData() _, _ = sw.rawData.WriteString(``) bulkAppendFields(&sw.rawData, sw.worksheet, 8, 15) mergeCells := strings.Builder{} -- cgit v1.2.1