java excel控件_如何在Java项目中调用excel的表格控件?

看看这个例子 希望对你有帮助!

package com.cari.web.cache;

import java.io.File;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.OutputStream;

import java.util.Iterator;

import java.util.List;

import jxl.Workbook;

import jxl.write.Label;

import jxl.write.WritableCellFormat;

import jxl.write.WritableFont;

import jxl.write.WritableSheet;

import jxl.write.WritableWorkbook;

import com.sun.org.apache.xerces.internal.impl.xpath.regex.ParseException;

import com.sun.xml.internal.bind.v2.model.core.ClassInfo;

public class outecell {

public void exportClassroom(OutputStream os) throws ParseException {

try {

WritableWorkbook wbook= Workbook.createWorkbook(os); //建立excel文件

WritableSheet wsheet = wbook.createSheet("监测报表", 0); //工作表名称

//设置Excel字体

WritableFont wfont = new WritableFont(WritableFont.ARIAL, 10,

WritableFont.BOLD, false,

jxl.format.UnderlineStyle.NO_UNDERLINE,

jxl.format.Colour.BLACK);

WritableCellFormat titleFormat = new WritableCellFormat(wfont);

String[] title = { "通道名称", "特征值类型", "最大值", "最小值","平均值" };

//设置Excel表头

for (int i = 0; i < title.length; i++) {

Label excelTitle = new Label(i, 0, title[i], titleFormat);

wsheet.addCell(excelTitle);

}

/*

int c = 1; //用于循环时Excel的行号

//ClassroomService cs = new ClassroomService();

List jiancebaobiao=null;

//List list = cs.findAllClassroom(); //这个是从数据库中取得要导出的数据

Iterator it = jiancebaobiao.iterator();

while (it.hasNext()) {

ClassroomDTO crdto = (ClassroomDTO) it.next(); //对象

Label content1 = new Label(0, c, crdto.getRoomname());

Label content2 = new Label(1, c, crdto.getCapicity().toString());

Label content3 = new Label(2, c, crdto.getRoomTypeId().toString());

Label content4 = new Label(3, c, crdto.getRemark());

wsheet.addCell(content1);

wsheet.addCell(content2);

wsheet.addCell(content3);

wsheet.addCell(content4);

c++;

} */

wbook.write(); //写入文件

wbook.close();

os.close();

} catch (Exception e) {

throw new ParseException("导出文件出错", 1);

}

}

public static void main(String[] args) {

File f=new File("F://监测报表.xls");

try {

f.createNewFile();

new outecell().exportClassroom(new FileOutputStream(f));

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

2010年10月11日 10:20

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值