weixin_37604133
weixin_37604133
2017-04-19 11:20

java poi excel 咋么让地址是用户自定义的

  • excel
  • java
  • poi

@RequestMapping(value="/poii")
public String nnn(HttpServletResponse response1) throws Exception {
HttpServletResponse response=new HttpServletResponseWrapper(response1);
ApplicationContext ac = new ClassPathXmlApplicationContext(
"applicationContext.xml");

    ProductServiceIn bean = ac.getBean("ProductService",
            ProductServiceIn.class);
    List<Map<String, Object>> list = bean.selectProduct();

    response.addHeader("Content-Dispositio","attachment;filename="+"name");
    Workbook wb = new HSSFWorkbook();

    Sheet sheet = wb.createSheet("product");
    for (int i = 0; i < list.size(); i++) {
        Row row = sheet.createRow(i);
        Map<String, Object> map = list.get(i);
        Set<String> set = map.keySet();
        Iterator<String> key = set.iterator();
        int j = 0;
        while (key.hasNext()) {
            String str = key.next();
            Cell cell = row.createCell(j);
            cell.setCellValue(map.get(str).toString());
            j++;
        }

    }

    wb.write(new FileOutputStream(""));
    return "test";
}
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答

为你推荐