{"record":{"id":"c72b99a9c30ce0b6","repo":"qax-os/excelize","slug":"parameter-datarange-parsing-error-s","errorCode":null,"errorMessage":"parameter 'DataRange' parsing error: %s","messagePattern":"parameter 'DataRange' parsing error: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"errors.go","lineNumber":363,"sourceCode":"\treturn fmt.Errorf(\"sheet %s is not a worksheet\", name)\n}\n\n// newPivotTableColFieldsError defined the error message on same data field\n// appears both in the pivot table column fields and filter fields.\nfunc newPivotTableColFieldsError(data []string) error {\n\treturn fmt.Errorf(\"data fields %s appear both in the pivot table column fields and filter fields\", strings.Join(data, \", \"))\n}\n\n// newPivotTableRowFieldsError defined the error message on same data field\n// appears both in the pivot table row fields and filter fields.\nfunc newPivotTableRowFieldsError(data []string) error {\n\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)","sourceCodeStart":345,"sourceCodeEnd":381,"githubUrl":"https://github.com/qax-os/excelize/blob/f2483381fbfbe432a6baa98d48a1c277183f3285/errors.go#L345-L381","documentation":"Returned by newPivotTableDataRangeError when the Options.DataRange of a pivot table cannot be parsed into a valid range reference, wrapping the underlying parse message. The pivot cache and layout computation depend on a well-formed rectangular range, so parsing is validated up front in parseFormatPivotTableSet, addPivotCache, getTableFieldsOrder, and getPivotTableDataRange.","triggerScenarios":"Passing Options{DataRange: ...} with a malformed reference (empty string, wrong sheet qualifier, reversed rows/cols, single-cell or non-contiguous range, invalid format like 'Sheet1!A1:B' or 'NotARange') to AddPivotTable or related pivot helpers.","commonSituations":"Building the range string with fmt.Sprintf and getting coordinates wrong; using coordinates from another sheet without the sheet-name prefix (or with an unquoted sheet name containing spaces); data range deleted/moved after the pivot options were captured.","solutions":["Fix the DataRange string to a valid contiguous range, e.g. \"Sheet1!A1:E10\" (quote sheet names with spaces: \"'My Sheet'!A1:E10\")","Use f.CellsCoordinates or CoordinatesToRangeName-style helpers to build the reference instead of hand-concatenating","Ensure the range spans at least a header row plus one data row and exists on a worksheet","Read the wrapped %s message for the exact parsing failure"],"exampleFix":"// before\nopts := &excelize.Options{DataRange: \"A1:B\"} // invalid\n// after\nopts := &excelize.Options{DataRange: \"Sheet1!A1:E10\"}","handlingStrategy":"validation","validationCode":"func validateDataRange(f *excelize.File, ref string) error {\n    parts := strings.SplitN(ref, \"!\", 2)\n    if len(parts) != 2 || parts[0] == \"\" || parts[1] == \"\" {\n        return fmt.Errorf(\"DataRange must be like Sheet1!A1:E10, got %q\", ref)\n    }\n    coords, err := f.CellsCoordinates(parts[1])\n    if err != nil {\n        return err\n    }\n    _ = coords\n    return nil\n}","typeGuard":"null","tryCatchPattern":"if err := f.AddPivotTable(opts.DataRange, opts.PivotTableRange, opts); err != nil {\n    if strings.Contains(err.Error(), \"'DataRange' parsing error\") {\n        return fmt.Errorf(\"check DataRange %q: %w\", opts.DataRange, err)\n    }\n    return err\n}","preventionTips":["Build range strings with helper functions rather than string concatenation","Quote sheet names containing spaces: 'My Sheet'!A1:E10","Ensure the range covers a header row and exists on a worksheet at call time","Read the wrapped message for the exact parse failure"],"tags":["go","excelize","pivot-table","range-reference"],"backgroundTag":"invalid-range-reference","analyzedSha":"f2483381fbfbe432a6baa98d48a1c277183f3285","analyzedAt":"2026-09-02T01:26:19.299Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}