|
|
@@ -342,14 +342,14 @@ func formulaForCell(rawcell xlsxC, sharedFormulas map[int]sharedFormula) string
|
|
|
var start, end int
|
|
|
for end = 0; end < len(orig); end++ {
|
|
|
c := orig[end]
|
|
|
- if c >= 'A' && c <= 'Z' {
|
|
|
+ if c >= 'A' && c <= 'Z' || c == '$' {
|
|
|
res += string(orig[start:end])
|
|
|
start = end
|
|
|
end++
|
|
|
foundNum := false
|
|
|
for ; end < len(orig); end++ {
|
|
|
idc := orig[end]
|
|
|
- if idc >= '0' && idc <= '9' {
|
|
|
+ if idc >= '0' && idc <= '9' || idc == '$' {
|
|
|
foundNum = true
|
|
|
} else if idc >= 'A' && idc <= 'Z' {
|
|
|
if foundNum {
|
|
|
@@ -360,10 +360,8 @@ func formulaForCell(rawcell xlsxC, sharedFormulas map[int]sharedFormula) string
|
|
|
}
|
|
|
}
|
|
|
if foundNum {
|
|
|
- fx, fy, _ := getCoordsFromCellIDString(string(orig[start:end]))
|
|
|
- fx += dx
|
|
|
- fy += dy
|
|
|
- res += getCellIDStringFromCoords(fx, fy)
|
|
|
+ cellID := string(orig[start:end])
|
|
|
+ res += shiftCell(cellID, dx, dy)
|
|
|
start = end
|
|
|
}
|
|
|
}
|
|
|
@@ -379,6 +377,55 @@ func formulaForCell(rawcell xlsxC, sharedFormulas map[int]sharedFormula) string
|
|
|
return strings.Trim(res, " \t\n\r")
|
|
|
}
|
|
|
|
|
|
+// shiftCell returns the cell shifted according to dx and dy taking into consideration of absolute
|
|
|
+// references with dollar sign ($)
|
|
|
+func shiftCell(cellID string, dx, dy int) string {
|
|
|
+ fx, fy, _ := getCoordsFromCellIDString(cellID)
|
|
|
+
|
|
|
+ // Is fixed column?
|
|
|
+ fixedCol := strings.Index(cellID, "$") == 0
|
|
|
+
|
|
|
+ // Is fixed row?
|
|
|
+ fixedRow := strings.LastIndex(cellID, "$") > 0
|
|
|
+
|
|
|
+ if !fixedCol {
|
|
|
+ // Shift column
|
|
|
+ fx += dx
|
|
|
+ }
|
|
|
+
|
|
|
+ if !fixedRow {
|
|
|
+ // Shift row
|
|
|
+ fy += dy
|
|
|
+ }
|
|
|
+
|
|
|
+ // New shifted cell
|
|
|
+ shiftedCellID := getCellIDStringFromCoords(fx, fy)
|
|
|
+
|
|
|
+ if !fixedCol && !fixedRow {
|
|
|
+ return shiftedCellID
|
|
|
+ }
|
|
|
+
|
|
|
+ // There are absolute references, need to put the $ back into the formula.
|
|
|
+ letterPart := strings.Map(letterOnlyMapF, shiftedCellID)
|
|
|
+ numberPart := strings.Map(intOnlyMapF, shiftedCellID)
|
|
|
+
|
|
|
+ result := ""
|
|
|
+
|
|
|
+ if fixedCol {
|
|
|
+ result += "$"
|
|
|
+ }
|
|
|
+
|
|
|
+ result += letterPart
|
|
|
+
|
|
|
+ if fixedRow {
|
|
|
+ result += "$"
|
|
|
+ }
|
|
|
+
|
|
|
+ result += numberPart
|
|
|
+
|
|
|
+ return result
|
|
|
+}
|
|
|
+
|
|
|
// fillCellData attempts to extract a valid value, usable in
|
|
|
// CSV form from the raw cell value. Note - this is not actually
|
|
|
// general enough - we should support retaining tabs and newlines.
|