Skip to content

Commit c423617

Browse files
committed
Check max length for SetCellStr and fix coordinate issue for MergeCell
1 parent 031ae30 commit c423617

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

calcchain.go

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func (f *File) deleteCalcChain(index int, axis string) {
5454

5555
type xlsxCalcChainCollection []xlsxCalcChainC
5656

57+
// Filter provides a function to filter calculation chain.
5758
func (c xlsxCalcChainCollection) Filter(fn func(v xlsxCalcChainC) bool) []xlsxCalcChainC {
5859
results := make([]xlsxCalcChainC, 0)
5960
for _, v := range c {

cell.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ func (f *File) SetCellStr(sheet, axis, value string) error {
183183
if err != nil {
184184
return err
185185
}
186+
if len(value) > 32767 {
187+
value = value[0:32767]
188+
}
186189
// Leading space(s) character detection.
187190
if len(value) > 0 && value[0] == 32 {
188191
cellData.XMLSpace = xml.Attr{
@@ -352,6 +355,7 @@ func (f *File) MergeCell(sheet, hcell, vcell string) error {
352355
return err
353356
}
354357

358+
// Correct the coordinate area, such correct C1:B3 to B1:C3.
355359
if vcol < hcol {
356360
hcol, vcol = vcol, hcol
357361
}
@@ -378,9 +382,10 @@ func (f *File) MergeCell(sheet, hcell, vcell string) error {
378382
c2, _ := checkCellInArea(vcell, cellData.Ref)
379383
c3, _ := checkCellInArea(cc[0], ref)
380384
c4, _ := checkCellInArea(cc[1], ref)
381-
if !c1 && !c2 && !c3 && !c4 {
382-
cells = append(cells, cellData)
385+
if !(!c1 && !c2 && !c3 && !c4) {
386+
return nil
383387
}
388+
cells = append(cells, cellData)
384389
}
385390
cells = append(xlsx.MergeCells.Cells, &xlsxMergeCell{Ref: ref})
386391
xlsx.MergeCells.Cells = cells
@@ -543,10 +548,10 @@ func checkCellInArea(cell, area string) (bool, error) {
543548
return false, err
544549
}
545550

546-
firstCol, firtsRow, _ := CellNameToCoordinates(rng[0])
551+
firstCol, firstRow, _ := CellNameToCoordinates(rng[0])
547552
lastCol, lastRow, _ := CellNameToCoordinates(rng[1])
548553

549-
return col >= firstCol && col <= lastCol && row >= firtsRow && row <= lastRow, err
554+
return col >= firstCol && col <= lastCol && row >= firstRow && row <= lastRow, err
550555
}
551556

552557
// getSharedForumula find a cell contains the same formula as another cell,

0 commit comments

Comments
 (0)