Home Java Poi Find Records of The Rows Using POI



Find Records of The Rows Using POI
Posted on: March 14, 2008 at 12:00 AM
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.

Related Tags for Find Records of The Rows Using POI:
cexcelapicomclassormformeventiomethodsmethodsedformatfindgetcolumnnumberusingthisrowforpoiexamplerecordprogramrecordstoramexamstoreextendinformationshexteextendsuseimfirstcomparableceinrminfoasmntparsheet3.0clemendpimeprotorumnxaxampseecolatisirinfmplgoartftcordsxtssrdthstabablatiapendsfinendsluminforminformatpleplprndodsonomogrolo


More Tutorials from this section

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

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.