POI

POI api Projects

POI api Project 1

Find Type of Excel Sheet
Previous Home Next

In this page of the tutorials we are going to find type of an excel sheet using POI2.5 API Event.

Methods Description

getSSTIndex()

This methods give the description copied from class.

getString(int i)

This methods find the type of object that is marked. This method returns short type of object.

The types of workbook are:

  1. TYPE_WORKBOOK
  2. TYPE_VB_MODULE
  3. TYPE_WORKSHEET
  4. TYPE_CHART
  5. TYPE_EXCEL_4_MACRO
  6. TYPE_WORKSPACE_FILE

Example

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 findexcelsheettype implements HSSFListener {
	private SSTRecord sstrecord;
	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 findexcelsheettype());
	 HSSFEventFactory fact = new HSSFEventFactory();
	  fact.processEvents(hreq,in);
	  fis.close();
	 in.close();
	  System.out.println("STOP");
	  }
	  public void processRecord(Record record)
	  {
	  switch (record.getSid())
	  {
	  case BOFRecord.sid:
	  BOFRecord bof = (BOFRecord) record;
	  if (bof.getType() == bof.TYPE_WORKSHEET)
	  {
	  System.out.println("Encountered sheet reference");
	  }
	  break;
	  }
	 }
}
Previous Home Next