0

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();
    }
}
2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by dougWill
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.