summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxuri <xuri.me@gmail.com>2019-04-14 12:55:44 +0800
committerxuri <xuri.me@gmail.com>2019-04-14 12:55:44 +0800
commitc423617e9d948b61cf9397710bf8f2098efe7634 (patch)
tree7314563d6a8210752e3d576d760cd8692dda86bd
parent031ae303fd37b43f687c57edbf58cad7f354f8c7 (diff)
Check max length for SetCellStr and fix coordinate issue for MergeCell
-rw-r--r--calcchain.go1
-rw-r--r--cell.go13
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,