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