java用jxl包导出Excel的例子


/**
* 导出信息
* @date 2011-6-10
*/
public void exportMatchangeExcel(QueryVo queryVo) {
WritableWorkbook workbook = null;
try{
HttpServletResponse response = ServletActionContext.getResponse();
OutputStream outPutS = response.getOutputStream();
response.resetBuffer();
response.setHeader("Content-Type", "application/force-download;");
//中文名:name = new String(name.getBytes("GBK"),"UTF-8");
response.setHeader("Content-disposition", "attachment;filename=matchange--"+FDateFormat.GetShortDate()+".xls");
response.setContentType("application/excel");
workbook = Workbook.createWorkbook(outPutS);

WritableSheet sheet = workbook.createSheet("仓库物料进出库信息", 0);
String title[] = {"序号","物料号"};

Label label = null;
/** 字体设置 */
WritableFont headerFont = new WritableFont(WritableFont.ARIAL, 12,
WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE,
Colour.BLACK);
/** 格式 */
WritableCellFormat headerFormat = new WritableCellFormat(headerFont);
headerFormat.setAlignment(Alignment.CENTRE);
headerFormat.setBorder(Border.ALL, BorderLineStyle.THIN,
Colour.BLACK);

WritableFont titleFont = new WritableFont(WritableFont.ARIAL, 10,
WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE,
Colour.BLACK);
WritableCellFormat titleFormat = new WritableCellFormat(titleFont);
titleFormat.setAlignment(Alignment.CENTRE);
titleFormat.setBorder(Border.ALL, BorderLineStyle.THIN,
Colour.BLACK);

WritableFont columnNameFont = new WritableFont(WritableFont.ARIAL,
10, WritableFont.NO_BOLD, false,
UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
WritableCellFormat columnNameFormat = new WritableCellFormat(
columnNameFont);
columnNameFormat.setAlignment(Alignment.CENTRE);
columnNameFormat.setBorder(Border.ALL, BorderLineStyle.THIN,
Colour.BLACK);

WritableCellFormat columnNameFormatLeft = new WritableCellFormat(
columnNameFont);
columnNameFormatLeft.setAlignment(Alignment.LEFT);
columnNameFormatLeft.setBorder(Border.ALL, BorderLineStyle.THIN,
Colour.BLACK);

sheet.mergeCells(0, 0, 13, 0);//第一个参数:开始列,第二个参数:开始行,第三个参数:结束列,第四个参数:结束行,
label = new Label(0, 0, "[仓库物料进出库信息列表--"+FDateFormat.GetLongDate()+"]", headerFormat);
sheet.addCell(label);

int index=0;//行索引
int row = 1;//行数
int column = 0;
for (int i = 0; i < title.length; i++) {
label = new Label(column++, 1, title[i], titleFormat);
sheet.addCell(label);
}

jxl.write.Number labelNF = null;

if(dsbfMatchangeList != null){
for(KdDsbfMatchangeVo dsbfMatchangeVo : dsbfMatchangeList){
++index;
row++;
column = 0;

//序号
labelNF = new jxl.write.Number(column++, row,index,columnNameFormat);
sheet.addCell(labelNF);

//物料号
label = new Label(column++, row,物料号,columnNameFormat);
sheet.addCell(label);
}
}
column = 0;

/* 设置长度 */
sheet.setColumnView(column++, 5 );//0
sheet.setColumnView(column++, 12);//1

// 写入数据
workbook.write();
}catch(Exception e){
e.printStackTrace();
}finally{
try {
workbook.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值