ahmad
ahmad

Reputation: 11

Trying to open a blank excel File using java and POI library

I am trying to creatin a blank excel file to be able to add some data after the creation,but the only issue that my code is stoping when The

XSSFWorkbook workbook = new XSSFWorbook();

there is no file created and there is no error that is shown.Can somebody tell me why this is happening

private void createExcelFile(String name) 
    {
    String excelFileName = startSavePath + separator + name + ".xlsx";
    System.out.println("test123");
    XSSFWorkbook workbook = new XSSFWorkbook();
    System.out.println("test456");
    XSSFSheet sheet = workbook.createSheet("test");
    
    try {
        System.out.println("test789");
    FileOutputStream out = new FileOutputStream(excelFileName);
    System.out.println("test10");
    workbook.write(out);
    out.close();
    }catch (Exception e) {
        System.out.println(e);
    }
    
    }

Thank you , and i am using POI 4.0.0

Upvotes: 0

Views: 57

Answers (1)

Neeraj
Neeraj

Reputation: 316

where are you expecting the file to be created. The file is created in the root of the project. You should probably do as below -

String excelFileName = startSavePath + separator + name + ".xlsx";
File f = new File(excelFileName);
// Other code
FileOutputStream out = new FileOutputStream(f);
System.out.println("File created here - " + f.getAbsolutePath());

Upvotes: 1

Related Questions