如何从Excel表格中使用selenium提取双int值

以下是我用于从Excel表中提取任何值的代码。 单元格的值可以是string,date或长整型。 使用下面的代码,我能够正确提取string和date,但长整型值是进来作为4.6861230317E10而不是46861230317.如何克服这个问题?

Cell = ExcelWSheet.getRow(RowNum).getCell(ColNum); if(Cell.getCellTypeEnum() == CellType.STRING) { System.out.println("check for celltype string"); CellData = Cell.getStringCellValue(); System.out.println("String CellData:"+CellData); } else if(Cell.getCellTypeEnum() == CellType.NUMERIC) { System.out.println("checking for celltype numeric"); CellData = fmt.formatCellValue(Cell); if(CellData.contains("/")) { System.out.println("its a date !"+CellData); } else if(!CellData.contains("/")) { double CellData2 = (double)Cell.getNumericCellValue(); System.out.println("actual double value "+CellData2); CellData=String.valueOf(CellData2); System.out.println("its a double int numeric value "+CellData); } } System.out.println("returning cell data "+CellData); return CellData; 

在你的代码中尝试下面的行实现

 cell.setCellType(Cell.CELL_TYPE_STRING) 

它为我工作。

代替

 double CellData2 = (double)Cell.getNumericCellValue(); 

使用

 long CellData2 = new Double(Cell.getNumericCellValue()).longValue(); 

它工作得很好!