大家好我是java的初学者。我正在为我的Android手机创建一个应用程序,我必须阅读excel文件,为此我使用的是POI。我的代码如下所示
Iterator<Row> rowIter = mySheet.rowIterator();
String phone_no = null;
String message =null;
int cell=0;
while(rowIter.hasNext()){
HSSFRow myRow = (HSSFRow) rowIter.next();
Iterator<Cell> cellIter = myRow.cellIterator();
cell=0;
while(cellIter.hasNext()){
HSSFCell myCell = (HSSFCell) cellIter.next();
if(cell==0){
phone_no=myCell.toString();
}
else if(cell==1){
message=myCell.toString();
}
cell++;
}
}
我的Excel工作表包含第一列的电话号码和第二列的邮件。当我运行代码我得到phone_num为1.23456789E9我需要它像1234567890.但在消息的情况下,我得到完整的字符串到我的变量,因为我给excel。
提前妥协......
答案 0 :(得分:1)
首先,您的代码中存在一些逻辑错误 -
cell = 0;
while(cellIter.hasNext()){
if(cell == 0) {
}
if(cell == 1) {
}
其次,不要盲目地调用toString
方法,请阅读documentation。