79617406

Date: 2025-05-12 07:47:47
Score: 1
Natty:
Report link

You're on the right track with your approach. In the web version of Excel using Office Script, you cannot directly use the ImageData class or manipulate raw pixel data like you would in a browser environment. Office Script provides a worksheet.addImage() method, but it only accepts a base64-encoded string representing an image in PNG or JPEG format. Unfortunately, there is no built-in way within Office Script to convert ImageData or a canvas element to base64, since Office Script does not have access to DOM elements like or browser-specific APIs. The recommended approach is to generate the barcode image outside of Office Script using a JavaScript barcode generation library such as JsBarcode or bwip-js, which can render barcodes to a canvas. From there, you can convert the canvas to a base64-encoded PNG using canvas.toDataURL("image/png"), and then pass that base64 string (stripping the "data:image/png;base64," prefix) into your Office Script. Once you have the base64-encoded image, you can easily insert it into your Excel worksheet using worksheet.addImage(base64Image). This workflow enables you to maintain barcode functionality in the Excel web version without relying on custom fonts or VBA.

Reasons:
  • Long answer (-1):
  • No code block (0.5):
  • Single line (0.5):
  • Low reputation (1):
Posted by: Sajeesh K