# Print Area

## Content

SpreadJS defines a print range in a worksheet by the custom name “Print\_Area” whenever the user sets a print area. The main benefits of the “Print\_Area” custom name are:

* The print area updates when the user inserts or deletes a row or column.
* The custom name can be used in formula functions.
* The print area updates automatically when a user sets "Print\_Area" to a formula.

## Interaction with Name Manager

The SpreadJS Name Manager adds a "Print\_Area" custom name with the same reference as the set print area. It can be selected in the worksheet by accessing it through the name box dropdown.

![](https://gcdocumentsitekrblob.blob.core.windows.net/document-site-files/images/8d606653-16a0-474d-b9dc-e2b4d01c2446/images/printarea.gif)

The users can also manually create or edit the "Print\_Area" custom name like any other custom name through the Name Manager dialog. The custom name is neither culture-related nor case-sensitive.

> **Note:** The “Print\_Area” custom name is valid when it is in sheet scope and refers to the range of the sheet. It acts only as a custom name if invalid.
> Hence, users can add a custom name "Print\_Area" with the workbook scope, but not affect the print area.

## Interaction with Print Information

The print range fetched from the “Print\_Area” custom name sets the values of the following [PrintInfo](/spreadjs/api/v17/classes/GC.Spread.Sheets.Print.PrintInfo) class methods: *rowStart*, *rowEnd*, *columnStart*, and *columnEnd*.

Conversely, the class methods set up the “Print\_Area” custom name in the SpreadJS worksheet. It is recommended to set the print range either through the custom name "Print\_Area" or through the PrintInfo methods, and not together.

## Examples

The following code sample shows how the “Print\_Area” custom name affects the PrintInfo methods.

```JavaScript
// Configure Workbook and Worksheet
var spread = new GC.Spread.Sheets.Workbook("ss");
var sheet = spread.getActiveSheet();

var printInfo = sheet.printInfo();

// Print_Area affecting PrintInfo
sheet.addCustomName("Print_Area", "=A1:B5")
console.log(printInfo.rowStart())   // Output: 0
console.log(printInfo.rowEnd())     // Output: 4

sheet.removeCustomName("Print_Area", "")
console.log(printInfo.rowStart())   // Output: -1
console.log(printInfo.rowEnd())     // Output: -1
```

The following code sample shows how the PrintInfo methods affect the “Print\_Area” custom name.

```JavaScript
// PrintInfo affecting Print_Area
printInfo.rowStart(1)
// Assume the rowCount of the sheet is 20
sheet.getCustomName("Print_Area")
// Return a NameInfo instance, and the formula is "=2:20"
console.log(printInfo.rowStart())   // Output: 1
console.log(printInfo.rowEnd())     // Output: -1

printInfo.rowEnd(15)
sheet.getCustomName("Print_Area")
// Return a NameInfo instance, and the formula is "=2:16"
console.log(printInfo.rowEnd())     // Output: 15
```

The following code sample shows how the “Print\_Area” custom name and the PrintInfo methods affect each other.

```JavaScript
// Print_Area and PrintInfo affecting each other
sheet.addCustomName("Print_Area", "=A1:B5")
console.log(printInfo.rowStart())   // Output: 0
console.log(printInfo.rowEnd())     // Output: 4

printInfo.rowStart(1);
sheet.getCustomName("Print_Area")
// Return a NameInfo instance, and the formula is "=A2:B5"
```

## Interaction with Formulas

SpreadJS provides the ability to use the custom name “Print\_Area” in formulas. This helps to apply conditional statements that can create dynamic print areas in a worksheet.

For example, you can enter the formula `=IFERROR(ROWS(Print_Area),"none")` to display the number of rows to print, and display "none" if it does not exist.

You can also update the print area automatically depending on whether values are inserted in a cell as shown in the code example below.

```javascript
// Configure Workbook and Worksheet
var spread = new GC.Spread.Sheets.Workbook("ss");
var sheet = spread.getActiveSheet();

var printInfo = sheet.printInfo();

// Formula with conditional statement
sheet.addCustomName("Print_Area", "=IF(Sheet1!$A$1,Sheet1!$B$1:$C$5,Sheet1!$D$5:$F$8)")
// Assume A1 is a truthy value
console.log(printInfo.rowStart())
// Output: 0
console.log(printInfo.rowEnd())
// Output: 4

printInfo.rowStart(1);
sheet.getCustomName("Print_Area")
// Return a NameInfo instance, and the formula is "=B2:C5"
```