enter image description here I am trying to make a generator from xml to ms word . I use apache poi for this purpose.

"Stuck" in this moment:

for (SheetType sa:sheetArray) { changeOrientation(document, sa.getLandscape()); TableType[] colArray = sa.getTableArray(); RowType[] rowArray = sa.getRowArray(); XWPFTable table = document.createTable(); for (RowType ra : rowArray) { XWPFTableRow tableRowOne = table.createRow(); CellsType[] cellArray = ra.getCellArray(); //Массив cells for (CellsType ca : cellArray) { CellsType.Value[] valueArray = ca.getValueArray(); //Массив values for (CellsType.Value value : valueArray) { XWPFTableCell cell = tableRowOne.addNewTableCell(); XWPFParagraph paragraph = cell.addParagraph(); XWPFRun run = paragraph.createRun(); tableRowOne.setHeight((int) ra.getHeigth()); table.setCellMargins( sa.getPositionTop(), sa.getPositionLeft(), sa.getPositionBottom(), sa.getPositionRight() ); run.setText(value.getStringValue()); run.setBold(ca.getBold()); run.setItalic(ca.getItalic()); run.setUnderline(UnderlinePatterns.valueOf(ca.getUnderline())); run.setFontFamily(ca.getFontName()); run.setFontSize(ca.getFontSize()); paragraph.setAlignment(ParagraphAlignment.valueOf(ca.getTextAlign())); paragraph.setBorderBottom(Borders.valueOf(ca.getBorderBottom())); paragraph.setBorderLeft(Borders.valueOf(ca.getBorderLeft())); paragraph.setBorderTop(Borders.valueOf(ca.getBorderTop())); paragraph.setBorderRight(Borders.valueOf(ca.getBorderRight())); paragraph.setSpacingAfter((short)ca.getSpacingAfter()); table.setInsideHBorder( XWPFTable.XWPFBorderType.valueOf(colArray[0].getTableBorderType()), Integer.parseInt(colArray[0].getTableBorderSize()), colArray[0].getTableBorderPosition(), colArray[0].getTableBorderColor() ); cell.removeParagraph(0); run.setColor(ca.getColor()); run.setSubscript(VerticalAlign.valueOf(ca.getSubscript())); } } } } 

I take all the data from xml , but after my iterator an extra Cell appears.

removeCell does not help.

At the output, I should have got a table, but I have an extra cell and column. what is the problem?

    1 answer 1

    Something like this

      XWPFTable table = document.createTable(rowArray.length, sa.getColArray().length);