01.
package
com.java.myapp;
02.
03.
import
java.io.File;
04.
import
jxl.Workbook;
05.
import
jxl.write.Label;
06.
import
jxl.write.WritableSheet;
07.
import
jxl.write.WritableWorkbook;
08.
09.
public
class
MyClass {
10.
11.
public
static
void
main(String[] args) {
12.
13.
14.
try
{
15.
String fileName =
"C:\\java\\myExcel.xls"
;
16.
17.
WritableWorkbook workbook = Workbook.createWorkbook(
new
File(fileName));
18.
19.
20.
WritableSheet ws1 = workbook.createSheet(
"mySheet1"
,
0
);
21.
ws1.addCell(
new
Label(
0
,
0
,
"Data 1"
));
22.
ws1.addCell(
new
Label(
0
,
1
,
"Data 2"
));
23.
ws1.addCell(
new
Label(
0
,
2
,
"Data 3"
));
24.
25.
26.
WritableSheet ws2 = workbook.createSheet(
"mySheet2"
,
1
);
27.
ws2.addCell(
new
Label(
0
,
0
,
"Data 4"
));
28.
ws2.addCell(
new
Label(
0
,
1
,
"Data 5"
));
29.
ws2.addCell(
new
Label(
0
,
2
,
"Data 6"
));
30.
31.
workbook.write();
32.
workbook.close();
33.
34.
System.out.println(
"Excel file created."
);
35.
36.
}
37.
catch
(Exception e) {
38.
e.printStackTrace();
39.
}
40.
41.
}
42.
43.
}