java 操作 excel

JgForm jgForm = (JgForm) form;
JgService js = new JgService();
String taskno1 = jgForm.getTaskno();
System.out.print("taskno=" + taskno1);
String prodcate = jgForm.getProdCate();
Long chanpinxinxiId = jgForm.getChanPinxinxi_ID();
Long entId = jgForm.getEnt_id();
String districtcode = jgForm.getDistrictCode();
String orgcode = jgForm.getOrgCode();
String insresult = jgForm.getInsResult();
String insorg = jgForm.getInsOrg();

List list1 = js.findAllDaochuJg(taskno1, prodcate, chanpinxinxiId,
entId, districtcode, orgcode, insresult, insorg);
System.out.println("list long=" + list1.size());

HSSFWorkbook workbook = new HSSFWorkbook();// 建立新HSSFWorkbook对象
HSSFSheet sheet = workbook.createSheet("结果信息");

if (list1 == null) {
list1 = new ArrayList();
}

ChouJg jg = null;
HSSFRow row01 = null;
for (int i = 0; i < list1.size(); i++) {
jg = (ChouJg) list1.get(i);
row01 = sheet.createRow((short) i);// 建立新行
HSSFCell cell1 = row01.createCell((short) 1);// 建立新cell
System.out.println("-------id----" + jg.getJgid());
cell1.setCellValue(jg.getJgid());
HSSFCell cell2 = row01.createCell((short) 2);// 建立新cell
cell2.setCellValue(jg.getTaskno());
HSSFCell cell3 = row01.createCell((short) 3);// 建立新cell
cell3.setCellValue(jg.getBrand());

}

try {
ServletOutputStream out = response.getOutputStream();

/* FileOutputStream fileOut = new FileOutputStream("workbook.xls");
workbook.write(fileOut);
fileOut.flush();
fileOut.close();
File file = new File("workbook.xls"); */
//
// ByteArrayOutputStream af = new ByteArrayOutputStream();
// af.writeTo(f);
// af.toByteArray();
//
response.setContentType("application/msexcel");
response.setHeader("Content-Disposition","attachment; filename=ddd.xls");
response.setCharacterEncoding("utf-8");
// out.write(getBytesFromFile(file));
//out.write(workbook.getBytes());
workbook.write(out);
System.out.println("sdffffffffff====");
out.flush();
out.close();

/* response.setContentType("application/msexcel");
response.setHeader("Content-Disposition",
"attachment; filename=ss.xls");
FileInputStream stream = new FileInputStream(file);
byte[] buffer = new byte[1024];
int len = 0;
while ((len = stream.read(buffer)) > 0) {
out.write(buffer, 0, len);
}
System.out.println("sdfhhhsdfs=");
out.flush();
out.close();*/
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值