我讀的Excel文檔如下:Excel文件分隔dat文件
package com.sample.file;
//necessary imports goes here
public class ExcelReader {
public static void main(String[] args) throws Exception{
String fname = "C:\\myExcel.xls"; // or "C:\\myExcel.xlsx"
InputStream inp = new FileInputStream(fname);
Workbook wb = WorkbookFactory.create(inp);
Sheet sheet = null;
sheet = wb.getSheetAt(0);
Iterator rows = sheet.rowIterator();
while (rows.hasNext())
{
Row row = (Row) rows.next();
// how to write to a semicolon delimited dat file here
}
inp.close();
}
}
如上所見,我能夠讀取行。但是,現在我想將該行寫入以分號分隔的dat文件中。
另外,如果一列是空的,它應該作爲文件中的空值,即連續分號之間沒有數據。
你必須做一些像HSSFRow row1 = sheet.createRow((short)0); HSSFCell cellA1 = row1.createCell((short)0); cellA1.setCellValue(「Hello」); – vels4j