Fix height of image in current sheet
function main(workbook: ExcelScript.Workbook) {
workbook.getActiveWorksheet().getShapes()
.forEach(shape => {
// Check if the shape is an image
if (shape.getType() === ExcelScript.ShapeType.image) {
const height = shape.getHeight();
if (height < 400) {
shape.scaleHeight(
400 / height,
ExcelScript.ShapeScaleType.currentSize,
ExcelScript.ShapeScaleFrom.scaleFromTopLeft);
}
// Black border
shape.getLineFormat().setColor("#000000");
}
});
}This Office Script automatically standardizes images in the active Excel worksheet by resizing any image shorter than 400 pixels to a height of 400 pixels (while keeping its aspect ratio) and adding a black border to each image.