CSV导出代码

public String exportqdCsv() {
OutputStream os = null;
WritableWorkbook wbook = null;
try {
HttpServletResponse response = ServletActionContext
.getResponse();
// 取得输出流
os = response.getOutputStream();
// 清空输出流
response.reset();
// 设定输出文件头
response.setHeader(
"Content-Disposition",
"attachment; filename=\""
+ new String("上游客户批量修改表".getBytes("GBK"),
("ISO8859-1")) + ".csv\"");
// 定义输出类型

response.setContentType("application/msexcel");
// 建立excel文件
wbook = Workbook.createWorkbook(os);
WritableSheet wsheet = wbook.createSheet("sheet1", 0);
// WritableSheet.setColumnView(int i,int width);
// 作用是指定第i+1列的宽度,比如:
// 将第一列的宽度设为30
// sheet.setColumnView(0,30);
// wsheet.setRowView(0,10);
// 设置单元格背景颜色
// 设置字体格式

// 表头
Label label_0 = new Label(0, 0, "测试");
wsheet.addCell(label_0);

Label label_1 = new Label(1, 0, "测试1");
wsheet.addCell(label_1);

Label label_2 = new Label(2, 0, "测试2");
wsheet.addCell(label_2);

Label label_3 = new Label(3, 0, "测试3");
wsheet.addCell(label_3);
wbook.write();
} catch (Exception e) {
logger.error(e);
} finally {
if (wbook != null) {
try {
wbook.close();
} catch (Exception e) {
logger.error(e);
}
wbook = null;
}
if (os != null) {
try {
os.close();
} catch (Exception e) {
logger.error(e);
}
os = null;
}
}
return RESULT_MESSAGE;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值