Find Type of Excel Sheet

In this program we are going to find type of an excel sheet using POI3.0 API Event.

Find Type of Excel Sheet

In this program we are going to find type of an excel sheet using POI3.0 API Event.

Find Type of Excel Sheet

Find Type of Excel Sheet

     

In this program we are going to find type of an excel sheet using POI3.0 API Event.

The methods used in this example:

getSid():
This method is used to give the description  copied  from class.

public static final short sid:
The sid variable is used for the less than operator as hex .

The public class BOFRecord extends Record class. It is  used for the beginning of a set of records that have a particular purpose or subject used in sheets and workbooks

getType():
This method is used to 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

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 TypeOfSheet implements HSSFListener
{  private SSTRecord sstrecord;
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 TypeOfSheet());
 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 BOFRecord.sid:
  BOFRecord bof = (BOFRecordrecord;
  if (bof.getType() == bof.TYPE_WORKSHEET)
  {
  System.out.println
(
"Encountered sheet reference");
  }
  break;
  }
 }  
  
}

The output of the program is given below:

C:\POI3.0\exmples\execl>javac FindNameOfSheet.java

C:\POI3.0\exmples\execl>java FindNameOfSheet example.xls
New sheet named: Sheet1
New sheet named: Sheet2
New sheet named: Sheet3
STOP

Download this example.