Skip to main content
A picture shows cells as the Copy Picture command in Microsoft Excel shows them: the cells as on screen, with charts and pictures. It does not show the selection or the frozen-pane lines. It shows row and column headers only when you set labels: true (see Labels). You can make a picture in Node and in the browser:

In Node

toPng needs skia-canvas and @reductoai/portable-fonts (see Installation).

Every sheet

With no options, toPng makes one PNG for each visible sheet. Each picture holds the sheet’s used cells, from A1.
Each entry is { sheet, width, height, png }. png is a Buffer. width and height are in pixels.

One sheet

Give the sheet names or zero-based indexes in sheets. Hidden sheets are included when you name them.

One range

Give an A1 range in range. Put the sheet name before !, and toPng returns one entry. Without a sheet name, toPng makes a picture of that range on each sheet in sheets, or on each visible sheet.
To check an edit by eye, make a picture of only the range you changed.

Options

From the JS API

range.getImage() returns a Base64 PNG of the range, at one image pixel for each sheet pixel. It is the Office.js Range.getImage. Office.js returns a ClientResult that you read after context.sync(). Here you await the string.
getImage needs a painter. @reductoai/xlsx/node brings one. In the browser, import @reductoai/xlsx/view once, anywhere in your app:
Without a painter, getImage rejects with an error that names the two entries. The image has gridlines when the sheet shows them, as in Office.js. Set worksheet.showGridlines to false, or give gridlines: false, to leave them out. In Office.js, getImage has no parameters. Here it takes the options labels, gridlines and scale, as toPng does:

In the browser, from a view

When the workbook is already on screen in a view or the editor, use view.rangeImage. It uses the view’s layout, fonts and pictures. The picture has the column widths and row heights the user sees, also after the user resizes a column.
Without a sheet name, the range is on the active sheet. With no range, the picture shows the selected cells. The options are scale, gridlines and labels, as for toPng. The promise resolves after the fonts and pictures in the range have loaded, so the first picture is correct.

Labels

labels: true adds column letters above the cells and row numbers to their left, as Excel’s headers show them. Use it when a person or a language model must read a cell address from the picture. For example, a model can say “the border under C7 is missing” when it sees the labels. Without the labels, it can only describe the position.
  • The labels name the sheet’s own rows and columns, so a picture of B2:H30 starts at column B and row 2.
  • A hidden row or column has no label. The gap in the numbers shows where it is.
  • A label that is wider than its column is left out.
  • The labels are an extension. Excel’s Copy Picture does not paint them.

Limits

  • A picture holds at most 1,000 rows and 100 columns, from the top-left cell of the range. A whole column such as "A:A" stops after 1,000 rows.
  • A picture is at most 16,384 pixels on each side and 16,777,216 pixels in area, because browsers and skia-canvas cannot make a larger canvas. Rows and columns past this limit are not included. At scale: 2, the picture holds half as many rows and columns before it gets to the limit.