Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML


 
  
 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 

 
Facing Programming Problem?
Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Find Name of Excel Sheet

                         

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

The advantage of
event API  is that you can read an XLS with a relatively small memory.

To use Event API we construct an instance of org.apache.poi.hssf.eventmodel.HSSFRequest. To register a class we have to create listener org.apache.poi.hssf.eventmodel.HSSFListener interface and use HSSFRequest.addListener(yourlistener, recordsid) method. The record Sid should be a static reference number (such as BOFRecord.sid) contained in the classes in org.apache.poi.hssf.record. Alternatively you can call HSSFRequest.addListenerForAllRecords(mylistener).

Once we have  registered our  listeners in the HSSFRequest object we can construct an instance of org.apache.poi.poifs.filesystem.FileSystem and pass it your XLS file inputstream. We can either pass this, along with the request we constructed, to an instance of HSSFEventFactory via the HSSFEventFactory.processWorkbookEvents(request, Filesystem) method, or we can get an instance of DocumentInputStream from Filesystem.createDocumentInputStream("Workbook") and pass it to HSSFEventFactory.processEvents(request, inputStream). Once we make this call, the listeners that we constructed receive calls to their processRecord(Record) methods with each Record they are registered to listen for until the file has been completely read.
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 less than operator as hex .

The public class BoundSheetRecord extends Record. This is used to defines a sheet within a workbook This is basically stores the sheet name and tells where the beginning of file record is within the HSSF file. 

getSheetname():
This method is used to find the name of sheet from  BoundSheetRecord.

 
 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 FindNameOfSheet implements HSSFListener
{
    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 FindNameOfSheet());
           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  BoundSheetRecord.sid:
                BoundSheetRecord bsrecord = 
(
BoundSheetRecordrecord;
               System.out.println("New sheet named: " +
 bsrecord.getSheetname
());
                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.

                         

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Latest Searches:
remove array element
MurachÑ??д?Ñ??и?Ñ??Ð
Hibernate sequences
jsf datatree component
find out factors of nu
jsp struts 2 tags
how to export zeroes t
??????????????????????
Passing Various Data T
source code of puzzle
3DS MAX Modeling Model
select a row of data t
netbeans jsp
multiple rows in singl
Photoshop Textures and
json lib/componen...]=
Visual Basic Date and
da Jfreechart a image
jfreechart
distributed cache upda
CSSCSSTheRevealTransFi
substring
java forward to page
<s:push> in struts2
JDBC and Mysql
how to add customised
struts2 checkbox
x509
joining queries in SQ
java servlet send soun
Building a Simple EJB
Tracing
select checkbox
Murachà¹??à¸?ะà¸???à
ASP Database Related U
assertNotNull
select
string operations jav
sort list
spiral
url redirecting in ser
call ?�¾????????�¾
XML parsing Example
å??奥ç?©èµ´????????å?
two dimensional array
Photoshop Magnifying L
servlet and session
jdk1.6.0_07 download
Try catch in JSP
length()
howtoretrievedatabasei
trim().length()
read hexadecimal from
Java Swing Swing's new
how to get the checkbo
How to insert multiple
how to track user logi
backing up stored proc
GetCharFromString usin
persistent cookie
J2se Tutorial
send emails with jsp
Photoshop Web Graphics
Ñ?одÑ?п?Ñ?оâ????Ñ?
json lib//componen...]
json lib//componen...]
server means
java set methods
Use of <x:set> tag of
<h:table
html div tags
sர?ய�ர?ய�?
prompt gui in java
Whyshouldexceptionhand
ShortestJobFirst
find a replace bytes i
register
print non prime number
jdbc with ms access
Photoshop Effects Ligh
Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.