Check max length for SetCellStr and fix coordinate issue for MergeCell

This commit is contained in:
xuri 2019-04-14 12:55:44 +08:00
parent 031ae303fd
commit c423617e9d
No known key found for this signature in database
GPG Key ID: BA5E5BB1C948EDF7
2 changed files with 10 additions and 4 deletions

View File

@ -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 {

13
cell.go
View File

@ -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,