When I run the sample code from ScriptLab on InsertImage:
async function insertImage() {
// This function inserts a web image into the currently selected cell.
await Excel.run(async (context) => {
// Retrieve image data from the task pane and then clear the input fields.
const imageUrl = $("#url").val() as string;
const imageAltText = $("#alt-text").val() as string;
clearForm();
// Load the active cell.
const activeCell = context.workbook.getActiveCell();
activeCell.load();
await context.sync();
if (!imageUrl) {
console.log("Please enter an image URL.");
return;
}
// Create a web image object and assign the image details.
const webImage: Excel.WebImageCellValue = {
type: "WebImage" /* The string equivalent of `Excel.CellValueType.webImage`. */,
address: imageUrl,
altText: imageAltText
};
// Insert web image into the active cell.
activeCell.valuesAsJson = [[webImage]];
await context.sync();
});
}
I get an error revolving around valueAsJson. I am able to load the image directly with window.open(UrlAddress, "_blank"); so there is nothing wrong with the URL.
code: "GeneralException"
message: "There was an internal error while processing the request."
toString: function toString()
errorLocation: "Range.valuesAsJson"
What am I doing wrong?