Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public setCellImage(rowStart: number, columnStart: number, rowEnd: number, columnEnd: number, base61Image: string, extension: string) {
- const image = this.workbook.addImage({
- base64: base61Image,
- extension: extension,
- });
- const imageElement = new Image();
- imageElement.src = base61Image;
- const imageWidth = imageElement.width;
- const imageHeight = imageElement.height;
- const areaWidthInPixels = (columnEnd - columnStart + 1) * 64;
- const areaHeightInPixels = (rowEnd - rowStart + 1) * 20;
- // resized to area width
- let imageResizedWidth = areaWidthInPixels;
- let imageResizedHeight = imageHeight / imageWidth * imageResizedWidth;
- if (imageResizedHeight > areaHeightInPixels) {
- // resized to area height if resizedHeight still bigger than the area
- imageResizedHeight = areaHeightInPixels;
- imageResizedWidth = imageWidth / imageHeight * imageResizedHeight;
- }
- const imagePosition = {
- tl: { col: columnStart - 1, row: rowStart - 1 },
- ext: { width: imageResizedWidth, height: imageResizedHeight }
- };
- this.sheet.addImage(image, imagePosition);
- }
Add Comment
Please, Sign In to add comment