0
我是新來的Excel - Java(Apache POI),並試圖找出一種方法將excel數據傳輸到文本文件。複製Excel數據到文本文件 - Java(POI)
我的Excel工作表看起來是這樣的
name table latest_table Date
1 george table1 t459 2017-08-24
2 john table1 thi7 2017-07-23
3 mary table1 gdr99 2017-07-22
到目前爲止我的代碼
public static void excel_to_text(XSSFWorkbook wb) {
XSSFSheet sheet = wb.getSheetAt(0);
int rows = sheet.getPhysicalNumberOfRows();
int cols = 0, tmp = 0;
XSSFRow row;
XSSFCell cell;
for(int i = 0; i < 10 || i < rows; i++) {
row = sheet.getRow(i);
if(row != null) {
tmp = sheet.getRow(i).getPhysicalNumberOfCells();
if(tmp > cols) cols = tmp;
}
}
for(int r = 0; r < rows; r++) {
row = sheet.getRow(r);
if(row != null) {
for(int c = 0; c < cols; c++) {
cell = row.getCell((short)c);
if(cell != null) {
*// code here*
}
}
}
}
}
任何幫助表示讚賞。
你的代碼有什麼問題? – 2017-08-24 15:51:51
文本文件應該如何顯示?如果你的問題是關於如何將數據/字符串寫入文件,請看這裏: https://stackoverflow.com/questions/2885173/how-do-i-create-a-file-and-write-to- it-in-java – Piwo
如何存儲數據,因爲存在不同類型的數據。另外,有沒有辦法讓文本文件看起來完全像表一樣? – Chid