• js导出excel


     js代码:

    function tableToExcelesMethod(){
                  
                $.ajax({    
                     "url" : "communityexcelupes.do",    
                     "type" : "POST",
                     "data" : {},     
                     "success" : function(data) {
                         if(data!=null && data!=""){
                             f_success_alert();//成功提示方法                      
                         }
                        
                    }  
                });
            }


    java代码:

    @RequestMapping(value = "/communityexcelupes.do") @ResponseBody public String importExpes(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException{ String re=null; request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); response.setContentType("application/x-download"); long time=System.currentTimeMillis(); String fileName = "D:"+File.separator+"FQCAPP"+File.separator+"htlsap"+File.separator+"PRD"+File.separator+"fqc"+File.separator+"DetailedList(Chinese)"+time+".xls"; //fileName = URLEncoder.encode(fileName, "UTF-8"); response.addHeader("Content-Disposition", "attachment;filename=" + fileName); HSSFWorkbook wb = new HSSFWorkbook(); // 第二步:创建一个Sheet页 HSSFSheet sheet = wb.createSheet("Sheet1"); sheet.setDefaultRowHeight((short) (2 * 256));//设置行高 sheet.setColumnWidth(0, 4000);//设置列宽 sheet.setColumnWidth(1,5500); sheet.setColumnWidth(2,5500); sheet.setColumnWidth(3,5500); sheet.setColumnWidth(11,3000); sheet.setColumnWidth(12,3000); sheet.setColumnWidth(13,3000); HSSFFont font = wb.createFont(); font.setFontName("宋体"); font.setFontHeightInPoints((short) 16); HSSFRow row = sheet.createRow(0); HSSFCell cell = row.createCell(0); cell.setCellValue("参考号"); cell = row.createCell(1); cell.setCellValue("工厂"); cell = row.createCell(2); HSSFRow rows; HSSFCell cells; List<InspectionListFiveLinkedRelationships> page = inspectionListFiveLinkedRelationshipService.getFiveLinkedDataByPageNewes(param); for(int i=0;i<page.size();i++){ rows = sheet.createRow(i+1); // 第四步:在该行创建一个单元格 cells = rows.createCell(0); // 第五步:在该单元格里设置值 if(page.get(i).getBarcode()!=null){ cells.setCellValue(page.get(i).getBarcode()); }else{ cells.setCellValue(""); } cells = rows.createCell(1); if(page.get(i).getPlnt()!=null){ cells.setCellValue(page.get(i).getPlnt()); }else{ cells.setCellValue(""); } cells = rows.createCell(2); } FileOutputStream outputStream; try { outputStream = new FileOutputStream(fileName); wb.write(outputStream); outputStream.flush(); outputStream.close(); re="DetailedList(Chinese)"+time+".xls"; } catch (FileNotFoundException e) { System.err.println("获取不到位置"); e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return re; }

    2019-12-04 11:42:09

  • 相关阅读:
    struts2 错误:Dispatcher initialization failed java.lang.RuntimeException
    JavaScript如何实现拖放功能
    Javascript异步执行时要小心的变量作用域
    Javascript异步编程
    Origin null is not allowed by Access-Control-Allow-Origin
    eclipse spket插件 错误 Syntax error on token "(", FunctionExpressionHeader expected after this
    EL--Expression Language
    [Swift]LeetCode820. 单词的压缩编码 | Short Encoding of Words
    [Swift]LeetCode879. 盈利计划 | Profitable Schemes
    [Swift]LeetCode878. 第 N 个神奇数字 | Nth Magical Number
  • 原文地址:https://www.cnblogs.com/jyy599/p/11981951.html
Copyright © 2020-2023  润新知