Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Tutorials Poi Excel Freeze Pane Feature

Related Tutorials


 
 

Share on Google+Share on Google+

Excel Freeze Pane Feature

Advertisement
In this section, you will learn about freezing row of excel document using Apache POI library.

Excel Freeze Pane Feature

In this section, you will learn about freezing row of excel document using Apache POI library.

Sometimes when you scroll down too far, we lost the heading at top. Due to this, we feel difficulty to relate which cell belongs to which heading. The solution of this problem is Freeze Pane which freezes the the row you want to retain at it's place.

Given below code will freezes the top row and all other row can scroll up or scroll down :

import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class XLfreezePanes {
public static void main(String args[]) throws IOException {
Workbook wb = new XSSFWorkbook();
CreationHelper createHelper = wb.getCreationHelper();
Sheet sheet1 = wb.createSheet("new sheet");

Row row = sheet1.createRow((short) 0);
// Create a cell and put a value in it.
row.createCell(0).setCellValue(
createHelper.createRichTextString("THIS IS FREEZED ROW"));
for (int i = 1; i < 20; i++) {
row = sheet1.createRow((short) i);
row
.createCell(0)
.setCellValue(
createHelper
.createRichTextString("This is the Moving Row"));
}

// Freeze just one row
sheet1.createFreezePane(0, 1, 0, 1);

FileOutputStream fileOut = new FileOutputStream(
"xlsx/FixedWorkbook.xlsx");
wb.write(fileOut);
fileOut.close();
}
}

In the function createFreezePane , the first two parameters are the columns and rows you wish to split by. The second two parameters indicate the cells that are visible in the bottom right quadrant.

OUTPUT

In the below example, row 1freezes and all other can scroll up or down :

Download Source Code

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: August 10, 2011

Related Tutorials

Discuss: Excel Freeze Pane Feature  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com