{"record":{"id":"8971c36223d01d1c","repo":"qax-os/excelize","slug":"parameter-pivottablerange-parsing-error-s","errorCode":null,"errorMessage":"parameter 'PivotTableRange' parsing error: %s","messagePattern":"parameter 'PivotTableRange' parsing error: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"errors.go","lineNumber":375,"sourceCode":"\treturn fmt.Errorf(\"data fields %s appear both in the pivot table row fields and filter fields\", strings.Join(data, \", \"))\n}\n\n// newPivotTableDataRangeError defined the error message on receiving the\n// invalid pivot table data range.\nfunc newPivotTableDataRangeError(msg string) error {\n\treturn fmt.Errorf(\"parameter 'DataRange' parsing error: %s\", msg)\n}\n\n// newPivotTableSelectedItemError defined the error message on receiving the\n// invalid pivot table selected item.\nfunc newPivotTableSelectedItemError(item, field string) error {\n\treturn fmt.Errorf(\"selected item %s does not exist in pivot table field %s\", item, field)\n}\n\n// newPivotTableRangeError defined the error message on receiving the invalid\n// pivot table range.\nfunc newPivotTableRangeError(msg string) error {\n\treturn fmt.Errorf(\"parameter 'PivotTableRange' parsing error: %s\", msg)\n}\n\n// newPivotTableShowValuesAsBaseFieldError defined the error message on receiving\n// the invalid pivot table \"show values as\" base field.\nfunc newPivotTableShowValuesAsBaseFieldError(field string) error {\n\treturn fmt.Errorf(\"base field %s does not exist in shared items\", field)\n}\n\n// newStreamSetRowError defined the error message on the stream writer\n// receiving the non-ascending row number.\nfunc newStreamSetRowError(row int) error {\n\treturn fmt.Errorf(\"row %d has already been written\", row)\n}\n\n// newStreamSetRowOrderError defined the error message on calling the SetRow\n// function before the order function.\nfunc newStreamSetRowOrderError(name string) error {\n\treturn fmt.Errorf(\"must call the %s function before the SetRow function\", name)","sourceCodeStart":357,"sourceCodeEnd":393,"githubUrl":"https://github.com/qax-os/excelize/blob/f2483381fbfbe432a6baa98d48a1c277183f3285/errors.go#L357-L393","documentation":"Excelize throws this when the PivotTableRange parameter passed to AddPivotTable cannot be parsed as a valid range reference. The range string is converted via NamespaceStrictName/CoordsToCellName-like parsing, and any malformed reference (bad sheet name quoting, reversed columns, or a multi-area/'non-rectangle' reference) fails. The underlying parse message is wrapped into the %s slot.","triggerScenarios":"Calling f.AddPivotTable(&PivotTableOptions{...}) or parseFormatPivotTableSet with DataRange, PivotTableRange, or FilterRange strings that fail range parsing, e.g. 'Sheet1:A1:D10' (missing !), 'Sheet1!D1:A10' non-topleft ordering, or a whole-column/open range.","commonSituations":"Hand-building PivotTableOptions with copy-pasted range strings; swapping the range corners; forgetting the sheet-qualified form 'Sheet1!A1:D10'; programmatic range built from wrong row/col variables (zero or negative coordinates).","solutions":["Use the fully-qualified 'SheetName!TopLeft:BottomRight' form with top-left cell first, e.g. 'Sheet1!A1:E10'.","Validate the range by calling f.GetSheetName / excelize.CoordinatesToCellName on your corner cells before passing it in.","Quote sheet names that contain spaces or special characters as 'My Sheet'!A1:D10.","Confirm DataRange and PivotTableRange overlap the same worksheet and are rectangular ranges, not multiple ranges or named ranges."],"exampleFix":"// before\nf.AddPivotTable(&excelize.PivotTableOptions{\n    DataRange:       \"A1:E10\",\n    PivotTableRange: \"Sheet1!D10:A1\",\n})\n// after\nf.AddPivotTable(&excelize.PivotTableOptions{\n    DataRange:       \"Sheet1!A1:E10\",\n    PivotTableRange: \"Sheet1!G2:D10\",\n})","handlingStrategy":"validation","validationCode":"func validRange(rng string) bool {\n    parts := strings.SplitN(rng, \"!\", 2)\n    if len(parts) != 2 || parts[0] == \"\" {\n        return false\n    }\n    corners := strings.Split(parts[1], \":\")\n    if len(corners) != 2 {\n        return false\n    }\n    for _, c := range corners {\n        if _, _, err := excelize.CellNameToCoordinates(c); err != nil {\n            return false\n        }\n    }\n    return true\n}\n// call before: if !validRange(opts.PivotTableRange) { return fmt.Errorf(\"bad PivotTableRange %q\", opts.PivotTableRange) }","typeGuard":null,"tryCatchPattern":"err := f.AddPivotTable(opts)\nif err != nil {\n    if strings.Contains(err.Error(), \"parameter 'PivotTableRange' parsing error\") {\n        log.Printf(\"invalid pivot range %q: %v\", opts.PivotTableRange, err)\n        return\n    }\n    return err\n}","preventionTips":["Always build ranges as \"Sheet!TopLeft:BottomRight\" with top-left first","Validate range strings with excelize.CellNameToCoordinates before use","Quote sheet names containing spaces","Keep range-building in one helper function instead of scattered string concatenation"],"tags":["go","excelize","pivot-table","range-parsing"],"backgroundTag":"invalid-range-reference","analyzedSha":"f2483381fbfbe432a6baa98d48a1c277183f3285","analyzedAt":"2026-09-02T01:26:19.299Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}