Google Sheets Script. Range 2 Image

Max Makhrov
2 min readAug 1, 2022

Hi, this is Max from Cooltables!

Here’s the demo:

🙌 Now you also may install the Range2Image add-on from Google Marketplace!

Please copy the sample sheet and try it:

https://docs.google.com/spreadsheets/d/1qNQ6iCMoBCQgJzBB63ymtBQ6BedXZFhjgZZKGItjeVA/copy

The script lets you convert the selected range to an image. It will also save a ready PNG to your Drive\Root.

How it works

It creates an URL for PDF first and then uses Canvas and Pdf.js to convert it into PNG.

Instruction:

  1. Select a range
  2. Use the custom menu to launch the script. Authorize and rerun it when you do it the first time.
  3. Wait until the image is rendered.
  4. Optionally right-click the image and save/copy it to your computer.

Issues

We want to solve these:

  1. [✅ RESOLVED 2023] The script only works if the Spreadsheet is shared as “Anyone on the internet with the link can view”
  2. We face a limit of ~1100 rows, if you try more, the engine cannot render an image.
  3. There is no method in Sheets to get the pixel size of a range, we can only do it row by row, column by column.
  4. There are different pixel sizes for rows and columns, for instance, if we create bold borders for cells, the actual image size will not fit.

Benefits

We recommend using the script if:

  1. You need to create a screenshot and use it later: send it to Telegram or email, or use it in Slides.
  2. You want to create an image of cells as you see them on screen, containing images, charts, sparklines, etc.
  3. You want to create a screenshot of a range that does not fit your screen.
  4. You want to create a screenshot of a range with high resolution.

Settings

Please adjust these settings inside the code:

var SaveRangeAsImageSettings = {
folder_id: '',
save2drive: true,
measure_limit: 150, // assume all other rows/cols have same size
size_limit: 1100, // the max. number of rows/columns,
image_scale: 1 // will multiply image size by this number
}

Conclusion

The script is still under construction. You’re welcome to join our tests:

--

--

Max Makhrov

Google Sheets Developer, master of Online Accounting