Java jacob multiple word merge header footer how to generate?

how do java jacob multiple word merge headers and footers be generated? The footers generated by
are incorrect.

clipboard.png

clipboard.png

clipboard.png

there are repeated cute new solutions in the wrong number.

String dest=filePath.substring (0filePath.indexOf (".")) + "- copy .doc";

FileChannel inputChannel = null;
FileChannel outputChannel = null;
try {
  inputChannel = new FileInputStream(filePath).getChannel();
  outputChannel = new FileOutputStream(dest).getChannel();
    outputChannel.transferFrom(inputChannel, 0, inputChannel.size());
}catch (IOException e) {
  e.printStackTrace();
}
finally {
  try {
    outputChannel.close();
    inputChannel.close();
  } catch (IOException e) {
    e.printStackTrace();
  }

}
boolean flag=true;
//word
ActiveXComponent app = new ActiveXComponent("Word.Application");//word

try {
  //word
  app.setProperty("Visible", new Variant(false));
  //documents
  Object docs = app.getProperty("Documents").toDispatch();


  //

  Object doc = Dispatch.invoke(
          (Dispatch) docs,
          "Open",
          Dispatch.Method,
          new Object[] { (String) dest,
                  new Variant(false), new Variant(true) },
          new int[3]).toDispatch();

 



  //
  Dispatch selection = app.getProperty("Selection").toDispatch();
  //
  Dispatch.call(selection, "HomeKey", new Variant(6));
  //
  //
  Dispatch.call(selection, "EndKey", new Variant(6));
  Dispatch.call(selection, "TypeParagraph");
  //
  Dispatch.call(selection, "InsertBreak");
  int i = 0;

  //
  for (TestingInstanceDetailAttach attach:attachList){
    iPP;
    String path=attach.getUpload().getPath();
    if(StringUtils.isNotBlank(path)){
      File file = new File(path);

      if(file.exists()&&path.endsWith("doc")){
        //

        //
        Dispatch.invoke(selection,
                "insertFile", Dispatch.Method, new Object[] {
                        (String)path, "",
                        new Variant(false), new Variant(false),
                        new Variant(false) }, new int[3]);
        //
        Dispatch.call(selection, "EndKey", new Variant(6));
        Dispatch.call(selection, "TypeParagraph");

      }
    }
  }



  //word
  File folder = new File(filePath.substring(0, filePath.lastIndexOf("/")+1));
  if(!folder.exists() && !folder.isDirectory()){
    folder.mkdirs();
  }
  Dispatch.invoke((Dispatch) doc, "SaveAs", Dispatch.Method,
          new Object[] { filePath, new Variant(1) }, new int[3]);
  Variant f = new Variant(false);
  Dispatch.call((Dispatch) doc, "Close", f);
} catch (Exception e) {
  flag=false;
  throw new RuntimeException("word.:" + e);

} finally {
  app.invoke("Quit", new Variant[] {});
  if (!dest.endsWith(File.separator))
    dest = dest + File.separator;
  File dirFile = new File(dest);
  if (!dirFile.exists()) {
    System.out.println(":" + dest + "");
    return false;
  }else{
    dirFile.delete();
  }

}
return flag;
Mar.15,2021
Menu