diff options
| author | Ri Xu <xuri.me@gmail.com> | 2017-01-25 18:13:11 +0800 |
|---|---|---|
| committer | Ri Xu <xuri.me@gmail.com> | 2017-01-25 18:13:11 +0800 |
| commit | a1060e779ee295e9871e2fbe9148d8d9dc72a379 (patch) | |
| tree | 2203416f0de8cf2dd3c5f0c7e09b52fdc8f593ea /excelize.go | |
| parent | c0a3020886df623e76baedec04b97903573b6c0d (diff) | |
Make functions: `SetCellValue`, `SetCellInt`, `SetCellHyperLink`, `SetCellFormula`, `GetCellValue` and `GetCellFormula` to support the merged cells.
Diffstat (limited to 'excelize.go')
| -rw-r--r-- | excelize.go | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/excelize.go b/excelize.go index d43f123..ed36589 100644 --- a/excelize.go +++ b/excelize.go @@ -64,14 +64,20 @@ func (f *File) SetCellValue(sheet string, axis string, value interface{}) { func (f *File) SetCellInt(sheet string, axis string, value int) { axis = strings.ToUpper(axis) var xlsx xlsxWorksheet + name := "xl/worksheets/" + strings.ToLower(sheet) + ".xml" + xml.Unmarshal([]byte(f.readXML(name)), &xlsx) + if xlsx.MergeCells != nil { + for i := 0; i < len(xlsx.MergeCells.Cells); i++ { + if checkCellInArea(axis, xlsx.MergeCells.Cells[i].Ref) { + axis = strings.Split(xlsx.MergeCells.Cells[i].Ref, ":")[0] + } + } + } col := string(strings.Map(letterOnlyMapF, axis)) row, _ := strconv.Atoi(strings.Map(intOnlyMapF, axis)) xAxis := row - 1 yAxis := titleToNumber(col) - name := "xl/worksheets/" + strings.ToLower(sheet) + ".xml" - xml.Unmarshal([]byte(f.readXML(name)), &xlsx) - rows := xAxis + 1 cell := yAxis + 1 @@ -89,18 +95,24 @@ func (f *File) SetCellInt(sheet string, axis string, value int) { // of characters that a cell can contain 32767 characters. func (f *File) SetCellStr(sheet string, axis string, value string) { axis = strings.ToUpper(axis) + var xlsx xlsxWorksheet + name := "xl/worksheets/" + strings.ToLower(sheet) + ".xml" + xml.Unmarshal([]byte(f.readXML(name)), &xlsx) + if xlsx.MergeCells != nil { + for i := 0; i < len(xlsx.MergeCells.Cells); i++ { + if checkCellInArea(axis, xlsx.MergeCells.Cells[i].Ref) { + axis = strings.Split(xlsx.MergeCells.Cells[i].Ref, ":")[0] + } + } + } if len(value) > 32767 { value = value[0:32767] } - var xlsx xlsxWorksheet col := string(strings.Map(letterOnlyMapF, axis)) row, _ := strconv.Atoi(strings.Map(intOnlyMapF, axis)) xAxis := row - 1 yAxis := titleToNumber(col) - name := "xl/worksheets/" + strings.ToLower(sheet) + ".xml" - xml.Unmarshal([]byte(f.readXML(name)), &xlsx) - rows := xAxis + 1 cell := yAxis + 1 @@ -119,14 +131,20 @@ func (f *File) SetCellStr(sheet string, axis string, value string) { func (f *File) SetCellDefault(sheet string, axis string, value string) { axis = strings.ToUpper(axis) var xlsx xlsxWorksheet + name := "xl/worksheets/" + strings.ToLower(sheet) + ".xml" + xml.Unmarshal([]byte(f.readXML(name)), &xlsx) + if xlsx.MergeCells != nil { + for i := 0; i < len(xlsx.MergeCells.Cells); i++ { + if checkCellInArea(axis, xlsx.MergeCells.Cells[i].Ref) { + axis = strings.Split(xlsx.MergeCells.Cells[i].Ref, ":")[0] + } + } + } col := string(strings.Map(letterOnlyMapF, axis)) row, _ := strconv.Atoi(strings.Map(intOnlyMapF, axis)) xAxis := row - 1 yAxis := titleToNumber(col) - name := "xl/worksheets/" + strings.ToLower(sheet) + ".xml" - xml.Unmarshal([]byte(f.readXML(name)), &xlsx) - rows := xAxis + 1 cell := yAxis + 1 |
