成人无码视频,亚洲精品久久久久av无码,午夜精品久久久久久毛片,亚洲 中文字幕 日韩 无码

資訊專欄INFORMATION COLUMN

java excel類

hiyayiji / 970人閱讀

摘要:?jiǎn)卧窀黝愋蛿?shù)據(jù)讀取基本類型處理的數(shù)據(jù)包括字符型數(shù)據(jù),數(shù)字日期公式等。下面是單元格類型說(shuō)明實(shí)例解析中數(shù)據(jù),要求轉(zhuǎn)換為文本方式存儲(chǔ)寫一個(gè)解析的抽象類版本的版本的解析的文件格式有誤

1.單元格各類型數(shù)據(jù)讀取

1.1 基本類型

處理的Excel數(shù)據(jù)包括字符型數(shù)據(jù),數(shù)字、日期、公式等。

下面是單元格類型說(shuō)明:

2實(shí)例
解析excel中數(shù)據(jù),要求轉(zhuǎn)換為文本方式存儲(chǔ)
2.1 寫一個(gè)excel解析的抽象類

public abstract class ExcelParser {

        private String fileName;
        private InputStream inputStream;
    
        private final static String excel2003L = ".xls";//2003- 版本的excel
        private final static String excel2007U = ".xlsx";//2007+ 版本的excel
    
        protected final static DecimalFormat decimalFormat = new DecimalFormat("0");
        protected final static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd");
    
        protected final static String[] columnStr = new String[]{
                "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
        };
           protected OrderExcelParser(String fileName, InputStream inputStream) {
            this.fileName = fileName;
            this.inputStream = inputStream;
        }
    
        protected Workbook getWorkbook() throws Exception {
            try {
                String fileType = fileName.substring(fileName.lastIndexOf("."));
                if (excel2003L.equals(fileType)) {
                    return new HSSFWorkbook(inputStream); //2003-
                } else if (excel2007U.equals(fileType)) {
                    return new XSSFWorkbook(inputStream); //2007+
                } else {
                    throw new Exception();
                }
            } catch (Exception e) {
                throw new Exception("解析的文件格式有誤!");
            }
        }
    
        protected abstract void parseTitles(int rowIndex) throws Exception;
    
        protected String getCellStringValue(Cell cell) throws Exception {
            String cellValue = "";
            if (cell == null) {
                return cellValue;
            } else if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
                cellValue = cell.getStringCellValue();
            } else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                if (HSSFDateUtil.isCellDateFormatted(cell)) {
                    double d = cell.getNumericCellValue();
                    Date date = HSSFDateUtil.getJavaDate(d);
                    cellValue = simpleDateFormat.format(date);
                } else {
                    cellValue = decimalFormat.format((cell.getNumericCellValue()));
                }
            } else if (cell.getCellType() == Cell.CELL_TYPE_BLANK) {
                cellValue = "";
            } else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) {
                cellValue = String.valueOf(cell.getBooleanCellValue());
            } else if (cell.getCellType() == Cell.CELL_TYPE_ERROR) {
                cellValue = "";
            } else if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
                cellValue = cell.getCellFormula();
            }
           
            return cellValue.trim();
        }
    }

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://m.hztianpu.com/yun/67072.html

相關(guān)文章

  • Java對(duì)象和Excel轉(zhuǎn)換工具XXL-EXCEL

    摘要:一行代碼完成對(duì)象和之間的轉(zhuǎn)換。說(shuō)明屬性列名稱四版本更新日志版本,新特性導(dǎo)出支持對(duì)象裝換為,并且支持字節(jié)數(shù)組等多種導(dǎo)出方式導(dǎo)入支持轉(zhuǎn)換為對(duì)象,并且支持文件路徑等多種導(dǎo)入方式版本,新特性字段支持類型。 《Java對(duì)象和Excel轉(zhuǎn)換工具XXL-EXCEL》 showImg(https://segmentfault.com/img/remote/1460000012470335);showI...

    mj 評(píng)論0 收藏0
  • java 導(dǎo)出 excel 最佳實(shí)踐,java 大文件 excel 避免OOM(內(nèi)存溢出) exce

    摘要:消費(fèi)之后,多線程處理文件導(dǎo)出,生成文件后上傳到等文件服務(wù)器。前端直接查詢并且展現(xiàn)對(duì)應(yīng)的任務(wù)執(zhí)行列表,去等文件服務(wù)器下載文件即可。這客戶體驗(yàn)不友好,而且網(wǎng)絡(luò)傳輸,系統(tǒng)占用多種問(wèn)題。拓展閱讀導(dǎo)出最佳實(shí)踐框架 產(chǎn)品需求 產(chǎn)品經(jīng)理需要導(dǎo)出一個(gè)頁(yè)面的所有的信息到 EXCEL 文件。 需求分析 對(duì)于 excel 導(dǎo)出,是一個(gè)很常見(jiàn)的需求。 最常見(jiàn)的解決方案就是使用 poi 直接同步導(dǎo)出一個(gè) exc...

    K_B_Z 評(píng)論0 收藏0
  • POI技術(shù)—用于java開發(fā)解析excel的抽象

    摘要:?jiǎn)卧窀黝愋蛿?shù)據(jù)讀取基本類型處理的數(shù)據(jù)包括字符型數(shù)據(jù),數(shù)字日期公式等。下面是單元格類型說(shuō)明實(shí)例解析中數(shù)據(jù),要求轉(zhuǎn)換為文本方式存儲(chǔ)寫一個(gè)解析的抽象類版本的版本的解析的文件格式有誤 1.單元格各類型數(shù)據(jù)讀取 1.1 基本類型 處理的Excel數(shù)據(jù)包括字符型數(shù)據(jù),數(shù)字、日期、公式等。 下面是單元格類型說(shuō)明: showImg(https://segmentfault.com/img/bVMjd...

    xfee 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

閱讀需要支付1元查看
<