zoukankan      html  css  js  c++  java
  • excel导出

    public class ExporTest {  
        private Map<String, CellStyle> smap;// 存储模板中单元格样式  
            @Test  
        public void test() {  
            Workbook wb = getWorkbook(path);  
            initStyle(wb);  
            writeSheet(wb.getSheetAt(1));  
            writeExcel(wb);  
        }  
      
        private Workbook getWorkbook(String filepath) {  
      
            Workbook wb = null;  
            try {  
                wb = new XSSFWorkbook(filepath);  
            } catch (Exception ex) {  
                ex.printStackTrace();  
            }  
            return wb;  
        }  
      
        /** 
         * 从模板中取单元格样式, 
         *  
         * @param wb 
         */  
        private void initStyle(Workbook wb) {  
      
            CellStyle normal = wb.getSheetAt(0).getRow(5).getCell(0).getCellStyle();  
            smap.put("normal", normal);  
        }  
      
        private void writeSheet(Sheet sh) {  
      
            for (int i = 0; i < ps.size(); i++) {  
                Row row = sh.createRow(i + 1);  
                Cell cell = row.createCell(0);  
                cell.setCellStyle(smap.get("normal"));  
                cell.setCellValue(permission.getName());  
            }  
        }  
      
        private void writeExcel(Workbook wb) {  
      
            try {  
                FileOutputStream out = new FileOutputStream("test.xls");  
                wb.write(out);  
                out.close();  
            } catch (FileNotFoundException e) {  
                e.printStackTrace();  
            } catch (IOException e) {  
                e.printStackTrace();  
            }  
        }  
      
    } 
  • 相关阅读:
    Luogu P3371 线段树1
    8-16模拟赛
    Luogu P1313 计算系数
    Luogu P1525 关押罪犯
    Luogu P1040 加分二叉树
    Luogu P1018 乘积最大
    Luogu P1541 乌龟棋
    BST,Splay平衡树学习笔记
    常见的逻辑错误
    行为认知疗法——十大认知错误
  • 原文地址:https://www.cnblogs.com/gym2017/p/7324520.html
Copyright © 2011-2022 走看看