Forum Discussion

teespolyglot's avatar
teespolyglot
Copper Contributor
Sep 05, 2024

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...
  • teespolyglot's avatar
    teespolyglot
    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);
    }

     

     

    MichelleRanMSFT SergeiBaklan

    Thank you both for taking the time to respond! 🙂

Resources