A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.tutorialspoint.com/javaexamples/set_print_area_of_spreadsheet.htm below:

How to set the print area of a spread sheet using Java

How to set the print area of a spread sheet using Java Problem Description

How to set the print area of a spread sheet using Java.

Solution

Following is the program to set the print area of a spread sheet using Java.

import java.io.File;
import java.io.FileOutputStream;

import org.apache.poi.xssf.usermodel.XSSFPrintSetup;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class SettingPrintAreaToSpreadSheet {
   public static void main(String[] args)throws Exception {

      //Create a Work Book
      XSSFWorkbook workbook = new XSSFWorkbook();
      XSSFSheet spreadsheet = workbook.createSheet("Print Area");

      //set print area with indexes
      workbook.setPrintArea(
         0, //sheet index
         0, //start column
         5, //end column
         0, //start row
         5  //end row
      );

      //set paper size
      spreadsheet.getPrintSetup().setPaperSize(XSSFPrintSetup.A4_PAPERSIZE);

      //set display grid lines or not
      spreadsheet.setDisplayGridlines(true);

      //set print grid lines or not
      spreadsheet.setPrintGridlines(true);
      FileOutputStream out = new FileOutputStream(
         new File("C:/poiexcel/printarea.xlsx"));
      
      workbook.write(out);
      out.close();
      
      System.out.println("printarea.xlsx written successfully");
   }
}
Output

java_apache_poi_excel


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4