2017-06-07 63 views
-2

我已經嘗試了使用selinium和java excel的自動化程序。不幸的是,公式不擅長。我嘗試使用各種方法,但初始selinium程序本身終止,只在Excel中輸出一行。有人能幫忙嗎?selinium和excel poi程序

+1

幫助如何?我們需要看看你做了什麼來告訴你要糾正什麼...... – Ray

回答

0

試試這個

FileInputStream fis = new FileInputStream("/test/tes123.xls"); 
     Workbook wb = new HSSFWorkbook(fis); 
     Sheet sheet = wb.getSheetAt(0); 
     FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); 

     // suppose your formula is in B2 
     CellReference cellReference = new CellReference("B2"); 
     Row row = sheet.getRow(cellReference.getRow()); 
     Cell cell = row.getCell(cellReference.getCol()); 

     if (cell!=null) { 
      switch (evaluator.evaluateFormulaCell(cell)) { 
       case Cell.CELL_TYPE_BOOLEAN: 
        System.out.println(cell.getBooleanCellValue()); 
        break; 
       case Cell.CELL_TYPE_NUMERIC: 
        System.out.println(cell.getNumericCellValue()); 
        break; 
       case Cell.CELL_TYPE_STRING: 
        System.out.println(cell.getStringCellValue()); 
        break; 
       case Cell.CELL_TYPE_BLANK: 
        break; 
       case Cell.CELL_TYPE_ERROR: 
        System.out.println(cell.getErrorCellValue()); 
        break; 

       // CELL_TYPE_FORMULA will never occur 
       case Cell.CELL_TYPE_FORMULA: 
        break; 
      } 
     }