• SpringMVC 导入导出Excel文件


    /**
      * 下载Excel模板 创建一个新的文件用于下载,创建的文件放在缓存中
      *
      * @param request
      * @param response
      */
     /*
      * @RequestMapping("/get_Sb_yys_sgyyqk_cj") public void
      * get_Sb_yys_sgyyqk_cj(HttpServletRequest request, HttpServletResponse
      * response) { try { // 输出流 OutputStream os = new
      * FileOutputStream(filePath); // 工作区 HSSFWorkbook wb = new HSSFWorkbook();
      * // 工作区名 HSSFSheet sheet = wb.createSheet("烟叶税采集模板");
      * sheet.autoSizeColumn(1, true); // 设置自适应宽度,高版本的POI才有用
      *
      * // 创建表头 HSSFRow row = sheet.createRow(0); row.setHeight((short) 600);//
      * 设定行的高度
      *
      * // 设置单元格内容格式 HSSFCellStyle style = wb.createCellStyle();
      * style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 水平布局:居中
      * style.setWrapText(true);// 自动换行
      *
      * // 设置单元格内容格式 HSSFCellStyle style1 = wb.createCellStyle(); //
      * 测试发现excel不支持精确到秒的日期格式,换成日期就够 //
      * style1.setDataFormat(HSSFDataFormat.getBuiltinFormat
      * ("yyyy/MM/dd hh:mm:ss"));
      * style1.setDataFormat(HSSFDataFormat.getBuiltinFormat("yyyy-MM-dd"));
      * style1.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 水平布局:居中
      * style1.setWrapText(true);// 自动换行
      *
      * HSSFCell cell = row.createCell(0); cell.setCellStyle(style);
      * cell.setCellValue("社会信用代码"); sheet.autoSizeColumn((short) 1); //
      * sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 2)); // //
      * 合并单元格(startRow,endRow,startColumn,endColumn)
      *
      * cell = row.createCell(1); cell.setCellStyle(style);
      * cell.setCellValue("收购数量");
      *
      * cell = row.createCell(2); cell.setCellStyle(style);
      * cell.setCellValue("单价");
      *
      * cell = row.createCell(3); cell.setCellStyle(style);
      * cell.setCellValue("烟叶等级代码"); sheet.autoSizeColumn((short) 3); // 调整第3列宽度
      *
      * cell = row.createCell(4); cell.setCellStyle(style1);
      * cell.setCellValue("收购日期(数据格式为yyyy-MM-dd,如:2017-12-11表示2017年12月11日)");
      * sheet.autoSizeColumn((short) 4); // 调整第四列宽度
      *
      * // 写文件 wb.write(os); // 关闭输出流 os.close(); download(filePath, response); }
      * catch (Exception e) { e.printStackTrace(); } }
      *//**
      * 此方法可以提出去公用
      *
      * @param path
      * @param response
      */
     /*
      * private void download(String path, HttpServletResponse response) { try {
      * // path是指欲下载的文件的路径。 File file = new File(path); // 取得文件名。 String filename
      * = file.getName(); // 以流的形式下载文件。 InputStream fis = new
      * BufferedInputStream(new FileInputStream(path)); byte[] buffer = new
      * byte[fis.available()]; fis.close(); // 清空response response.reset(); //
      * 设置response的Header response.addHeader("Content-Disposition",
      * "attachment;filename=" + new String(filename.getBytes()));
      * response.addHeader("Content-Length", "" + file.length()); OutputStream
      * toClient = new BufferedOutputStream( response.getOutputStream());
      * response.setContentType("application/vnd.ms-excel;charset=utf-8");
      * toClient.write(buffer); toClient.flush(); toClient.close();
      * if(file.exists()){ //删除缓存的文件 file.delete(); } } catch (IOException ex) {
      * ex.printStackTrace(); } }
      */

  • 相关阅读:
    使用Jenkins进行Android自动打包,自定义版本号等信息【转】
    Android config Android.mk parameter
    cocos2D-X config external library
    OpenCV Install OpenCV with Visual Studio
    cmake make library
    cocos2D-X create image sprite solution
    cocos2d-X 打开一个文件是否跨平台
    android use NDK api call AssetManager
    android add asset file
    android error: cannot use ‘throw’ with exceptions disabled
  • 原文地址:https://www.cnblogs.com/zhonglihai/p/7527416.html
Copyright © 2020-2023  润新知