POI

POI api Projects

POI api Project 1

Find the record in row wise in POI API
Previous Home Next

 

In this page of the example we are trying to find records of an excel sheet using POI2.5 API Event. The class RowRecordextends Record implements Comparable. in this program it class is store the row information for the sheet.


 
getFirstCol():-
This methods get the first column number for the sheet.
getLastCol():-
This methods get the last column number for the sheet.


 
package r4r;
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 findrecordtest {
public static void main(String[] args) throws IOException
  {
  FileInputStream fis = new FileInputStream(args[0]);
  POIFSFileSystem pfs = new POIFSFileSystem(fis);
  InputStream in = pfs.createDocumentInputStream
("Workbook");
  HSSFRequest hreq = new HSSFRequest();
 hreq.addListenerForAllRecords(new findrecordtest());
 HSSFEventFactory factory = new HSSFEventFactory();
  factory.processEvents(hreq, in);
  fis.close();
 in.close();
  System.out.println("STOP");
  }
  public void processRecord(Record record)
  {
  switch (record.getSid())  {
  case  RowRecord.sid:
  RowRecord rowrececord = (RowRecord) record;
  System.out.println("Row is found, First column at "
  + rowrececord.getFirstCol() + 
" Last column at " + rowrececord.getLastCol());
  break; 
  }
 }  
}


Previous Home Next