|
|
@@ -312,65 +312,65 @@ func makeEmptyRow() *Row {
|
|
|
}
|
|
|
|
|
|
type sharedFormula struct {
|
|
|
- x, y int
|
|
|
- formula string
|
|
|
+ x, y int
|
|
|
+ formula string
|
|
|
}
|
|
|
|
|
|
func formulaForCell(rawcell xlsxC, sharedFormulas map[int]sharedFormula) string {
|
|
|
- var res string
|
|
|
-
|
|
|
- f := rawcell.F
|
|
|
- if f.T == "shared" {
|
|
|
- x, y, err := getCoordsFromCellIDString(rawcell.R)
|
|
|
- if err != nil {
|
|
|
- res = f.Content
|
|
|
- } else {
|
|
|
- if f.Ref != "" {
|
|
|
- res = f.Content
|
|
|
- sharedFormulas[f.Si] = sharedFormula{x, y, res}
|
|
|
- } else {
|
|
|
- sharedFormula := sharedFormulas[f.Si]
|
|
|
- dx := x - sharedFormula.x
|
|
|
- dy := y - sharedFormula.y
|
|
|
- orig := []byte(sharedFormula.formula)
|
|
|
- var start, end int
|
|
|
- for end = 0; end < len(orig); end++ {
|
|
|
- c := orig[end]
|
|
|
- if c >= 'A' && c <= 'Z' {
|
|
|
- res += string(orig[start:end])
|
|
|
- start = end
|
|
|
- end++
|
|
|
- foundNum := false
|
|
|
- for ; end < len(orig); end++ {
|
|
|
- idc := orig[end]
|
|
|
- if idc >= '0' && idc <= '9' {
|
|
|
- foundNum = true
|
|
|
- } else if idc >= 'A' && idc <= 'Z' {
|
|
|
- if foundNum {
|
|
|
- break
|
|
|
- }
|
|
|
- } else {
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- if foundNum {
|
|
|
- fx, fy, _ := getCoordsFromCellIDString(string(orig[start:end]))
|
|
|
- fx += dx
|
|
|
- fy += dy
|
|
|
- res += getCellIDStringFromCoords(fx, fy)
|
|
|
- start = end
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if start < len(orig) {
|
|
|
- res += string(orig[start:end])
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- res = f.Content
|
|
|
- }
|
|
|
- return strings.Trim(res, " \t\n\r")
|
|
|
+ var res string
|
|
|
+
|
|
|
+ f := rawcell.F
|
|
|
+ if f.T == "shared" {
|
|
|
+ x, y, err := getCoordsFromCellIDString(rawcell.R)
|
|
|
+ if err != nil {
|
|
|
+ res = f.Content
|
|
|
+ } else {
|
|
|
+ if f.Ref != "" {
|
|
|
+ res = f.Content
|
|
|
+ sharedFormulas[f.Si] = sharedFormula{x, y, res}
|
|
|
+ } else {
|
|
|
+ sharedFormula := sharedFormulas[f.Si]
|
|
|
+ dx := x - sharedFormula.x
|
|
|
+ dy := y - sharedFormula.y
|
|
|
+ orig := []byte(sharedFormula.formula)
|
|
|
+ var start, end int
|
|
|
+ for end = 0; end < len(orig); end++ {
|
|
|
+ c := orig[end]
|
|
|
+ if c >= 'A' && c <= 'Z' {
|
|
|
+ res += string(orig[start:end])
|
|
|
+ start = end
|
|
|
+ end++
|
|
|
+ foundNum := false
|
|
|
+ for ; end < len(orig); end++ {
|
|
|
+ idc := orig[end]
|
|
|
+ if idc >= '0' && idc <= '9' {
|
|
|
+ foundNum = true
|
|
|
+ } else if idc >= 'A' && idc <= 'Z' {
|
|
|
+ if foundNum {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if foundNum {
|
|
|
+ fx, fy, _ := getCoordsFromCellIDString(string(orig[start:end]))
|
|
|
+ fx += dx
|
|
|
+ fy += dy
|
|
|
+ res += getCellIDStringFromCoords(fx, fy)
|
|
|
+ start = end
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if start < len(orig) {
|
|
|
+ res += string(orig[start:end])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ res = f.Content
|
|
|
+ }
|
|
|
+ return strings.Trim(res, " \t\n\r")
|
|
|
}
|
|
|
|
|
|
// fillCellData attempts to extract a valid value, usable in
|