Thanks Annika for your assistance on getting this done.
Still there is some problem with the count and it doesn't behave properly when we have both rowspan and colspan regions start in same row. Please refer the doc attached.
I expect the count when it reaches to
second row as below (example table is of size 5x4):
Total Merged Columns: 1
Total Merged Rows: 1
Total Merged Columns: 1
Total Merged Rows: 2
Total Merged Columns: 2
Total Merged Rows: 1
Total Merged Columns:
<IDEALLY THIS PRINT SHOULD BE SKIPPED SINCE IT WAS HANDLED IN ABOVE COLSPAN, PLEASE CONFIRM>Total Merged Rows: 1
Total Merged Columns: 1
Total Merged Rows: 2
Count for the last column of second row is coming as 1 instead of 2. Please advise.
- Code: Select all
Table table = (Table) object;
RowCollection rows = table.getRows();
for(int i=0; i < rows.getCount(); i++) {
TableRow row = rows.get(i);
CellCollection cells = row.getCells();
for(int j=0; j < cells.getCount(); j++) {
TableCell cell = table.get(i, j);
int rowSpanCount = 1;
int columnSpanCount = cell.getGridSpan();
System.out.println("Total Merged Columns: " + columnSpanCount);
if (cell.getCellFormat().getVerticalMerge().equals(CellMerge.Start)) {
for (int k = i; k <rows.getCount()-1 ; k++) {
if(table.get(k, j).getCellFormat().getVerticalMerge().equals(CellMerge.Continue)) {
rowSpanCount++;
}
}
if(rowSpanCount > 1) {
System.out.println("Total Merged Rows: " + rowSpanCount);
}
}
}
}
Additionally, thanks for the code given for the DOCX TO HTML, but our requirement is to extract the partial content which is HTML formatted and make it in HTML form outside. In our case, same document could contain both HTML and Non-HTML (MS Word objects like paragraphs, tables etc.) contents on it.
Login to view the files attached to this post.