ronaldkwandy

Untitled

Jun 25th, 2020
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     public setCellImage(rowStart: number, columnStart: number, rowEnd: number, columnEnd: number, base61Image: string, extension: string) {
  2.     const image = this.workbook.addImage({
  3.       base64: base61Image,
  4.       extension: extension,
  5.     });
  6.  
  7.     const imageElement = new Image();
  8.     imageElement.src = base61Image;
  9.     const imageWidth = imageElement.width;
  10.     const imageHeight = imageElement.height;
  11.     const areaWidthInPixels = (columnEnd - columnStart + 1) * 64;
  12.     const areaHeightInPixels = (rowEnd - rowStart + 1) * 20;
  13.  
  14.     // resized to area width
  15.     let imageResizedWidth = areaWidthInPixels;
  16.     let imageResizedHeight = imageHeight / imageWidth * imageResizedWidth;
  17.     if (imageResizedHeight > areaHeightInPixels) {
  18.       // resized to area height if resizedHeight still bigger than the area
  19.       imageResizedHeight = areaHeightInPixels;
  20.       imageResizedWidth = imageWidth / imageHeight * imageResizedHeight;
  21.     }
  22.  
  23.     const imagePosition = {
  24.       tl: { col: columnStart - 1, row: rowStart - 1 },
  25.       ext: { width: imageResizedWidth, height: imageResizedHeight }
  26.     };
  27.  
  28.     this.sheet.addImage(image, imagePosition);
  29.   }
Add Comment
Please, Sign In to add comment