我试图在每个循环中向fos添加工作簿内容但是我收到错误org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException,如果我在循环外编写工作簿它只写入循环中的最后一本工作簿。任何解决方案这是我的代码,谢谢。
public static void main(String[] args) throws InvalidFormatException, IOException, ParseException {
String [] listefichiers;
String chemin="D:\\part";
FileOutputStream fos=new FileOutputStream("D:\\saisonedit3.xlsx");
FichierExcel fG_gares=new FichierExcel("D:\\Traitement aristote\\","Parametres_MP_java.xlsx","Gares");
File repertoire = new File(chemin);
listefichiers=repertoire.list();
XSSFWorkbook workbook=null;
for(int i=0;i<listefichiers.length;i++){
FileInputStream fis = new FileInputStream(chemin+"\\"+listefichiers[i]);
System.out.println("nom fic "+listefichiers[i]);
workbook = new XSSFWorkbook(fis);
XSSFSheet sheet = workbook.getSheetAt(0);
workbook.write(fos);
}
fos.close();
}
}