我创建了一个 java maven 程序,它使用 Apache POI API 生成 excel 文件,一切正常,但是当我尝试将报告放到特定位置时,这样做
:FileInputStream inputStream = new FileInputStream(new File("C:\\Users\\C5292600\\Desktop\\report1.xlsx"));
我收到以下错误:
Exception in thread "main" java.lang.IllegalArgumentException: Invalid char (:) found at index (1) in sheet name 'C:\Users\C5292600\Desktop\repor'
at org.apache.poi.ss.util.WorkbookUtil.validateSheetName(WorkbookUtil.java:151)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.createSheet(XSSFWorkbook.java:873)
at com.occCheckNoData.report.Create.newSheet(Create.java:25)
at com.occCheckNoData.report.mainReport.main(mainReport.java:34)
最佳答案
它是现有路径吗?如果不使用类似 File file = new File(yourpath); 的内容file.mkdirs();
创建一个新路径。并生成文件 FileOutputStream fileOut = new FileOutputStream(new File(yourpath + filetype));
关于java - 如何在特定位置生成POI excel文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60435177/