Set Print Area

Aspose.Cells - Set Print Area

By default, only the print area incorporates all areas of the worksheet that contain data. Developers can establish a specific print area of the worksheet.

To select a specific print area, use the PageSetup class' setPrintArea method. Assign a cell range that defines the print area to this property.


 // Instantiating a Workbook object

Workbook workbook = new Workbook();

// Accessing the first worksheet in the Workbook file

WorksheetCollection worksheets = workbook.getWorksheets();

Worksheet sheet = worksheets.get(0);

// Obtaining the reference of the PageSetup of the worksheet

PageSetup pageSetup = sheet.getPageSetup();

// Specifying the cells range (from A1 cell to F20 cell) of the print area


Apache POI SS - HSSF XSSF - Set Print Area

Workbook.setPrintArea method is available to set page properties of print area.


 Workbook wb = new HSSFWorkbook();

Sheet sheet = wb.createSheet("Sheet1");

//sets the print area for the first sheet

wb.setPrintArea(0, "$A$1:$C$2");



        0, //sheet index

        0, //start column

        1, //end column

        0, //start row

        0  //end row


Download Running Code

Download Sample Code