Forum Discussion
Script to convert base64 to image in Excel not working
- Sep 10, 2024
Thanks SergeiBaklan, your reply essentially pointed me in the right direction. Power Automate clearly didn't like me passing in the base64 string directly from the PowerApps input, so I've initialised a string variable and hardcoded it in a cell in a hidden sheet in an earlier step.
I've then modified my script to create a string variable, using getRange.getText() and then I'm passing that variable into the addImage() function
function main(workbook: ExcelScript.Workbook, base64ImageString1: string, base64ImageString2: string) { const sheet = workbook.getWorksheet("Output"); const sheetB = workbook.getWorksheet("Responses"); const base641 = sheetB.getRange("G2").getText(); const base642 = sheetB.getRange("I2").getText(); const range1 = sheet.getRange("C43"); const range2 = sheet.getRange("G43"); let image1 = sheet.addImage(base641); image1.setTop(range1.getTop()); image1.setLeft(range1.getLeft()); image1.setWidth(range1.getWidth()); image1.setHeight(range1.getHeight()); image1.setPlacement(ExcelScript.Placement.twoCell); let image2 = sheet.addImage(base642); image2.setTop(range2.getTop()); image2.setLeft(range2.getLeft()); image2.setWidth(range2.getWidth()); image2.setHeight(range2.getHeight()); image2.setPlacement(ExcelScript.Placement.twoCell); }
Thank you both for taking the time to respond! 🙂
Hi teespolyglot, - sorry to hear you're running into this issue! I tested the script Sergei shared with the hardcoded base64 image, which worked fine when run through a flow, so I'm wondering if there may be an issue with how the image is being passed into the script. Would you be able to share the inputs of the "Run Script" action that failed, as well as the request id? That should help us troubleshoot further.