简体   繁体   English

尝试使用 java 和 POI 库打开一个空白 excel 文件

[英]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我正在尝试创建一个空白 excel 文件以便能够在创建后添加一些数据,但唯一的问题是我的代码在

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谢谢,我正在使用 POI 4.0.0

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());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM