使用poi导入导出

POI结构

        HSSF - 提供读写Microsoft Excel XLS格式档案的功能。
        XSSF - 提供读写Microsoft Excel OOXML XLSX格式档案的功能。
        HWPF - 提供读写Microsoft Word DOC格式档案的功能。
        HSLF - 提供读写Microsoft PowerPoint格式档案的功能。
        HDGF - 提供读Microsoft Visio格式档案的功能。
        HPBF - 提供读Microsoft Publisher格式档案的功能。    
        HSMF - 提供读Microsoft Outlook格式档案的功能。

  获取单元格值

     private String getCellValue(HSSFCell cell) {  
            String cellValue = "";  
            DecimalFormat df = new DecimalFormat("#");  
            switch (cell.getCellType()) {  
            case HSSFCell.CELL_TYPE_STRING:  
                cellValue = cell.getRichStringCellValue().getString().trim();  
                break;  
            case HSSFCell.CELL_TYPE_NUMERIC:  
                cellValue = df.format(cell.getNumericCellValue()).toString();  
                break;  
            case HSSFCell.CELL_TYPE_BOOLEAN:  
                cellValue = String.valueOf(cell.getBooleanCellValue()).trim();  
                break;  
            case HSSFCell.CELL_TYPE_FORMULA:  
                cellValue = cell.getCellFormula();  
                break;  
            default:  
                cellValue = "";  
            }  
            return cellValue;  
        } 

猜你喜欢

转载自qun715715.iteye.com/blog/2193894