Home Java Poi Find Records of The Rows Using POI
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Find Records of The Rows Using POI

Advertisement
In this program we are going to find records of an excel sheet using POI3.0 API Event.

Find Records of The Rows Using POI

    

In this program we are going to find records of  an excel sheet using POI3.0 API Event.

The class RowRecordextends Record implements Comparable. This class is used to store the row information for the sheet. 

The methods used in this example are :

getFirstCol():
This method is used to get the first column number for the sheet.

 getLastCol():
This method is used to
get the last col number for the sheet.

The code of the program is given below:
import java.io.*;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.poifs.filesystem.*;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.eventusermodel.*;
import org.apache.poi.hssf.record.*;
import org.apache.poi.hssf.dev.EFHSSF;
public class FindRowAtColumn implements HSSFListener
{ 
public static void main(String[] argsthrows IOException
  {
  FileInputStream fin = new FileInputStream(args[0]);
  POIFSFileSystem poifs = new POIFSFileSystem(fin);
  InputStream din = poifs.createDocumentInputStream
(
"Workbook");
  HSSFRequest req = new HSSFRequest();
 req.addListenerForAllRecords(new FindRowAtColumn());
 HSSFEventFactory factory = new HSSFEventFactory();
  factory.processEvents(req, din);
  fin.close();
 din.close();
  System.out.println("STOP");
  }
  public void processRecord(Record record)
  {
  switch (record.getSid())  {
  case  RowRecord.sid:
  RowRecord rowrececord = (RowRecordrecord;
  System.out.println("Row found, first column at "
  + rowrececord.getFirstCol() 
" last column at " + rowrececord.getLastCol());
  break; 
  }
 }  
}

The output of the program is given below:

C:\exmples\execl>javac FindRowAtColumn.java

C:\POI3.0\exmples\execl>java FindRowAtColumn example.xls
Row found, first column at 0 last column at 2
Row found, first column at 0 last column at 2
Row found, first column at 0 last column at 2
Row found, first column at 0 last column at 2
Row found, first column at 0 last column at 2
Row found, first column at 0 last column at 2
Row found, first column at 0 last column at 2
Row found, first column at 0 last column at 2
Row found, first column at 0 last column at 2
Row found, first column at 0 last column at 2
Row found, first column at 0 last column at 2
Row found, first column at 0 last column at 2
Row found, first column at 0 last column at 2
Row found, first column at 0 last column at 2
Row found, first column at 0 last column at 2
STOP
 

Download this example.

Advertisements

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: March 14, 2008

Related Tutorials

Ask Questions?    Discuss: Find Records of The Rows Using POI  

Post your Comment


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