Excel 日期轉換

來源:互聯網
上載者:User

標籤:style   blog   color   os   art   io   

public static void importExcel2(File file) throws Exception, IOException {        Workbook book  =  Workbook.getWorkbook(file);        //  獲得第一個工作表對象         Sheet sheet  =  book.getSheet( 0 );        //  得到第一列第一行的儲存格          int  columnum  =  sheet.getColumns(); //  得到列數          int  rownum  =  sheet.getRows(); //  得到行數         System.out.println(columnum);       System.out.println(rownum);        for  ( int  i  =   1 ; i  <  rownum; i ++ ) //  迴圈進行讀寫          {//            for  ( int  j  =   0 ; j  <  columnum; j ++ )  {//           }              CaseInfor caseInfor = new CaseInfor();            System.out.print(sheet.getCell(0, i).getContents());            caseInfor.title=sheet.getCell(0, i).getContents();//            if(sheet.getCell(0, i).getContents()==""){//                 flash.put("error", "標題不可為空");//                 list(null,null);//            }                                    Cell cell1  =  sheet.getCell(1, i);            if(sheet.getCell(1, i).getType() == CellType.DATE){                DateCell dc = (DateCell)cell1;                    Date date = dc.getDate();                        SimpleDateFormat ds = new SimpleDateFormat("yyyy-MM-dd");                        String    cellcon = ds.format(date);                            System.out.print(cellcon);                             System.out.print( " \t " );                             caseInfor.acceptTime=date;          }            Cell cell2  =  sheet.getCell(2, i);            if(sheet.getCell(1, i).getType() == CellType.DATE){                DateCell dc = (DateCell)cell2;                Date date = dc.getDate();                SimpleDateFormat ds = new SimpleDateFormat("yyyy-MM-dd");                String    cellcon = ds.format(date);                System.out.print(cellcon);                 caseInfor.deadTime=date;                System.out.print( " \t " );            }            caseInfor.department=sheet.getCell(3, i).getContents();            caseInfor.process=sheet.getCell(4, i).getContents();            caseInfor.account=sheet.getCell(5, i).getContents();            caseInfor.information=sheet.getCell(6, i).getContents();            caseInfor.mandatory=sheet.getCell(7, i).getContents();            caseInfor.save();       }        book.close();       flash.put("success", "匯入成功");       list(null,null);    }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.