zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    c#中的命名空间、类
    C#编写“hello,world”
    django1.9中manage.py的操作命令
    JS原生Ajax操作(XMLHttpRequest)
    Jquery百宝箱
    jQuery与Ajax入门
    JSON
    JSTL与EL表达式
    知识点整理
    Servlet与JSP进阶
  • 原文地址:https://www.cnblogs.com/jyy599/p/11981951.html
Copyright © 2011-2022 走看看