本文介绍了如何通过将破折号替换为空白来读取Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友,我需要您的帮助.我正在读取一个excel文件&写入数据以访问数据库,这是正确的写法,但是如果excell工作表中有空白,则表示正在读取下一行&放入空白数据,以便下一个单元格进入空白数据单元格.我的代码是这样的
Hi friend I want your help.I am reading an excel file & writing data to access database it is writting correctly but if there is any blank space in excell sheet it is reading the next row & puting insted of blank data so next cell comes to balnk data cell.my code is like this
Sheet mySheet = myWorkBook.getSheetAt(0);
/** We now need something to iterate through the cells.**/
Iterator rowIter = mySheet.rowIterator();
while(rowIter.hasNext())
{
Row myRow = (XSSFRow) rowIter.next();
Iterator cellIter = myRow.cellIterator();
Vector cellStoreVector=new Vector();
String nextElement="";
while(cellIter.hasNext())
{
Cell myCell = (XSSFCell) cellIter.next();
System.out.println("Cell Type is :"+myCell.getCellType()+" | "+myCell.toString());
if(myCell.getCellType()==XSSFCell.CELL_TYPE_BLANK)
{
System.out.println("Blank data found ");
myCell.setCellValue("-");
cellStoreVector.addElement(myCell);
}
else
{
cellStoreVector.addElement(myCell);
}
}
System.out.println("");
cellVectorHolder.addElement(cellStoreVector);
}
}
catch (Exception e)
{
e.printStackTrace();
}
我已经使用过XSSFCell.CELL_TYPE_BLANK,但是不会进入此循环,请帮帮我.谢谢.
I have used XSSFCell.CELL_TYPE_BLANK but it is not going to this loop please help me.Thanks.
推荐答案
if(""+myCell.toString()=="")
{
System.out.println("Blank data found ");
myCell.setCellValue("-");
cellStoreVector.addElement(myCell);
}
else
{
cellStoreVector.addElement(myCell);
}
这篇关于如何通过将破折号替换为空白来读取Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!