0
我想写我的测试结果/数据在运行时为我写了下面的代码。编译这段代码时我没有收到任何错误,但是结果没有写在这里。有人能帮我解决这个问题吗?无法使用POI在运行时写入excel
public void WritetoExcel(String filepath, String OrderID) throws IOException
{
FileInputStream ExcelFile = new FileInputStream(filepath);
System.out.println(filepath);
ExcelWBook = new XSSFWorkbook(ExcelFile);
System.out.println("WorkBook Sucessfully");
ExcelWSheet = ExcelWBook.getSheetAt(0);
System.out.println("Sheet Sucessfully");
Iterator<Row> rowIterator= ExcelWSheet.iterator();
int RowNum =0;
while (rowIterator.hasNext())
{
Row row=rowIterator.next();
RowNum++;
}
try
{
Row = ExcelWSheet.createRow(RowNum);
Iterator<Cell> cellIterator=Row.iterator();
Cell = Row.getCell(0);
if (Cell==null)
{
Cell=Row.createCell(0);
Cell.setCellValue(OrderID);
}
else
{
Cell.setCellValue(OrderID);
}
FileOutputStream fileOut = new FileOutputStream(filepath);
ExcelWBook.write(fileOut);
fileOut.flush();
fileOut.close();
}
catch (Exception e)
{
throw (e);
}
}
'catch(Exception e){throw(e); } - - 认真?!? 'Row = ExcelWSheet.createRow(RowNum);'这怎么编译?!? –
通过编译我的意思是,它不显示任何错误。我是Java新手,因此避免了任何语法错误。指导将不胜感激 –
看看这个链接是否有帮助 - http://viralpatel.net/blogs/java-read-write-excel-file-apache-poi/ – Rao