POI api Projects

POI api Project 1

Find String Values of Cell with help of POI
Previous Home Next

In this page of the tutorials we are going to find the String Values of Cell of an excel sheet using POI2.5.0 API Event.

The class org.apache.poi.hssf.record.LabelSSTRecord extends Record implements CellValueRecordinterface and java.lang.Comparable. this is used to make reference of a string and a column value.

Methods Description


This method is used to give the Find String Values of Cellin the SSTRecord. and The return type of this getSSTIndex() method is integer (Find String Values of Cellof string in the SST Table).

getString(int i)

This method is used to get the string value from SSTRecord .


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 findstringvalueofcell implements HSSFListener {
	public static void main(String[] args) throws IOException
	 FileInputStream fis = new FileInputStream(args[0]);
	 	  POIFSFileSystem pfs = new POIFSFileSystem(fis);
	  InputStream in = pfs.createDocumentInputStream
	  HSSFRequest hreq = new HSSFRequest();
	 hreq.addListenerForAllRecords(new findstringvalueofcell());
	 HSSFEventFactory fact = new HSSFEventFactory();
	  fact.processEvents(hreq, in);
	  SSTRecord sstrecord;
	  public void processRecord(Record record)
	  switch (record.getSid()) {
	  case SSTRecord.sid:
	  sstrecord = (SSTRecord) record;
	  for (int k = 0; k < sstrecord.getNumUniqueStrings(); k++)
	  System.out.println("String table values " + k + " = " + sstrecord.getString(k));
	  case LabelSSTRecord.sid:
	  LabelSSTRecord lrecord = (LabelSSTRecord) record;
	  System.out.println("String cell found with values \t"
	  + sstrecord.getString(lrecord.getSSTIndex()));
Previous Home Next