Bugfix: unable to read the value of the merged cell, relate issue #78

formula
Ri Xu 8 years ago
parent 654a676d93
commit 38df838598
No known key found for this signature in database
GPG Key ID: BA5E5BB1C948EDF7

@ -7,7 +7,8 @@ import (
// mergeCellsParser provides function to check merged cells in worksheet by // mergeCellsParser provides function to check merged cells in worksheet by
// given axis. // given axis.
func (f *File) mergeCellsParser(xlsx *xlsxWorksheet, axis string) { func (f *File) mergeCellsParser(xlsx *xlsxWorksheet, axis string) string {
axis = strings.ToUpper(axis)
if xlsx.MergeCells != nil { if xlsx.MergeCells != nil {
for i := 0; i < len(xlsx.MergeCells.Cells); i++ { for i := 0; i < len(xlsx.MergeCells.Cells); i++ {
if checkCellInArea(axis, xlsx.MergeCells.Cells[i].Ref) { if checkCellInArea(axis, xlsx.MergeCells.Cells[i].Ref) {
@ -15,6 +16,7 @@ func (f *File) mergeCellsParser(xlsx *xlsxWorksheet, axis string) {
} }
} }
} }
return axis
} }
// GetCellValue provides function to get formatted value from cell by given // GetCellValue provides function to get formatted value from cell by given
@ -23,8 +25,7 @@ func (f *File) mergeCellsParser(xlsx *xlsxWorksheet, axis string) {
// the raw value of the cell. // the raw value of the cell.
func (f *File) GetCellValue(sheet, axis string) string { func (f *File) GetCellValue(sheet, axis string) string {
xlsx := f.workSheetReader(sheet) xlsx := f.workSheetReader(sheet)
axis = strings.ToUpper(axis) axis = f.mergeCellsParser(xlsx, axis)
f.mergeCellsParser(xlsx, axis)
row, _ := strconv.Atoi(strings.Map(intOnlyMapF, axis)) row, _ := strconv.Atoi(strings.Map(intOnlyMapF, axis))
xAxis := row - 1 xAxis := row - 1
rows := len(xlsx.SheetData.Row) rows := len(xlsx.SheetData.Row)
@ -80,8 +81,7 @@ func (f *File) formattedValue(s int, v string) string {
// index and axis in XLSX file. // index and axis in XLSX file.
func (f *File) GetCellFormula(sheet, axis string) string { func (f *File) GetCellFormula(sheet, axis string) string {
xlsx := f.workSheetReader(sheet) xlsx := f.workSheetReader(sheet)
axis = strings.ToUpper(axis) axis = f.mergeCellsParser(xlsx, axis)
f.mergeCellsParser(xlsx, axis)
row, _ := strconv.Atoi(strings.Map(intOnlyMapF, axis)) row, _ := strconv.Atoi(strings.Map(intOnlyMapF, axis))
xAxis := row - 1 xAxis := row - 1
rows := len(xlsx.SheetData.Row) rows := len(xlsx.SheetData.Row)
@ -114,8 +114,7 @@ func (f *File) GetCellFormula(sheet, axis string) string {
// sheet index. // sheet index.
func (f *File) SetCellFormula(sheet, axis, formula string) { func (f *File) SetCellFormula(sheet, axis, formula string) {
xlsx := f.workSheetReader(sheet) xlsx := f.workSheetReader(sheet)
axis = strings.ToUpper(axis) axis = f.mergeCellsParser(xlsx, axis)
f.mergeCellsParser(xlsx, axis)
col := string(strings.Map(letterOnlyMapF, axis)) col := string(strings.Map(letterOnlyMapF, axis))
row, _ := strconv.Atoi(strings.Map(intOnlyMapF, axis)) row, _ := strconv.Atoi(strings.Map(intOnlyMapF, axis))
xAxis := row - 1 xAxis := row - 1
@ -141,8 +140,7 @@ func (f *File) SetCellFormula(sheet, axis, formula string) {
// and link URL address. Only support external link currently. // and link URL address. Only support external link currently.
func (f *File) SetCellHyperLink(sheet, axis, link string) { func (f *File) SetCellHyperLink(sheet, axis, link string) {
xlsx := f.workSheetReader(sheet) xlsx := f.workSheetReader(sheet)
axis = strings.ToUpper(axis) axis = f.mergeCellsParser(xlsx, axis)
f.mergeCellsParser(xlsx, axis)
rID := f.addSheetRelationships(sheet, SourceRelationshipHyperLink, link, "External") rID := f.addSheetRelationships(sheet, SourceRelationshipHyperLink, link, "External")
hyperlink := xlsxHyperlink{ hyperlink := xlsxHyperlink{
Ref: axis, Ref: axis,

@ -118,8 +118,7 @@ func (f *File) SetCellValue(sheet, axis string, value interface{}) {
// name and cell coordinates. // name and cell coordinates.
func (f *File) GetCellStyle(sheet, axis string) int { func (f *File) GetCellStyle(sheet, axis string) int {
xlsx := f.workSheetReader(sheet) xlsx := f.workSheetReader(sheet)
axis = strings.ToUpper(axis) axis = f.mergeCellsParser(xlsx, axis)
f.mergeCellsParser(xlsx, axis)
col := string(strings.Map(letterOnlyMapF, axis)) col := string(strings.Map(letterOnlyMapF, axis))
row, _ := strconv.Atoi(strings.Map(intOnlyMapF, axis)) row, _ := strconv.Atoi(strings.Map(intOnlyMapF, axis))
xAxis := row - 1 xAxis := row - 1
@ -168,8 +167,7 @@ func (f *File) workSheetReader(sheet string) *xlsxWorksheet {
// worksheet name, cell coordinates and cell value. // worksheet name, cell coordinates and cell value.
func (f *File) SetCellInt(sheet, axis string, value int) { func (f *File) SetCellInt(sheet, axis string, value int) {
xlsx := f.workSheetReader(sheet) xlsx := f.workSheetReader(sheet)
axis = strings.ToUpper(axis) axis = f.mergeCellsParser(xlsx, axis)
f.mergeCellsParser(xlsx, axis)
col := string(strings.Map(letterOnlyMapF, axis)) col := string(strings.Map(letterOnlyMapF, axis))
row, _ := strconv.Atoi(strings.Map(intOnlyMapF, axis)) row, _ := strconv.Atoi(strings.Map(intOnlyMapF, axis))
xAxis := row - 1 xAxis := row - 1
@ -203,8 +201,7 @@ func (f *File) prepareCellStyle(xlsx *xlsxWorksheet, col, style int) int {
// of characters that a cell can contain 32767 characters. // of characters that a cell can contain 32767 characters.
func (f *File) SetCellStr(sheet, axis, value string) { func (f *File) SetCellStr(sheet, axis, value string) {
xlsx := f.workSheetReader(sheet) xlsx := f.workSheetReader(sheet)
axis = strings.ToUpper(axis) axis = f.mergeCellsParser(xlsx, axis)
f.mergeCellsParser(xlsx, axis)
if len(value) > 32767 { if len(value) > 32767 {
value = value[0:32767] value = value[0:32767]
} }
@ -237,8 +234,7 @@ func (f *File) SetCellStr(sheet, axis, value string) {
// default format without escaping the cell. // default format without escaping the cell.
func (f *File) SetCellDefault(sheet, axis, value string) { func (f *File) SetCellDefault(sheet, axis, value string) {
xlsx := f.workSheetReader(sheet) xlsx := f.workSheetReader(sheet)
axis = strings.ToUpper(axis) axis = f.mergeCellsParser(xlsx, axis)
f.mergeCellsParser(xlsx, axis)
col := string(strings.Map(letterOnlyMapF, axis)) col := string(strings.Map(letterOnlyMapF, axis))
row, _ := strconv.Atoi(strings.Map(intOnlyMapF, axis)) row, _ := strconv.Atoi(strings.Map(intOnlyMapF, axis))
xAxis := row - 1 xAxis := row - 1

Loading…
Cancel
Save