Hi,
I am trying to add content to an excel sheet using the below code. However, when I open the excel sheet, nothing is added. Please advice.
public class StepNoToExcel
{
HSSFWorkbook wb = null;
String fileName = "C:\\StepNoForEvidences.xls";
File file = null;
StepNoToExcel()
{
file = new File(fileName);
if(!file.exists())
{
try {
file.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
wb = new HSSFWorkbook();
wb.createSheet("Step Number");
}
public void addToWorkBook(String step) throws IOException
{
System.out.println(step);
HSSFSheet sheet = wb.getSheetAt(wb.getActiveSheetIndex());
for(Row row : sheet)
{
Cell cell = row.createCell(0);
if(cell.equals(Cell.CELL_TYPE_BLANK))
{
cell.setCellValue(step);
}
}
FileOutputStream fileOut = new FileOutputStream(file);
wb.write(fileOut);
fileOut.close();
}
}