adjustRange adjust range, for example: adjust Sheet1!$E$31:$A$1 to Sheet1!$A$1:$E$31
(rangeStr string)
| 229 | |
| 230 | // adjustRange adjust range, for example: adjust Sheet1!$E$31:$A$1 to Sheet1!$A$1:$E$31 |
| 231 | func (f *File) adjustRange(rangeStr string) (string, []int, error) { |
| 232 | if len(rangeStr) < 1 { |
| 233 | return "", []int{}, ErrParameterRequired |
| 234 | } |
| 235 | rng := strings.Split(rangeStr, "!") |
| 236 | if len(rng) != 2 { |
| 237 | return "", []int{}, ErrParameterInvalid |
| 238 | } |
| 239 | trimRng := strings.ReplaceAll(rng[1], "$", "") |
| 240 | coordinates, err := rangeRefToCoordinates(trimRng) |
| 241 | if err != nil { |
| 242 | return rng[0], []int{}, err |
| 243 | } |
| 244 | x1, y1, x2, y2 := coordinates[0], coordinates[1], coordinates[2], coordinates[3] |
| 245 | if x1 == x2 && y1 == y2 { |
| 246 | return rng[0], []int{}, ErrParameterInvalid |
| 247 | } |
| 248 | |
| 249 | // Correct the range, such correct C1:B3 to B1:C3. |
| 250 | if x2 < x1 { |
| 251 | x1, x2 = x2, x1 |
| 252 | } |
| 253 | |
| 254 | if y2 < y1 { |
| 255 | y1, y2 = y2, y1 |
| 256 | } |
| 257 | return rng[0], []int{x1, y1, x2, y2}, nil |
| 258 | } |
| 259 | |
| 260 | // getTableFieldsOrder provides a function to get order list of pivot table |
| 261 | // fields. |