星空网 > 软件开发 > Java

java处理Excel相关笔记

      String name = file.getFilename();          name = name.replaceAll("(&|=|,)", "");      response.setHeader("Content-Disposition", "Attachment; Filename=" + name);      response.setContentType(file.getContentType());      IOUtils.copy(file.getInputStream(), response.getOutputStream());     response.flushBuffer();

      // 构建输出流      response.reset();      final String attachmentHeader = "Attachment; Filename*=utf-8''"          + URLEncoder.encode(project.getName() + ".xls", "UTF-8").replaceAll("\\+", "%20");      response.setHeader("Content-disposition", attachmentHeader);      response.setContentType("application/msexcel");      // 生成工作表      WritableWorkbook wwb = Workbook.createWorkbook(response.getOutputStream());      WritableSheet sheet = wwb.createSheet("任务列表", 1);      // 格式化文本      WritableFont font1 = new WritableFont(WritableFont.TIMES, 12, WritableFont.BOLD);      WritableCellFormat format1 = new WritableCellFormat(font1);      format1.setAlignment(jxl.format.Alignment.CENTRE);      format1.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);          // 表格大小          sheet.setColumnView(0, 20);         // 表头      sheet.addCell(new Label(0, 0, "任务名称", format1));          // 任务列表      SimpleDateFormat sdf = new SimpleDateFormat("MM/dd HH:mm");      for (int i = 1; i <= taskList.size(); i++) {        ProjectTask pt = taskList.get(i - 1);        sheet.addCell(new Label(0, i, pt.getName(), format2));       }       // 关闭输出流      wwb.write();      wwb.close();       //初始化工作表输出流      String title="工程项目导出";      response.setContentType("application/vnd.ms-excel");        response.setHeader("Content-disposition", "attachment;filename="+new String(title.getBytes("GB2312"),"ISO8859_1") +".xls");             //标题有中文必须转码 ,attachment:显示另存为对话框inline:尝试用已知关联的程序打开。      WritableWorkbook workbook;      OutputStream ouputStream = response.getOutputStream();           workbook = Workbook.createWorkbook(ouputStream);            WritableSheet sheet = workbook.createSheet("工程列表", 0);        sheet.setColumnView(0, 5);  //设置宽度           jxl.write.WritableFont wfont = new jxl.write.WritableFont(WritableFont.createFont("宋体"), 10);//设置字体      WritableCellFormat wc = new WritableCellFormat(wfont);             wc.setAlignment(Alignment.CENTRE);         // 设置居中       wc.setBackground(jxl.format.Colour.LIGHT_GREEN); // 设置单元格的背景颜色            //工作表内容 - Label label      sheet.addCell(new jxl.write.Label(0, 0,"序号",wc));             sheet.addCell(new jxl.write.Label(13, 0,"任务状态",wc));            for (int i = 1; i <= omProjectList.size(); i++) {        OmProject omProject = omProjectList.get(i-1);        sheet.addCell(new jxl.write.Number(0, i,i));         sheet.addCell(new jxl.write.Label(1, i,omProject.getAcceptDate()));               }      //关闭工作表输出流      workbook.write();      workbook.close();      ouputStream.flush();        ouputStream.close();         FileInputStream inputStream = new FileInputStream(importFile);      FileOutputStream outputStream = new FileOutputStream(filePath);      byte[] buf = new byte[1024];      int length = 0;      while ((length = inputStream.read(buf)) != -1) {        outputStream.write(buf, 0, length);      }      inputStream.close();      outputStream.flush();  Workbook workbook = Workbook.getWorkbook(new File(filePath));    Sheet[] sheets = workbook.getSheets();      if (sheets != null && sheets.length > 0) {        Sheet sheet = sheets[0];        int rowSize = sheet.getRows();                for (int j = 1; j < rowSize; j++) {        Cell[] psCells = sheet.getRow(j);                String content = psCells[k].getContents();   }

 




原标题:java处理Excel相关笔记

关键词:JAVA

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

WishPost部分物流渠道及路向价格调整情况:https://www.goluckyvip.com/news/3668.html
Shopee美妆产品主图大比拼!原来东南亚和巴西喜欢这样~:https://www.goluckyvip.com/news/3669.html
速卖通、Shopee、 Lazada三大电商平台发布双11捷报!:https://www.goluckyvip.com/news/367.html
Lazada运营分析:如何做好选品?有什么方法?:https://www.goluckyvip.com/news/3670.html
Lazada什么产品好卖?自身货源优势结合市场需求定位符合自身的产品!:https://www.goluckyvip.com/news/3671.html
东南亚本土号最大的难点是什么:https://www.goluckyvip.com/news/3672.html
从园岭新村到大梅沙海滨总站坐什么车:https://www.vstour.cn/a/363191.html
七月份适合去日本旅游吗 7月份去日本哪里好玩:https://www.vstour.cn/a/363192.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流