Fix Power Automate Errors Exporting Multiple Excel Charts via Office Scripts
Question details
The user needs to export multiple Excel charts as images to a Word template using Office Scripts and Power Automate, but encounters execution errors when attempting to process a second chart.

- Product
- Microsoft Excel, Power Automate
- Device & OS
- not provided
- Scenario
- Automating document generation by extracting multiple chart images from an Excel workbook and inserting them into a Word template via Power Automate.
- Observed behavior
- The automation successfully exports the first chart image, but returning and processing a second chart within the same script causes workflow errors.
Ensure that your Office Script is saved in Excel on the web and that your Power Automate flow has the appropriate permissions to read from the target Excel workbook.
Use an Array to Return Multiple Chart Images
Consolidate the exported chart images into a single array within your Office Script so Power Automate can process them sequentially.
Office Scripts can only return a single final output object to Power Automate. If you attempt to return multiple standalone image variables, the flow will fail to parse the output correctly. Storing the base64 image strings in a single JavaScript array solves this issue.
Open Excel on the web, navigate to the 'Automate' tab, and open the Code Editor for your existing Office Script.
Modify your script to store the images in an array. For example: `function main(workbook: ExcelScript.Workbook) { const sheet = workbook.getWorksheet("Sheet1"); const charts = sheet.getCharts(); return [charts[0].getImage(), charts[1].getImage()]; }`
In your Power Automate flow, update the subsequent actions to expect an array instead of a single string. Pass the returned array into an 'Apply to each' loop.
Inside the 'Apply to each' loop, add your 'Populate a Microsoft Word template' action to handle each image dynamically based on the current item in the iteration.

Looking for a Free, Lightweight Alternative to Microsoft Excel?
If you are managing complex datasets, reports, and charts but prefer a highly compatible and cost-effective solution, WPS Office provides robust spreadsheet capabilities without the heavy subscription fees.
- 1. Download WPS Office: Install WPS Office for free from the official website and launch WPS Spreadsheet.
- 2. Open Your Workbooks: Open your existing .xlsx files directly; all your original charts, data, and formatting remain intact.
- 3. Export and Share Easily: Use the built-in 'Export to Picture' or 'Export to PDF' features to quickly share your charts without needing complex external automation flows.

Frequently Asked Questions
Why does Power Automate fail when I return multiple single chart images?
Office Scripts are designed to return one primary output object. Attempting to return multiple independent output definitions conflicts with the schema Power Automate expects. Grouping them into a single array ensures the flow receives a valid, single JSON array object.
How do I handle a variable number of charts in the Office Script?
Instead of hardcoding indices (like charts[0] and charts[1]), you can use a loop or the .map() method in your script to iterate over the entire array returned by sheet.getCharts() and dynamically extract all available images.
Why are my extracted Excel charts returning as blank images?
This can happen if the script executes before dynamic data connections have refreshed or finished rendering the chart. Adding a brief delay in your flow or ensuring data connections are fully resolved before running the script usually resolves this.
Can I export these chart images to a PDF instead of a Word document?
Yes. Once you pass the array of base64 images to Power Automate, you can use HTML to Word or directly use HTML to PDF conversion connectors to generate a PDF containing all the charts.




