Office Script to add image
Hi! I am using the following code to add image into excel sheet automatically. However, it only works for JPG file and not for JPEG and PNG file. May I modify the following code and let it works for 3 types of image files? Thank you very much.
function main(workbook: ExcelScript.Workbook, base64ImageString: string,imageName: string) {
// get table row count
let sheet1 = workbook.getWorksheet(‘In progress’);
let table1 = workbook.getTable(‘Inprogress’);
let rowCount = table1.getRowCount();
let n1:number = rowCount + 1;
let range1:string = ”;
let imageAddress:string = ”;
let nameAddress:string = ”;
imageAddress = ‘J’ + n1.toString();
nameAddress = ‘N’ + n1.toString();
range1 = n1 + ‘:’ + n1
sheet1.getRange(range1).getFormat().setRowHeight(230);
let range = sheet1.getRange(imageAddress);
let image = sheet1.addImage(base64ImageString);
image.setName(imageName);
image.setTop(range.getTop());
image.setLeft(range.getLeft());
image.setWidth(300);
image.setHeight(225);
sheet1.getRange(nameAddress).setValue(imageName)
}
Hi! I am using the following code to add image into excel sheet automatically. However, it only works for JPG file and not for JPEG and PNG file. May I modify the following code and let it works for 3 types of image files? Thank you very much. function main(workbook: ExcelScript.Workbook, base64ImageString: string,imageName: string) {
// get table row count
let sheet1 = workbook.getWorksheet(‘In progress’);
let table1 = workbook.getTable(‘Inprogress’);
let rowCount = table1.getRowCount();
let n1:number = rowCount + 1;
let range1:string = ”;
let imageAddress:string = ”;
let nameAddress:string = ”;
imageAddress = ‘J’ + n1.toString();
nameAddress = ‘N’ + n1.toString();
range1 = n1 + ‘:’ + n1
sheet1.getRange(range1).getFormat().setRowHeight(230);
let range = sheet1.getRange(imageAddress);
let image = sheet1.addImage(base64ImageString);
image.setName(imageName);
image.setTop(range.getTop());
image.setLeft(range.getLeft());
image.setWidth(300);
image.setHeight(225);
sheet1.getRange(nameAddress).setValue(imageName)
} Read More