我在使用Apache POI將一些數據寫入Excel工作表時遇到問題。 我想多次調用一個函數,它會將數據寫入我創建的Excel工作表中。使用Apache POI將數據寫入java中的excel文件
有沒有什麼辦法可以將指針移動到每次函數結尾的下一行???
下面我的代碼給出...
public static void excelLog(String filename , String message)
{
String dest="D:\\testexcel.xls";
HSSFWorkbook myWorkBook = new HSSFWorkbook();
HSSFSheet mySheet = myWorkBook.createSheet();
HSSFRow myRow = null;
HSSFCell myCell = null;
String excelData [][] = new String [1][2];
excelData[0][0]=filename;
excelData[0][1]=message;
myRow = mySheet.createRow(rowNum);
for (int cellNum = 0; cellNum < 2 ; cellNum++){
myCell = myRow.createCell((short) cellNum);
myCell.setCellValue(excelData[rowNum][cellNum]);
}
rowNum++;
try{
FileOutputStream out = new FileOutputStream(dest);
myWorkBook.write(out);
out.close();
}catch(Exception e){
e.printStackTrace();
}
}
請幫我在這。 謝謝:)
一兩件事我想知道的是,這裏,我只想在Excel工作表,所以我使用2-d陣列插入兩列。如果我必須在表格中填充5列,那麼使用數組將太複雜了嗎?那麼這裏的替代品是什麼? – ASH