Home Answers Viewqa Java-Beginners Using HSSF 3.5 to READ XLS

 
 


Henrik
Using HSSF 3.5 to READ XLS
1 Answer(s)      3 years and 9 months ago
Posted in : Java Beginners

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 Pages:
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
Java Programming: Section 3.5
Section 3.5 The if Statement THE FIRST OF THE TWO BRANCHING... with it.) As an example of using if statements, lets suppose that x, y, and z are variables... in the output.) An outline of the process is Read the user's input
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 "
xls to js using javascript
xls to js using javascript  ![how can we convert a xls file in js file using javascript][1
hibernate 3.5 maven
In this section, you will learn how to a generate simple java Hibernate 3.5 project using Maven project builder
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
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
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
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
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
XLS JDBC Example
.style1 { background-color: #FFFFCC; } XLS JDBC XlS JDBC driver is used to access xls file from java application. It is read only JDBC driver. You can only do a SELECT * FROM xls file statement. The other SQL command
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
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
Java code for conversion between .xls and .xlsx or vice versa - Development process
is developed using Servlets and JSP. My project allows clients to Upload / Download MS Excel sheets. The problem is I'm using MS Excel 2003 (.xls format...Java code for conversion between .xls and .xlsx or vice versa  I've
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
How to read excel2007 file - JSP-Servlet
How to read excel2007 file  Dear sir , I am able to read a excel 97-2003(.xls)files using apache poi.But for 2007(.xlsx)files to read using poi its nt possible.So please help me sir.... Thanks ....  Hi
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... to. // FileOutputStream fos = null; try { fos = new FileOutputStream(new File("xls
Apache HSSF Jar file location
Apache HSSF Jar file location  where can i get jar files for apache hssf
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
Java sdk/java poi hssf code to creat excel with folder structure,( i,e folders, subfolders and childrens )
Java sdk/java poi hssf code to creat excel with folder structure,( i,e folders... . i need some help in getting folder structure using this java . Folder... HSSF lines are half done, pls bear with that !! if(topFolders.size() <
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
read and write a file using javascript
read and write a file using javascript  How to read and write a file using javascript
Read bufferedreader
Read bufferedreader  Tell me the example of Read file using bufferedreader. Thanks   Read the tutorial Reading file using BufferedReader class. Thanks
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
xl read
xl read  hi, i have read excel sheet data using poi api and printed on console, now i have to store the same data which is printed on the console...: Insert excel file data into database Read Excel File
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 RFID data
Read RFID data  how to read RFID data using java
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
read xml elements
read xml elements  i want read xml data using sax parser in java. but is there any classes or methods to read xml elements
read xml elements
read xml elements  i want read xml data using sax parser in java. but is there any classes or methods to read xml elements
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 unread emails
How to read unread emails  How to read unread emails from account using POP3
Overview of the POI APIs
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... format using pure Java. In short, we can read and write MS Excel files using Java
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 Issue itext
Read Issue itext  Hello, I m using itext to read data from pdf file... In variable whole page data there... so i want to read data line by line so is der any way to read line by line data using itext so dat i can process
Read Issue itext
Read Issue itext  Hello, I m using itext to read data from pdf file... In variable whole page data there... so i want to read data line by line so is der any way to read line by line data using itext so dat i can process
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
JSP/Servlet to read and update Excel
JSP/Servlet to read and update Excel  Hi Team, My requirement is based upon my input(name) value via one jsp, the program(jsp/servlet) should fetch all the column values which is related to my input(name) from Excel(.xls
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
Error in reading Excel data using jsp
Error in reading Excel data using jsp  ERROR while executing bellow code:java.io.IOException: Invalid header signature; read 576460838270094160.... ---------- java.io.IOException: Invalid header signature; read 576460838270094160, expected
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 from a window - Java Beginners
Read from a window  HI, I need to open a website and read the content from the site using Java script. Please suggest. Thanks
read data from Excel sheet
read data from Excel sheet  Hi, How to read data from an excel sheet using JSP. Thank you
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
Sending email with read and delivery requests
Sending email with read and delivery requests  Hi there, I am sending emails using JavaMail in Servlets on behalf of a customer from the website, and I'm having difficulty understanding how to implement, read and delivery