My requirement is write document code towards the header from the document. The document has a header which compose of the table. I have to achieve a cell and write document code. Now, I'm able to obtain the header and browse the information but I am unable to alter the header.

                       InputStream input = new FileInputStream("D:\\test.docx");
        XWPFDocument document=new XWPFDocument(input);
        XWPFHeaderFooterPolicy headerPolicy = new XWPFHeaderFooterPolicy(document);

        XWPFHeader header = headerPolicy.getDefaultHeader();
        List<XWPFTable> table = header.getTables();

        for (XWPFTable xwpfTable : table) {
            xwpfTable.getRow(1).getCell(0).setText("aaa");              //document.setTable(0, xwpfTable);
            //header.insertTable(1, xwpfTable);
        }
        //System.out.println(header.getTables());
        FileOutputStream out = new FileOutputStream("D:\\test.docx");
        document.write(out);
             out.close();