How to find the value of the column in POI API
Previous | Home | Next |
In this page of the tutorials we are going to find the value of row from the column of an excel sheet using POI2.5 API Event. The org.apache.poi.hssf.record.NumberRecord class extends Record and implements CellValueRecord interface,
java.lang.Comparable interface.
getRow():-This methods get the row from cell.getColumn():-This methods get the column from cell defines within the row.getNumStrings():-This methods fine the number of strings.
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 findvalueofcolumn 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 findvalueofcolumn()); 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 NumberRecord.sid: NumberRecord numrecord = (NumberRecord) record; System.out.println("found value in Cell " + numrecord.getValue() + " at row " + numrecord.getRow() + " and column " + numrecord.getColumn()); break; case SSTRecord.sid: SSTRecord sstrecord = (SSTRecord) record; for (int k = 0; k < sstrecord. getNumUniqueStrings(); k++) { System.out.println("String value " + k + " \t " + sstrecord.getString(k)); } break; } } }
Previous | Home | Next |