From c423617e9d948b61cf9397710bf8f2098efe7634 Mon Sep 17 00:00:00 2001 From: xuri Date: Sun, 14 Apr 2019 12:55:44 +0800 Subject: Check max length for SetCellStr and fix coordinate issue for MergeCell --- calcchain.go | 1 + cell.go | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/calcchain.go b/calcchain.go index 6fbdcd7..22aab7e 100644 --- a/calcchain.go +++ b/calcchain.go @@ -54,6 +54,7 @@ func (f *File) deleteCalcChain(index int, axis string) { type xlsxCalcChainCollection []xlsxCalcChainC +// Filter provides a function to filter calculation chain. func (c xlsxCalcChainCollection) Filter(fn func(v xlsxCalcChainC) bool) []xlsxCalcChainC { results := make([]xlsxCalcChainC, 0) for _, v := range c { diff --git a/cell.go b/cell.go index 36f2d93..f9bf174 100644 --- a/cell.go +++ b/cell.go @@ -183,6 +183,9 @@ func (f *File) SetCellStr(sheet, axis, value string) error { if err != nil { return err } + if len(value) > 32767 { + value = value[0:32767] + } // Leading space(s) character detection. if len(value) > 0 && value[0] == 32 { cellData.XMLSpace = xml.Attr{ @@ -352,6 +355,7 @@ func (f *File) MergeCell(sheet, hcell, vcell string) error { return err } + // Correct the coordinate area, such correct C1:B3 to B1:C3. if vcol < hcol { hcol, vcol = vcol, hcol } @@ -378,9 +382,10 @@ func (f *File) MergeCell(sheet, hcell, vcell string) error { c2, _ := checkCellInArea(vcell, cellData.Ref) c3, _ := checkCellInArea(cc[0], ref) c4, _ := checkCellInArea(cc[1], ref) - if !c1 && !c2 && !c3 && !c4 { - cells = append(cells, cellData) + if !(!c1 && !c2 && !c3 && !c4) { + return nil } + cells = append(cells, cellData) } cells = append(xlsx.MergeCells.Cells, &xlsxMergeCell{Ref: ref}) xlsx.MergeCells.Cells = cells @@ -543,10 +548,10 @@ func checkCellInArea(cell, area string) (bool, error) { return false, err } - firstCol, firtsRow, _ := CellNameToCoordinates(rng[0]) + firstCol, firstRow, _ := CellNameToCoordinates(rng[0]) lastCol, lastRow, _ := CellNameToCoordinates(rng[1]) - return col >= firstCol && col <= lastCol && row >= firtsRow && row <= lastRow, err + return col >= firstCol && col <= lastCol && row >= firstRow && row <= lastRow, err } // getSharedForumula find a cell contains the same formula as another cell, -- cgit v1.2.1