Sunday Feb 05
Move
Display 0 | 5 | 10 | 15 Stories

Gadget

Topics
Top Story

Waterproof LCD for Bathrooms

Waterproof LCD for Bathrooms

  Have you been wishing for a waterproof LCD TV for use in you bathroom? Good for you, Vu has launched...

PlayStation 4 Release date and Features

PlayStation 4 Release date and Features

  The next generation PlayStation may arrive sooner than we think.. maybe even in 2009! But based...

XBox 720 Release date and Features

  In an interview with the head of Microsoft’s Interactive Entertainment Business division, Peter...

Wii 2 Release date and Features

  Nintendo are selling Wii’s faster than stores can stock them and some may believe that they...

PSP 2 Release date and Features

  The PS2P should be available in 2009 - 10, to compete with the upgraded Nintendo DS. Some features...

Upcoming Game Consoles

Gadget

Move
Display 0 | 5 | 10 | 15 Stories

Software Tutorials

Topics
Top Story

How to Enable / Disable Autoformat in word 2007

How to Enable / Disable Autoformat in word 2007

  The interface of Office 2007 does does not offer an intuitive tool to enable or disable the autocorrect...

How to use old MSN Messenger without upgrading

  If you dont like the newer version of MSN Live Messenger and want to use the old MSN Messenger...

Software Tutorials

 

Move
Display 0 | 5 | 10 | 15 Stories

General

Topics
Top Story

PRAM model of Parallel Computation

PRAM model of Parallel Computation

  A PRAM consists of a control unit, global memory, and an unbounded set of processors,each with its...

The Crisis of Credit Visualized

A Vimeo video by Jonathan Jarvis attempting to visually explain the credit crisis -   The Crisis...

How to carry money while travelling

If you are planning to go abroad for any purpose, like higher studies, tourism or business purpose,...

How to call from US to india

  There are many ways to call back to india You can take a sim card from the Matrix company and...

Translation of source code to object module : The Preprocessor Compilation Process

The preposessor (We'll be talking of the C preprocessor) is a seperate program invoked by the compiler...

Virtua Kitchen - The Kitchen Operating System

What is a Synergistic Processing Element / SPE

What is a Power Processor Element / PPE

What is the Element Interconnect Bus / EIB

What is the Cell Architecture

Why use Automated Testing Tools

What is the Software Testing Life Cycle (STLC)

What is Software Testing

AudioSurf - Ride Your Music !

Ubuntu 8.10 is out!

Move
Display 0 | 5 | 10 | 15 Stories

Programming

Topics
Top Story

Code for Writing a xlsx file in java

Here is a small code to write xlsx file though java code.    You may need to include some of...

Code for Reading a xlsx file in java

Here is a small code to read xlsx file thoug java code.    You may need to include some of the...

How to read and write data from socket in java

   ServerSocket serverSocket=new ServerSocket(port);  // The below statement will wait for the...

Producer Consumer Problem in C using Semaphores and Shared Memory

  The classic bounded-buffer problem can be implemented using a variety of synchronization mechanisms....

Common Intermediate Language

Common Intermediate Language (formerly called Microsoft Intermediate Language or MSIL) is the lowest-level...

Common Type System in C#

Common Language Runtime

A Quick Introduction to C# Features

Code for updating database using hibernate framework in java

Conversion of int to byte and vice versa

Web Crawler in Python

Neural Network in Python

Programming

Move
Display 0 | 5 | 10 | 15 Stories

Graphics

Topics
Top Story
Move
Display 0 | 5 | 10 | 15 Stories

Linux

Topics
Top Story

Linux

 

Move
Display 0 | 5 | 10 | 15 Stories

Web

Topics
Top Story

What is Kosmix

  I am guessing that you looked up the term ' What is Kosmix ' on google after hearing somewhere about...

What is a meta tag

  There was a time when I didnt know of Meta tags myself. I'm glad I do now as they have really helped...

Why some search results have no description

  Before I go on to explain why some search results have no description , I woud like to state that...

What is the Facebook Bill of Rights

Have you also been wondering what the facebook bill of rights is? Here is the short answer to the popular...

The Fastest Safari Browser

  Apple has announced the public beta of Safari 4 for Macintosh and Windows PCs, which is the fastest...

Web

Move
Display 0 | 5 | 10 | 15 Stories

Games

Topics
Top Story

Games

 

Move
Display 0 | 5 | 10 | 15 Stories

Windows

Topics
Top Story

Windows

 

Code for Reading a xlsx file in java

(10 votes, average: 4.60 out of 5)





Here is a small code to read xlsx file thoug java code. 

 

You may need to include some of the jar files like

  • xmlbeans-2.3.0.jar
  • dom4j-1.1.jar
  • poi-ooxml-schemas-3.6-20091214.jar
  • poi-ooxml-3.6-20091214.jar
  • poi-3.6-20091214.jar

You can google it and download and include it along with the below code.

You have to include a simple xlsx file with some values in it (string values) and run the code.  This code will fetch the values and print it on the screen.

 


import org.apache.poi.xssf.usermodel.XSSFWorkbook; 

import org.apache.poi.xssf.usermodel.XSSFSheet;

import org.apache.poi.xssf.usermodel.XSSFCell;

import org.apache.poi.xssf.usermodel.XSSFRow;

import java.util.Iterator;

import java.io.*;

public class Main {

 

 

    public void ReadSheet() throws Exception

    {

        String filename = "book1.xlsx";

        FileInputStream fis = null;

        try {

            fis = new FileInputStream(filename);

            

            XSSFWorkbook workbook = new XSSFWorkbook(fis);

            XSSFSheet sheet = workbook.getSheetAt(0);

            Iterator rows = sheet.rowIterator();

            int number=sheet.getLastRowNum();

            System.out.println(" number of rows"+ number);

            while (rows.hasNext())

            {

 

                XSSFRow row = ((XSSFRow) rows.next());

                Iterator cells = row.cellIterator();

                while(cells.hasNext())

                {

                    XSSFCell cell = (XSSFCell) cells.next();

                    String Value=cell.getStringCellValue();

                    System.out.println(Value);

                }

             }

        } catch (IOException e) {

            e.printStackTrace();

        } finally {

            if (fis != null) {

                fis.close();

            }

        }

       

    }

 

 

    public static void main(String[] args) {

 

        Main object=new Main();

        try{

        object.ReadSheet();

 

        }catch(Exception e)

        {

            e.printStackTrace();

        }

}

 

}

 

 

Similarly you can do for the numeric cells. Or i will paste a different code for it. Leave a comment if you need some help.



Add this page to your favorite Social Bookmarking websites
Reddit! Del.icio.us! Google! Live! Facebook! Slashdot! Technorati! StumbleUpon! Spurl! Furl! Yahoo! Squidoo! Ask! DZone! Free Joomla PHP extensions, software, information and tutorials.



Comments

avatar mehdi
0
 
 
think's it's work but when a use a big xlsx file a java heap space exception
B
i
u
Quote
Code
List
List item
URL
Name *
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar metin
0
 
 
have you confirmed that?
if yes,can you give info about the sheet
thx in advance
B
i
u
Quote
Code
List
List item
URL
Name *
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar Ebosis
0
 
 
is there any options to read xls files with this jars ??
B
i
u
Quote
Code
List
List item
URL
Name *
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar Kate
0
 
 
very nice example ! Thanks!
B
i
u
Quote
Code
List
List item
URL
Name *
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar sambit
0
 
 
java.lang.NoClassDefFound Error: org/apache/poi/ss/formula/udf/UDFFinder i get thi exception but i dont find any jar fiel containing this class file ..... :(
B
i
u
Quote
Code
List
List item
URL
Name *
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar shail
0
 
 
Thanks for such a good example.............. :)
B
i
u
Quote
Code
List
List item
URL
Name *
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar Sajeev
0
 
 
Will this code work for xlsx file which is encrypted in MAC OS? I have a problem with it. I have an xlsx file which is created and protected in MAC OS. When I try to read it through java program in windows, it breaks with the following exception......... Can you please help me here?

java.lang.RuntimeExceptio n: Buffer underrun - requested 2 bytes but 0 was available
at org.apache.poi.poifs.filesystem.ODocumentInputS tream.checkAvaliable(ODocumentInputS tream.java:192)
at org.apache.poi.poifs.filesystem.ODocumentInputS tream.readUShort(ODocumentInputS tream.java:293)
B
i
u
Quote
Code
List
List item
URL
Name *
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar Alvaro
0
 
 
Thanks. It works for me.
B
i
u
Quote
Code
List
List item
URL
Name *
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar Manick
0
 
 
This one is nice...but can u paste some different code for this ? thnks in advance...
B
i
u
Quote
Code
List
List item
URL
Name *
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar Arijit Nag
0
 
 
* xmlbeans-2.3.0.jar
* dom4j-1.1.jar
* poi-ooxml-schem as-3.6-20091214.jar
* poi-ooxml-3.6-20091214.jar
* poi-3.6-20091214.jar

required ?
B
i
u
Quote
Code
List
List item
URL
Name *
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar pawan
0
 
 
Hi can you please paste the code for reading the numeric values as string in my programme.
B
i
u
Quote
Code
List
List item
URL
Name *
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar Rudresh
0
 
 
Thanks a lot...
B
i
u
Quote
Code
List
List item
URL
Name *
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
B
i
u
Quote
Code
List
List item
URL
Name *
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment

Tag Cloud

Login Form