Mein Javanicht in der Lage, um numerische Werte von Excel-Tabelle in Selen WebDriver mit Java
public class Readexcel {
public void readfile(String filepath, String filename, String sheetname) throws IOException
{
File file = new File(filepath+"\\"+filename);
FileInputStream fis = new FileInputStream(file);
// for creating .xlsx workbook
Workbook wb = new XSSFWorkbook(fis);
// for reading the sheet by its name
Sheet sh = wb.getSheet(sheetname);
//find the total rows in sheet
int rowcount = sh.getLastRowNum()-sh.getFirstRowNum();
// create a loop to create
for(int i=0;i<rowcount+1;i++)
{
Row row= sh.getRow(i);
// create a loop to print cell values
for(int j=0;j<row.getLastCellNum();j++)
{
Cell cell= row.getCell(j);
switch (cell.getCellType()) {
case Cell.CELL_TYPE_STRING:
System.out.print(row.getCell(j).getStringCellValue() + " ");
break;
case Cell.CELL_TYPE_NUMERIC:
System.out.print(row.getCell(j).getNumericCellValue() + " ");
break;
}
System.out.print(row.getCell(j).getStringCellValue()+"||");
}
System.out.println();
}
}
public static void main(String...strings) throws IOException
{
Readexcel re = new Readexcel();
String filepath = "F://Excelsheet";
re.readfile(filepath,"Book1.xlsx","Sheet1");
}
}
Durch die Verwendung von oben Code zu erhalten Ich erhalte eine Fehlermeldung „kann nicht Textwert von numerischer Zelle erhalten“. Irgendeine Hilfe? Auch Meine Ausgabe ist nicht richtig zugeordnet. Alle Saiten zeigen einen unter einem. Ausgabe sollte wie
Username Password
john 123
rambo 456
sein, aber ich bin immer eine Ausgabe wie
Username
password
john
Benutzername Benutzername || Passwort Passwort || John John || 12345.0 Ausgabe wie folgt (rambo kann nicht drucken) – Ab123
Ich habe meine Readfile-Funktion in meine Antwort eingefügt. Meine Ausgabe sieht so aus: – Gelbi
Code bearbeitet bitte überprüfen – Ab123