I am reading an excel document as below:
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();
}
}
As seen above, I am able to read the row. However, now I want to write that row into a semicolon delimited dat file.
Also, if a column is empty, it should go as an empty value in the file i.e. no data between consecutive semicolons.
1 Answer