Fix Excel Office Scripts Error for Doughnut Chart Data Labels
Question details
The user needs to fix an error encountered when setting the data label position for a doughnut chart using Office Scripts.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Automating chart formatting and data label positioning using the Office Scripts API in Excel.
- Observed behavior
- Executing chart.getDataLabels().setPosition() returns the error "This operation is not permitted for the current object" because the requested position is unsupported for doughnut charts.
Ensure you have saved your workbook and verify the exact chart type you are targeting, as different chart types support different data label parameters in the Office Scripts API.
Use Supported Label Positions or Format Manually
Modify your script to use a universally supported data label position, or bypass the API limitation by formatting the chart manually.
Doughnut charts have specific structural limitations in Excel. Certain data label positions, such as 'Callout' or 'OutsideEnd', may not be supported through the current Office Scripts API.
To resolve the "operation is not permitted" error, you must request a supported ChartDataLabelPosition or apply the desired formatting manually.
Open the Code Editor in Excel and find the line containing chart.getDataLabels().setPosition() in your Office Script.
Update the requested position parameter to a standard option that is supported for doughnut charts, such as 'Center' or 'BestFit'.
Execute the script again to confirm that the "operation is not permitted" error is resolved and the labels update successfully.
If your project strictly requires callouts that the API rejects, click on the doughnut chart in Excel, click the '+' Chart Elements icon, select 'Data Labels', and format them manually via the Format Data Labels pane.

Consult Microsoft Q&A for API Guidance
Seek direct assistance and check for API updates from Microsoft engineers and the developer community.
Try WPS Office for Seamless Chart Formatting
If complex scripting errors and API limitations in Microsoft Excel are slowing down your workflow, WPS Office offers a highly compatible, user-friendly alternative. Enjoy intuitive built-in chart formatting without the steep learning curve of automation scripts.
- 1. Open your data in WPS Spreadsheets: Launch WPS Office and open your existing Excel workbook containing the chart data.
- 2. Insert a Doughnut Chart: Select your data range, navigate to the Insert tab, click the Chart icon, and choose the Doughnut Chart layout.
- 3. Customize Data Labels intuitively: Right-click the chart and select 'Add Data Labels'. Use the straightforward formatting pane to easily position them as callouts or centers without writing a single line of code.

Frequently Asked Questions
Why does Excel throw an error when I set doughnut chart data labels via Office Scripts?
This happens because the specific label position you are trying to apply (like 'Callout') is not supported for doughnut charts through the Office Scripts API. Calling an unsupported configuration triggers the "operation is not permitted" error.
Can I use VBA instead of Office Scripts to set data label positions?
Yes. VBA utilizes a different, older object model that sometimes offers more flexibility than the newer Office Scripts API. You can experiment with the DataLabels.Position property in a VBA macro to see if it allows your desired layout.
Which data label positions are universally supported for doughnut charts in Excel?
Generally, simple positions like 'Center' or 'BestFit' are supported. Complex positions like 'OutsideEnd' or detailed data callouts are often restricted on doughnut and pie charts depending on the exact API version.




