Hi,
We now have a problem.
We want to get the table information with a word, and we found it can not get the correct information when the table has a horizontal merged cells.
The following is our demo and the attachment is our word:
public static void main(String[] args) {
Document doc = null;
try {
doc = new Document(“test.docx”);
}
catch (Exception e) {
e.printStackTrace();
}
SectionCollection sections = doc.getSections();
for (int i = 0; i < sections.getCount(); i++) {
Section section = sections.get(i);
NodeCollection<?> nodes = section.getBody().getChildNodes();
convertParsTables(doc, nodes);
}
}
private static void convertParsTables(Document doc, NodeCollection<?> nodes) {
int count = nodes.getCount();
for (int i = 0; i < count; i++) {
Node node = nodes.get(i);
if (node instanceof Table) {
Table table = (Table) node;
convertTable(doc, table);
}
}
}
private static void convertTable(Document doc, Table table) {
RowCollection rows = table.getRows();
for (int r = 0; r < rows.getCount(); r++) {
Row row = rows.get®;
convertRow(doc, rows, row, r);
}
}
private static void convertRow(Document doc, RowCollection rows, Row row, int r) {
CellCollection cells = row.getCells();
for (int c = 0; c < cells.getCount(); c++) {
Cell cell = cells.get©;
convertCell(doc, rows, cells, r, c, cell);
}
}
private static void convertCell(Document doc, RowCollection rows, CellCollection cells, int r, int c, Cell cell) {
CellFormat cellformat = cell.getCellFormat();
int hmerge = cellformat.getHorizontalMerge();
int vmerge = cellformat.getVerticalMerge();
System.out.println(Integer.toString(hmerge));
System.out.println(Integer.toString(vmerge));
}
The red code can not get the correct information, result of this code is always 0.