Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Poi Find Value of Column

Related Tutorials


 
 

Share on Google+Share on Google+

Find Value of Column

Advertisement
In this program we are going to find the value of row from the column of an excel sheet using POI3.0 API Event.

Find Value of Column

     

In this program we are going to find the value of row from the column of  an excel sheet using POI3.0 API Event.

The org.apache.poi.hssf.record.NumberRecord class extends Record and implements CellValueRecord interface,  java.lang.Comparable interface.

The methods used in this example:

getRow():
This method is used to get the row from cell.

getColumn():
This method is used to get the column from cell defines within the row. 

getNumStrings():
This method is used to fine the number of strings.

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 FindValuesRowAtColumn 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 
FindValuesRowAtColumn());
 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 NumberRecord.sid:
  NumberRecord numrecord = (NumberRecord
record;

  System.out.println("Cell found with value "
 
+ numrecord.getValue()
  " at row " + numrecord.getRow() +
 
" and column " + numrecord.getColumn());
  break;
  case SSTRecord.sid:
  SSTRecord sstrecord = (SSTRecordrecord;
  for (int k = 0; k < sstrecord.
getNumUniqueStrings
(); k++)
  {
  System.out.println("String table value " + k + 
" \t " + sstrecord.getString(k));
  }
  break;
  }
 }  
}

The output of the program is given below:

C:\POI3.0\exmples\execl>java FindValuesRowAtColumn example.xls
String table value 0     Name Of Example
String table value 1     Status
String table value 2     coding is completed
String table value 3     compressedUnicode.java
String table value 4     EventAPIsExample.java
String table value 5     FindNameOfSheet.java
String table value 6     FindRowAtColumn.java
String table value 7     FindStringCellsValues.java
String table value 8     FindValuesRowAtColumn.java
String table value 9     setDataFormat.java
String table value 10    setDataFormatForFullList.java
String table value 11    setNameUnicodeDataFormat.java
String table value 12    setSheetNameUnicodeDataFormat.java
String table value 13    setUnicodeDataFormat.java
String table value 14    TypeOfSheet.java
String table value 15    TypeOfWorkBook.java
Cell found with value 1.11323232E8 at row 14 and column 0
STOP

Download this example.

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: March 14, 2008

Related Tutorials

Discuss: Find Value of Column  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com