Power Automate: Office Script in Excel doesn't Chart as Image

Stadelmann Lukas 1 Reputation point
2022-11-10T16:08:08.533+00:00

In Power Automate I trigger an office script in Excel, that updates a bubble chart.
This Chart should then be returned to the automate flow and populates a Word.

The Script seems to work properly, as it does return data, but the Word document refuses the data with the error code:

The image is not of type PNG or JPG. Please provide an image of type PNG or JPG.

function main(workbook: ExcelScript.Workbook) {  
	let selectedSheet = workbook.getActiveWorksheet();  
  
	// Set range D2:H3 on selectedSheet  
	selectedSheet.getRange("D2:H3").setFormulasLocal([["=WENN(C2=1;C2;-2)","=WENN(UND(C2<1;C2>0,85);C2;-2)","=WENN(UND(C2<0,9;C2>0,75);C2;-2)","=WENN(C2>0,8;C2;-2)","1"],[null,null,"",null,"2"]]);  
	// Set range H4 on selectedSheet  
	selectedSheet.getRange("H4").setValue("3");  
	// Auto fill range  
	selectedSheet.getRange("H2:H4").autoFill();  
	// Set range G2 on selectedSheet  
	selectedSheet.getRange("G2").setFormulaLocal("=WENN(C2<0,8;C2;-2)");  
  
	var waitUntil = new Date().getTime() + 2000;  
	while (new Date().getTime() < waitUntil) { };  
  
	let diagramm_1 = selectedSheet.getChart("Diagramm 1");  
	let Pointimage = diagramm_1.getImage();  
	  
	selectedSheet.getRange("A33").setValue(diagramm_1.getChartType());  
	return {Pointimage};  
}  

In Power Automate, the image is extracted as follows:

{  
  "$content_type": "image/png",  
  "$content": @{outputs('Skript_ausführen')?['body/result']?['Pointimage']}  
}  
Not Monitored
Not Monitored
Tag not monitored by Microsoft.
35,946 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Geoff Ren 1 Reputation point Microsoft Employee
    2022-11-23T19:09:20.407+00:00

    From the documentation of the chart.getImage() function: Renders the chart as a base64-encoded image. So you need to pass it in a different format. Can you try the solution posted here and see if that works?

    I would also recommend testing by logging out the image string and using that directly. Just so you can isolate the area that you are trying to test better.

    0 comments No comments

  2. Dave Patrick 426.1K Reputation points MVP
    2022-11-23T19:17:13.737+00:00

    Power automate is not currently supported here on Q&A. The product group for Power automate actively monitors questions in dedicated forums here.
    https://powerusers.microsoft.com/t5/Microsoft-Power-Automate/ct-p/MPACommunity

    --please don't forget to upvote and Accept as answer if the reply is helpful--

    0 comments No comments