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! 🙂
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! 🙂
teespolyglot , you are welcome and thank you for the update. Not sure why it's not possible to take signature code directly from Power App, but I had no practical experience with such kind of tasks.
Anyway, at least workaround works.