Using HSSF 3.5 to READ XLS

Using HSSF 3.5 to READ XLS

View Answers

October 5, 2009 at 10:32 AM

Hi Friend,

Try the following code:

import java.io.*;
import java.util.*;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;

public class ReadFile {
public static void main( String [] args ) {
String fileName="C:\\excelFile.xls";
Vector dataHolder=ReadFile(fileName);
printCellDataToConsole(dataHolder);
}
public static Vector ReadFile(String fileName) {
Vector cellVectorHolder = new Vector();
try{
FileInputStream myInput = new FileInputStream(fileName);
POIFSFileSystem myFileSystem = new POIFSFileSystem(myInput);
HSSFWorkbook myWorkBook = new HSSFWorkbook(myFileSystem);
HSSFSheet mySheet = myWorkBook.getSheetAt(0);
Iterator rowIter = mySheet.rowIterator();
while(rowIter.hasNext()){
HSSFRow myRow = (HSSFRow) rowIter.next();
Iterator cellIter = myRow.cellIterator();
Vector cellStoreVector=new Vector();
while(cellIter.hasNext()){
HSSFCell myCell = (HSSFCell) cellIter.next();
cellStoreVector.addElement(myCell);
}
cellVectorHolder.addElement(cellStoreVector);
}
}catch (Exception e){e.printStackTrace(); }
return cellVectorHolder;
}
private static void printCellDataToConsole(Vector dataHolder) {
for (int i=0;i<dataHolder.size(); i++){
Vector cellStoreVector=(Vector)dataHolder.elementAt(i);
for (int j=0; j < cellStoreVector.size();j++){
HSSFCell myCell = (HSSFCell)cellStoreVector.elementAt(j);
String stringCellValue = myCell.toString();
System.out.print(stringCellValue+"\t");
}
System.out.println();
}
}
}

Thanks









Related Tutorials/Questions & Answers:
Using HSSF 3.5 to READ XLS - Java Beginners
Using HSSF 3.5 to READ XLS  I just dont seem to get this working. I have tried the examples here on this homepage but they are out of date for 3.5... to do is to iterate through an XLS file and print out every colum and every row
Read Simple Excel(.xls) document using Apache POI
Read Simple Excel(.xls) document using Apache POI In this section, you will learn how to read Excel file having .xls extension using Apache POI library. In the below example, we will read excel document having one sheet named as "
Advertisements
xls to js using javascript
xls to js using javascript  ![how can we convert a xls file in js file using javascript][1
Excel Created using POI and HSSF - Development process
Excel Created using POI and HSSF  Hi i ceated excel file using jakarta poi library i want to add Percentage formula to cell i am not able to do that can you please suggest me how do i add formula c3.setCellValue("Percentage
how to create xls file and give download option using jsp/servlet?
how to create xls file and give download option using jsp/servlet?  Hi, how to create file and give download option to user,so that the user can save the file on defined path
Read XML using Java
Read XML using Java  Hi All, Good Morning, I have been working... of all i need to read xml using java . i did good research in google and came to know that there are many ways to read using different API like SAX, DOM , XOM Jar
read xml using java
read xml using java  <p>to read multiple attributes... to other interacting modules, as communication is only allowed to take place using... is only allowed to take place using this layer. The data stored is composed
insert data 50 row *column into 300 row *column by using xls sheet data (50 row *column) are given in xls sheet
insert data 50 row *column into 300 row *column by using xls sheet data (50 row *column) are given in xls sheet   1- there are matrix of data... column that have different field value,that are given in xls sheet
read and write a file using javascript
read and write a file using javascript  How to read and write a file using javascript
read string - using loops in Java
read string - using loops in Java  Write a program to read a string composed of an unknown number of words, then count the number of words in the string, and Display the longest and shortest words, with first letter Uppercase
Examples of POI3.0
Format, probably written using MFC, that you needed to read in Java.We can use  HSSF if you needed to read or write an Excel file using Java (XLS). We can use HWPF for Word Documents , HSLF for PowerPoint
Create Simple Excel(.xls) document using Apache POI
Create Simple Excel(.xls) document using Apache POI In this section, you will learn how to create a Simple Excel sheet having .xls extension using Apache...;xls/CreateExcelDemo.xls")); workbook.write(fos); } catch (IOException e
Apache HSSF Jar file location
Apache HSSF Jar file location  where can i get jar files for apache hssf
Error in reading Excel data using jsp even having .xls and POI Library in respective folders
Error in reading Excel data using jsp even having .xls and POI Library in respective folders  Hi, hello.xls and POI library files... on console. java.io.IOException: Invalid header signature; read
read/write to Windows Registry using Java
read/write to Windows Registry using Java  read/write to Windows Registry using Java
how to read and write an xml file using java
how to read and write an xml file using java  Hi Can anyone help me how to read and write an xml file which has CData using java
Read Email using Java Mail API - James
Read Email using Java Mail API - James   https://www.roseindia.net/javamail/send-mail.shtml From this sample, i understand that we need to pass user credentials for reading the email content. Is there any option to read all
Read Email using Java Mail API - James
Read Email using Java Mail API - James   https://www.roseindia.net/javamail/send-mail.shtml From this sample, i understand that we need to pass user credentials for reading the email content. Is there any option to read all
Read Email using Java Mail API - James
Read Email using Java Mail API - James   https://www.roseindia.net/javamail/send-mail.shtml From this sample, i understand that we need to pass user credentials for reading the email content. Is there any option to read all
To read & write a excel file using the core java
To read & write a excel file using the core java  Hai, I'm new to JavaProgram.But now i need java program to read & write a excel file so, can anyone help me to learn the above mentioned topic(link for the portion
Read Email using Java Mail API - James
Read Email using Java Mail API - James   https://www.roseindia.net/javamail/send-mail.shtml From this sample, i understand that we need to pass user credentials for reading the email content. Is there any option to read all
How to read value from xml using java?
How to read value from xml using java?  Hi All, I want to read value from following xml using java.. In <Line>,data is in format of key and value pair.. i want to read only values..could u plz help me in this?Thanks
how to read file using InputStreamReader in java
how to read file using InputStreamReader in java  Hi, I want to learn to use the InputStreamReader class of Java and trying to read a text file with the class. how to read file using InputStreamReader in java? Thanks  
How to Read a file line by line using BufferedReader?
How to Read a file line by line using BufferedReader?  Hello Java... to Read a file line by line using BufferedReader, efficiently and using less memory... to me in my company. Here I have many big text files. I have to read these files
hibernate 3.5 maven
In this section, you will learn how to a generate simple java Hibernate 3.5 project using Maven project builder
Read Header/Footer Margin size using Java
Read Header/Footer Margin size using Java  Hi, Is it possible to read the "Header from Top" and "Footer from bottom" properties of a MS word document in Java? I have been searching the web for hours now, POI's and several other
Read Header/Footer Margin size using Java
Read Header/Footer Margin size using Java  Hi, Is it possible to read the "Header from Top" and "Footer from bottom" properties of a MS word document in Java? I have been searching the web for hours now, POI's and several other
read from file and store using hash map
read from file and store using hash map  I was stuck with a java project where I have to read a file with two different concepts and store them differently in hashmap. My data file would be something like Adults: Name, xyz
Program to read 2 integers using oops concepts
Program to read 2 integers using oops concepts  Write a program to read two integers with the following significance. ? The first integer value represents a time of day on a 24 hour clock, so that 1245 represents quarter
Read Complex XML using DOM/SAX Parser.
Read Complex XML using DOM/SAX Parser.  I have a XML file which is having two types of Items. I want to extract all details of a type only. My XML goes something like this <Movie> <Bollywood> <Actor> Shah Rukh
read XML file and display it using java servlets
read XML file and display it using java servlets  sir, i can't access Xml which is present in my d drive plz can u should go through my code n tell me the things where i went wrong java servlet program protected void
Read Multipart mail using Java Mail
Read Multipart mail using Java Mail       This Example shows you how to read a multipart message using javamail api. When we read a multipart mail firstly create
HSSF WORKSHEET FORMATTING - Java Beginners
HSSF WORKSHEET FORMATTING  I am using the following code in my jsp to import thr o/p to excel on the server. It works fine but I want to change
POI and HSSF - Development process
POI and HSSF  Hi i ceated excel file using jakarta poi library i want to add Percentage formula to cell i am not able to do that can you please suggest me how do i add formula c3.setCellValue("Percentage"); cell3.setCellType
Read Excel data using JSP and update MySQL databse
Read Excel data using JSP and update MySQL databse  HOw to read excel data using JSP and update MySQl database
How to read properties file in Python using configparser?
How to read properties file in Python using configparser and printing.... Now we can proceed for developing the program to read properties file using.... Here is the complete code to read properties file in Python using
Java Read .doc file using POI library
Java Read .doc file using POI library In this section, you will learn how to read the word document file using POI library. The class HWPFDocument throw all of the Word file data and the class WordExtractor extract the text from
write a progam for bubble sort using file read nd write?
write a progam for bubble sort using file read nd write?  hi, please give the code
Read Excel(.xlsx) document using Apache POI
Read Excel(.xlsx) document using Apache POI In this section, you will learn how to read Excel file having .xlsx extension using Apache POI library. In the below example, we will read excel document having one sheet named as "new
Read code from excel sheet and upload into database using JSP
Read code from excel sheet and upload into database using JSP  I want to upload data to database from an excel worksheet using jsp ...Please help
Read data from excel file and update database using jsp
Read data from excel file and update database using jsp  read data from excel file and update database using jsp Hi, I am using a MySQL database... upload excel file and update database using JSP ? Thanks in Advance
How to read yahoo mail using java mail api - WebSevices
How to read yahoo mail using java mail api  Hi there .... i wanted to know how to read mail from yahoo using pure java code. Is there any one who can help me regarding this, please if possible show me the exact way as well
how read excel data into database using struts2 with hibernate
how read excel data into database using struts2 with hibernate   hi friends, i am venkat i am started learning struts 2, please help me how to read excel data into database using struts2 with hibernate, please show me
ModuleNotFoundError: No module named 'xls'
ModuleNotFoundError: No module named 'xls'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'xls' How to remove the ModuleNotFoundError: No module named 'xls' error
ModuleNotFoundError: No module named 'xls'
ModuleNotFoundError: No module named 'xls'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'xls' How to remove the ModuleNotFoundError: No module named 'xls' error
how to read values from excel sheet and compare with database using jsp
how to read values from excel sheet and compare with database using jsp  hi sir i am arun how to read values from excel sheet and compare with database using jsp coding i.e, if i have 6(assetid,assetname,serialno,cubical
how to read file line by line using filereader in java
how to read file line by line using filereader in java  Hi, how to read file line by line using filereader in java? Thanks   Hi, This is example code: package my.code; import java.io.BufferedReader; import
How to read the data in text file seperated by by ',' in java using IO Operations
How to read the data in text file seperated by by ',' in java using IO Operations  in Text file data like raju 45,56,67 ramu 46,65,78 raji 34,23,56 this is the student marks in text file.this data read and calculate
how to convert a .xlsx to .xls fil - JSP-Servlet
how to convert a .xlsx to .xls fil  Dear sir, How to convert a .xlsx file to .xls using poi .Please give me some clue.... Thanks in advance
program to create student report using java applet,read the input using text boxesand generate the grades..?
program to create student report using java applet,read the input using text boxesand generate the grades..?   sir plz give me java applet codes for above question

Ads