Problem Debugging Microsoft Script in Excel

beaverbuzz

New Member
Joined
Aug 15, 2022
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Good morning,

I wrote a thread a few days ago about my issue of automating the embedding an image in a cell in Excel.

I found a solution through using web Excel and automation of a workbook through Microsoft script (not VBA...).

The solution included a script which I tweaked for my purpose.

Please find attached a screenshot of the problem I am encountering with it.

Also please find below the entirety of the script.

Any suggestions/help to reconcile that problem would be appreciated!

beaverbuzz
Excel Formula:
async function main(workbook: ExcelScript.Workbook) {

// Fetch the image from a URL.



const sheet = workbook.getWorksheet("Form1");



const response = await fetch(sheet.getRange("I7"));



// Store the response as an ArrayBuffer, since it is a raw image file.

const data = await response.arrayBuffer();



// Convert the image data into a base64-encoded string.

const image = convertToBase64(data);



// Add the image to a worksheet.

workbook.getWorksheet("WebSheet").addImage(image);

}



/**

* Converts an ArrayBuffer containing a .png image into a base64-encoded string.

*/

function convertToBase64(input: ArrayBuffer) {

const uInt8Array = new Uint8Array(input);

const count = uInt8Array.length;



// Allocate the necessary space up front.

const charCodeArray = new Array(count) as string[];



// Convert every entry in the array to a character.

for (let i = count; i >= 0; i--) {

charCodeArray[i] = String.fromCharCode(uInt8Array[i]);

}



// Convert the characters to base64.

const base64 = btoa(charCodeArray.join(''));

return base64;

}
 

Attachments

  • Microsoft Script Problem.png
    Microsoft Script Problem.png
    185.8 KB · Views: 12

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Bumping this thread. I hope someone can help. I'll try a different forum if not...
 
Upvote 0
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Problem Debugging Microsoft Office Script in Excel
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0

Forum statistics

Threads
1,215,012
Messages
6,122,682
Members
449,091
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top