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;
可以在我們的替代使用什麼不贊成的方法?
你在你的類路徑或你的'pom.xml'或其他東西中有'xmlbeans-XXX.jar'嗎? – passion
我只是做了它,並得到了一個新的異常,我正在編輯原始問題。請看看 –
檢查報告的類是否存在?也許你的依賴不適合你的環境。 – passion