【发布时间】:2014-10-23 14:07:01
【问题描述】:
我正在尝试读取 java 中的 .xlsx 文件(使用 Apache POI API),其单元格包含具有前导零的值。例如 0590040100000124
但是在输出中我得到了类似的东西
6247241.0 5.90040100000124E14 0.0 5.90020100000125E14 这是我的代码
public static void main(String[] args) throws FileNotFoundException, IOException {
// TODO Auto-generated method stub
try{
Workbook workbook = new XSSFWorkbook(new FileInputStream("C://dedup//dedup.xlsx"));
String sheetName= workbook.getSheetName(0);
System.out.println("Sheet Name:"+sheetName);
double cellValues[] = new double[1000];
for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
Sheet sheet = workbook.getSheetAt(i);
int cellIndex=0;
for (Row row : sheet) {
for (Cell cell : row) {
//if(cell.toString()!=null){
cell.setCellType(Cell.CELL_TYPE_NUMERIC);
cellValues[cellIndex]=cell.getNumericCellValue();
cellIndex++;
//}
}
}
for(int k=0;k<cellValues.length;k++)
System.out.print(cellValues[k]+" <-> "+"\t");
}
}catch(Exception e){
System.out.println("JKB Exception Message:"+e.getMessage());
}
【问题讨论】:
-
将单元格内容读取为字符串,然后使用此字符串创建您的值
-
@jhamon 即使您将值读取为字符串,您也会得到相同的输出
-
如果将单引号连接到值的开头会发生什么?
标签: java excel apache apache-poi