This answer explains how to do this in Word: fooobar.com/questions/1646582 / ... , and similarly I was able to do it like this: Excel:
insertImageBase64New() {
Excel.run(async (ctx) => {
let sheet = ctx.workbook.worksheets.getItem("Sheet1");
let address = "C3";
let range = sheet.getRange(address);
range.select();
await ctx.sync();
Office.context.document.setSelectedDataAsync(this.getBase64(), {
coercionType: Office.CoercionType.Image,
imageLeft: 0,
imageTop: 0,
imageWidth: 300,
imageHeight: 100
}, function(asyncResult) {
if (asyncResult.status === Office.AsyncResultStatus.Failed) {
console.log("Action failed with error: " + asyncResult.error.message);
}
});
});
}
getBase64() {
return "return "iVBORw0KGgoAAAANSUhEU..."; //put your base64 encoded image here
}
Documentation link: https://dev.office.com/reference/add-ins/excel/rangefill
I used a random site to encode the image: https://www.browserling.com/tools/image-to-base64
source
share