jxl例子

public class ExcelReport {
public void createExcel(OutputStream os ,List<Book> list) throws Exception{
WritableWorkbook wwb = Workbook.createWorkbook(os);
WritableSheet sheet = wwb.createSheet("图书清单", 0);
//设置标题格式
WritableCellFormat wcf = new WritableCellFormat();
wcf.setAlignment(Alignment.CENTRE);
wcf.setBackground(jxl.format.Colour.SEA_GREEN);
sheet.addCell(new Label(0, 0, "图书编号",wcf));
sheet.addCell(new Label(1, 0, "图书名称",wcf));
sheet.addCell(new Label(2, 0, "图书作者",wcf));
sheet.addCell(new Label(3, 0, "图书价格",wcf));
sheet.addCell(new Label(4, 0, "图书数量",wcf));
sheet.addCell(new Label(5, 0, "出版社",wcf));
for(int i=1;i<list.size();i++){
sheet.addCell(new Label(0,i,list.get(i).getBookId()));
sheet.addCell(new Label(1,i,list.get(i).getBookName()));
sheet.addCell(new Label(2,i,list.get(i).getAuthor()));
sheet.addCell(new Label(3,i,list.get(i).getPrice()));
sheet.addCell(new Label(4,i,list.get(i).getCount()));
sheet.addCell(new Label(5,i,list.get(i).getPublish()));
}
wwb.write();
wwb.close();
os.close();
}
}

public class Test {

public static void main(String[] args) throws Exception {
List list = bulidList();
OutputStream os = new FileOutputStream("d:\\test2.xls");
ExcelReport excel = new ExcelReport();
excel.createExcel(os, list);
}
public static List bulidList(){
List list = new ArrayList();

for(int i=0;i<10;i++){
Book bo = new Book();
bo.setBookId("00"+i);
bo.setAuthor("小"+i);
bo.setBookName("第"+i+"集");
bo.setCount(i+"本");
bo.setPrice("10"+i);
bo.setPublish("出版社"+i);
list.add(bo);
}

return list;
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值