2016-09-29 8 views
0

Excelから要素を読み取るために、以下のコードを書いています。しかし、このコードを実行しているときにエラーが発生しました。誰もこれで私を助けることができますか?POIでExcelから要素を読み込む際のエラー

package testUtilities; 

import java.io.File; 
import java.io.InputStream; 
import java.io.FileInputStream; 
import java.io.FileNotFoundException; 
import java.io.IOException; 
import java.text.DecimalFormat; 
import java.util.ArrayList; 
import java.util.HashMap; 
import java.util.Iterator; 
import java.util.List; 
import java.util.Map; 

import org.apache.poi.ss.usermodel.Cell; 
import org.apache.poi.ss.usermodel.Row; 
import org.apache.poi.xssf.streaming.SXSSFRow.CellIterator; 
import org.apache.poi.xssf.usermodel.XSSFSheet; 
import org.apache.poi.xssf.usermodel.XSSFWorkbook; 


@SuppressWarnings("unused") 
public class ReadLocatorsFromExcel { 


    public static void main (String args[]) throws IOException { 

     FileInputStream file = new FileInputStream(new File("/home/suvin/Documents/SeleniumWebdriver/Script/PaytmAutomationFramework/src/testUtilities/TestData.xlsx")); 
      XSSFWorkbook wb = new XSSFWorkbook(file); 
      XSSFSheet sheet = wb.getSheetAt(0); 
      Iterator<Row> rowIterator = sheet.iterator(); 
      while (rowIterator.hasNext()) 
      { 
       Row nexRow = rowIterator.next(); 
       Iterator<Cell> celIterator = nexRow.cellIterator(); 
       while (celIterator.hasNext()) 
       { 
       Cell cell = celIterator.next(); 
       switch (cell.getCellType()) { 
       case Cell.CELL_TYPE_STRING: 
        System.out.print(cell.getStringCellValue()); 
        break; 
       case Cell.CELL_TYPE_BOOLEAN: 
        System.out.print(cell.getBooleanCellValue()); 
        break; 
       case Cell.CELL_TYPE_NUMERIC: 
        System.out.print(cell.getNumericCellValue()); 
        break; 
      } 
       System.out.print(" - "); 
       } 
       System.out.println(); 
      } 

      wb.close(); 
      file.close(); 
     } 




    } 

私はラインから非推奨メソッド我々はその代わりに使用することができますどのような

case Cell.CELL_TYPE_STRING: 
         System.out.print(cell.getStringCellValue()); 
         break; 
        case Cell.CELL_TYPE_BOOLEAN: 
         System.out.print(cell.getBooleanCellValue()); 
         break; 
        case Cell.CELL_TYPE_NUMERIC: 
         System.out.print(cell.getNumericCellValue()); 
         break; 

のために、このコードで例外を取得していますか?

+0

クラスパスや 'pom.xml'などに' xmlbeans-XXX.jar'がありますか? – passion

+0

私はちょうどそれを行い、元の質問で私が編集している新しい例外を取得しました。どうぞご覧ください –

+0

報告されたクラスが存在するかどうかを確認しますか?多分あなたの依存はあなたのenvに適していません。 – passion

答えて

0

ほとんどの場合、必要なjarファイルがありません。 Mavenを使用していますか?これを追加します:

<dependency> 
    <groupId>org.apache.xmlbeans</groupId> 
    <artifactId>xmlbeans</artifactId> 
    <version>2.6.0</version> 
</dependency> 

あなたのpom.xmlに追加してください。

関連する問題