POI

POI api Projects

POI api Project 1

Find Type of Work Book
Previous Home Next

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

Methods Description

getSid()

This methods give the description copied from class.

getType()

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

The different 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

In this program we are trying to find the type of workbook and compare it BOFRecord .If compression returns true the print we are printing a String message .

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 findtypeofworkbook 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("Workbook");
	  HSSFRequest hreq = new HSSFRequest();
	  hreq.addListenerForAllRecords(new findtypeofworkbook());
	  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_WORKBOOK)
	  {
	  System.out.println("Workbook");
	  	  } 
	  break;
	  }
	 }
}
Previous Home Next