R4R provide basic Jexcel Tutorials concept with
Jexcel Examples .
Through R4R you can develop Jexcel programming concept. R4R provide
Jexcel Interview Questions with answers.R4R provide Jexcel Languages study materials in easy way.
Jexcel Examples
2.1 Jexcel Basic Example
JExcel API refers as Java Excel API .JExcel
is an open source java API by sourceforge. JExcel(Java Excel API) is used
to read, write, and modify excel spreadsheets. Java developers can read data from database or xml or from any other resources
through JExcel API Java developers can read, write and modify excel spreadsheets
dynamically. We can make excel sheet in different format. We can set background
colors ,foreground colors ,we can set boards of cells etc .by using JExcel API
JExcel API allow developers to read a excel spreadsheet and modify
it as per as requirements .Jexcel can use Web based applications as well
as any Desktop based applications. We can used Jexcel with JSP and
Servlet .To make a program ( or make a excel spreadsheet ) with JExcel API we need only
JDK only. Here in this section we will covers JExcel tutorials and JExcel
Examples. We will cover also how we can make excel sheet in different formats?
JExcel Examples:-
http://r4r.co.in/java/apis/jexcel/basic/example/
JExcel Tutorials :-
http://r4r.co.in/java/apis/jexcel/basic/tutorial
JEXCEL
JExcel is the java API which helps to read ,write and modify
Excel spreadsheet. JExcel API is an open source Java library to read, write and manipulate Microsoft Excel spreadsheets .This API is very easy
to use. The API can be invoked from within a servlet, means giving access to
Excel spreadsheets over internet and intranet web applications.
Java developers can read data from database or xml or from any other resources
through JExcel API Java developers can read, write and modify excel
spreadsheets dynamically. We can make excel sheet in different format .We can
set background colors ,foreground colors ,we can set boards of cells
etc .by using JExcel API
JExcel API have wonderful features like:
-
It is used to create a workbook.
-
JExcel API helps to create a worksheet with given name.
-
This API formatted cell with bold, italic , border and
borderline etc.
-
Add label to sheet with or without formatting.
-
Add Integer to sheet with or without formatting.6.Wrap text data in Cell.
Limitations of JExcel
JExcelApi does not generate or chart, graph or macro information. This
information is however preserved when spreadsheets are copied. When adding images to a sheet, only PNG image formats are supported .
EXAMPLE
First Excel Spreadsheets Using JExcel API
In this we are going to create first example of JExcel API.then we are going to create a work space and excel sheet. To create excel spread sheet we have to create an object
of WritableWorkbook .To create it Jexcel API
provides a static method createWorkbook() of WorkBook
class .In this createWorkbook() method we have pass file name with
.xls extension.Then we have to create a sheet .For this WritableWorkbook class has a method
createSheet(String sheetname,int sheetnumner) which return type is
WritableSheet. After that store this object into a variable of WritableSheet To add some
value in cell we can use addCell(Label label)
method provided in WritableSheet class. The Label class is used to create label and add on cell. Finally write() method of
WritableWorkbook class to write on workbook and at last close the workbook.
import java.io.File;
import java.io.IOException;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
public class FirstJExcelExample {
public static void main(String[] args) {
WritableWorkbook workbook;
try {
workbook = Workbook.createWorkbook(new File("myfile.xls"));
WritableSheet sheet = workbook.createSheet("First Sheet", 0);
Label label = new Label(0, 2, "R4R JExcel API Example");
sheet.addCell(label);
workbook.write();
workbook.close();
} catch (WriteException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}