Preparing Sheets. How to Set Print Area in Google Sheets

How to Set Print Area in Google Sheets #

Google Sheets is a powerful tool for creating and managing spreadsheets, and it offers several features to help you customize your printed documents. One such feature is the ability to set a print area, which allows you to define the range of cells that should be printed when you want to create a hard copy of your spreadsheet. In this article, we will explore how to set the print area in Google Sheets manually and programmatically using Google Apps Script.

Setting the Print Area Manually #

To set the print area manually in Google Sheets, follow these steps:

  1. Open your spreadsheet in Google Sheets.
  2. Select the range of cells you want to include in the print area. You can click and drag to select multiple cells or use the keyboard shortcuts Shift+Click or Ctrl+Click to select non-adjacent cells.
  3. Once you have selected the desired range, go to the "File" menu and click on "Print".
  4. In the Print settings panel that appears on the right-hand side, click on the "Print range" dropdown menu.
  5. Select the "Selected cells" option. You will notice that the preview of the print area updates to reflect your selection.
  6. Adjust any other print settings as needed, such as page orientation, paper size, or margins.
  7. When you are ready to print, click on the "Print" button to generate a hard copy of your spreadsheet using the defined print area.

By following these steps, you can easily set the print area in Google Sheets manually and customize your printed documents according to your needs.

Setting the Print Area Programmatically with Google Apps Script #

Google Apps Script provides a way to automate tasks in Google Sheets, including setting the print area programmatically. To achieve this, follow these instructions:

  1. Open your Google Sheets spreadsheet.
  2. Go to the "Tools" menu and select "Script editor" to open the Google Apps Script editor.
  3. In the script editor, delete the code in the default myFunction function.
  4. Replace it with the following code:
function setPrintArea() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var range = sheet.getSelection();
sheet.setPrintArea(range);
}
  1. Save the script by clicking on the floppy disk icon or pressing Ctrl+S.
  2. Close the script editor.

You can now use the newly created setPrintArea function to set the print area programmatically in your Google Sheets spreadsheet. To do so, follow these steps:

  1. Select the range of cells you want to include as the print area.
  2. Go to the "Extensions" menu and hover over "Custom Functions".
  3. Click on "setPrintArea". This will execute the setPrintArea function and set the selected range as the print area.

Use Case Examples #

Here are a few examples of when setting the print area in Google Sheets can be useful:

  • Creating reports: You can set the print area to include only the relevant data and formatting for reports, ensuring that unnecessary information is not printed.
  • Generating invoices: By setting the print area to include specific cells with invoice details, you can easily create printable invoices without including any extraneous information.
  • Printing specific data: If you only need to print certain sections or ranges of your spreadsheet, such as charts, tables, or summaries, setting the print area allows you to control what is printed.

Setting the print area in Google Sheets can help you customize and optimize your printed documents, whether you're creating reports, invoices, or simply printing specific data. By following the manual instructions or using the provided Google Apps Script, you can easily define the print area to suit your needs.

Delete empty rows: To clean up your Google Sheets, you can delete empty rows using a simple process.
Delete rows: If you need to remove specific rows from your Google Sheets, follow this guide on how to delete rows.
Sort by column: To organize your data more effectively, you can sort it by column in Google Sheets.
Remove blank rows: Learn how to remove blank rows from your Google Sheets and maintain a clean dataset.
Delete duplicates: Discover how to delete duplicate entries in Google Sheets and streamline your data.

Published