Forum Discussion
teespolyglot
Sep 05, 2024Copper Contributor
Script to convert base64 to image in Excel not working
This is a cross post from the Power Platform Community, as i'm not sure where is best to ask my question. I have developed a mobile power app for my engineers to complete treatment reports in the...
- 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! 🙂
peiyezhu
Sep 06, 2024Bronze Contributor
If all work flow through app on web,it may be not easy to accomplish your goal with low code tool like power automate.
- teespolyglotSep 06, 2024Copper Contributor
Many thanks for your response. Can you please explain to me why you think this is the case?
I have searched through the documentation to find an explanation, but nothing in the various limitations documents suggests that this shouldn't be possible?
The flow was previously writing the base64 as a string to the relevant cell(s) in Excel without issue. It's only when I tried to introduce the script to convert the base64 to images that I've encountered problems.
It therefore seems logical that either
- there is a problem with my script, or
- there is an uncatalogued issue with the addImage(base64string) function + Run Script connector in Power Automate
In your response, you said it's not achievable with a low-code solution. What would be your suggestion on how it could be achieved otherwise?
Again, my thanks for taking the time to respond! 😊
- peiyezhuSep 11, 2024Bronze Contributor
https://www.geeksforgeeks.org/how-to-display-base64-images-in-html/
It is easy to display an image in a html by img tag.
On the other hand, you can write to Excel with script and dispay the picture,it may run slowly.