Professional Documents
Culture Documents
Excel and Java
Excel and Java
(http://www.vogella.com)
Downloads (http://www.vogella.com/downloads/) Books (http://www.vogella.com/books/) Company (http://www.vogella.com/company/)
Excel and Java - Read and Write Excel with Online Training
(https://learn.vogella.c
Java - Contact
Donate (http://www.vogella.com/support.html) Tutorial
us (http://www.vogella.com/contact.html)
QUICK LINKS
Lars Vogel (c) 2008, 2016 vogella GmbH – Version 1.4, 29.08.2016
15 OCT - RCP
Training
Table of Contents
(http://www.vogell
1. Installation vogella Training
2. Create an Excel Spreadsheet (http://www.vogell
This article demonstrate how to create and how to read Excel files
with the Java Excel API.
1. Installation
Download the Java Excel library (http://jexcelapi.sourceforge.net/) from the
webpage
To use this library in your Java program add the lib jxl.jar to your classpath in
your project. See Changing classpath in Eclipse
(http://www.vogella.com/tutorials/Eclipse/article.html#classpath).
http://www.vogella.com/tutorials/JavaExcel/article.html 1/5
8/1/2018 Excel and Java - Read and Write Excel with Java - Tutorial
JAVA
package writer;
Tutorials (http://www.vogella.com/tutorials/) Training (http://www.vogella.com/training/) Consulting (http://www.vogella.com/consulting/)
Search
workbook.write();
workbook.close();
}
http://www.vogella.com/tutorials/JavaExcel/article.html 2/5
8/1/2018 Excel and Java - Read and Write Excel with Java - Tutorial
WriteException,
Tutorials (http://www.vogella.com/tutorials/) Training
RowsExceededException {
(http://www.vogella.com/training/) Consulting (http://www.vogella.com/consulting/)
Search
// Write a few number
(http://www.vogella.com)
for (int i = 1; i < 10; i++) {
Downloads (http://www.vogella.com/downloads/) Books (http://www.vogella.com/books/)
// First column Company (http://www.vogella.com/company/) Online Training
addNumber(sheet, 0, i, i + 10); (https://learn.vogella.c
// Second column
Donate (http://www.vogella.com/support.html) Contact us (http://www.vogella.com/contact.html)
addNumber(sheet, 1, i, i * i);
QUICK LINKS
}
// Lets calculate the sum of it 15 OCT - RCP
StringBuffer buf = new StringBuffer(); Training
buf.append("SUM(A2:A10)"); (http://www.vogell
Formula f = new Formula(0, 10, buf.toString());
vogella Training
sheet.addCell(f);
buf = new StringBuffer(); (http://www.vogell
buf.append("SUM(B2:B10)"); vogella Books
f = new Formula(1, 10, buf.toString()); (http://www.vogell
sheet.addCell(f);
SHARE
// now a bit of text
for (int i = 12; i < 20; i++) {
// First column
addLabel(sheet, 0, i, "Boring text " + i);
// Second column
addLabel(sheet, 1, i, "Another text");
}
}
I assume that the code is pretty much self-explaining. I tried to add lots of
comments to make it easier to understand.For more complex examples have a
look at the excellent documentation of the Java Excel API which is also part of
the distribution.
http://www.vogella.com/tutorials/JavaExcel/article.html 3/5
8/1/2018 Excel and Java - Read and Write Excel with Java - Tutorial
JAVA
package reader;
Tutorials (http://www.vogella.com/tutorials/) Training (http://www.vogella.com/training/) Consulting (http://www.vogella.com/consulting/)
Search
if (type == CellType.NUMBER) {
System.out.println("I got a number "
+ cell.getContents());
}
}
}
} catch (BiffException e) {
e.printStackTrace();
}
}
I assume that the code is pretty much self-explaining. I tried to add lots of
comments to make it easier to understand.For more complex examples have a
look at the excellent documentation of the Java Excel API which is also part of
the distribution.
http://www.vogella.com/tutorials/JavaExcel/article.html 4/5
8/1/2018 Excel and Java - Read and Write Excel with Java - Tutorial
Support free content Questions and Tutorial & code license Get the source code
Tutorials (http://www.vogella.com/tutorials/) Training (http://www.vogella.com/training/)
discussion Consulting (http://www.vogella.com/consulting/)
Search
(http://www.vogella.com)
Downloads (http://www.vogella.com/downloads/) Books (http://www.vogella.com/books/) Company (http://www.vogella.com/company/) Online Training
(http://www.vogella.com/support.html) (http://www.vogella.com/license.html)
(http://www.vogella.com/code/index.html)(https://learn.vogella.c
(http://www.vogella.com/contact.html)
5. Links
Donate (http://www.vogella.com/support.html) and
Contact Literature
us (http://www.vogella.com/contact.html)
QUICK LINKS
5.1. Java Excel Resources 15 OCT - RCP
Training
Java Excel API - Homepage (http://jexcelapi.sourceforge.net)
(http://www.vogell
vogella Training
5.2. vogella GmbH training and consulting support (http://www.vogell
vogella Books
TRAINING SERVICE & SUPPORT (http://www.vogell
(http://www.vogella.com/training/) (http://www.vogella.com/consulting/)
SHARE
The vogella company provides The vogella company offers expert
comprehensive training and consulting
education services (http://www.vogella.com/consulting/)
(http://www.vogella.com/training/) from services, development support and
experts in the areas of Eclipse RCP, coaching. Our customers range from
Android, Git, Java, Gradle and Fortune 100 corporations to
Spring. We offer both public and individual developers.
inhouse training. Whichever course
you decide to take, you are
guaranteed to experience what
many before you refer to as “The
best IT class I have ever attended”
(http://www.vogella.com/training/).
Version 1.4
Last updated 2018-02-13 12:00:43 +01:00
http://www.vogella.com/tutorials/JavaExcel/article.html 5/5