JXL创建Excel文件

 1 package poi;
 2 
 3 import java.io.File;
 4 import jxl.Workbook;
 5 import jxl.write.Label;
 6 import jxl.write.WritableSheet;
 7 import jxl.write.WritableWorkbook;
 8 /*
 9  * poi 
10  * jxl 创建excel文件,并且添加数据
11  * */
12 public class JxlExpExcel {
13 
14     public static void main(String[] args) {
15     //表头
16     String[] title = {"name", "age", "sex"};
17     //创建excel文件
18     File file = new File("e:/jxl.xls");
19     try {
20         file.createNewFile();
21         //创建工作薄
22         WritableWorkbook workbook = Workbook.createWorkbook(file);
23         //创建sheet
24         WritableSheet sheet = workbook.createSheet("sheet1", 0);
25         Label label= null;
26         //填写表头
27         for (int i = 0; i < title.length; i++) {
28             //label参数 列,行,内容
29             label = new Label(i, 0, title[i]);
30             //将内容填写到单元格中
31             sheet.addCell(label);
32         }
33         //添加数据
34         for (int i = 1; i < 10; i++) {
35             label = new Label(0, i, "user"+i );
36             sheet.addCell(label);
37             label = new Label(1, i, 12+i+"" );
38             sheet.addCell(label);
39             label = new Label(2, i, "M" );
40             sheet.addCell(label);
41             label = new Label(3, i, "d" );
42             sheet.addCell(label);
43             
44         }
45         //写入数据
46         workbook.write();
47         //关闭工作薄
48         workbook.close();
49         
50         
51     } catch (Exception e) {
52         // TODO Auto-generated catch block
53         e.printStackTrace();
54     }
55 
56     }
57 
58 }

 

转载于:https://www.cnblogs.com/budong/p/4453360.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值