We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose Table Manipulation

Hi Aspose Team,

I attached a word document(docx file) which have tables in it. I used latest Aspose words java api to create another docx file by reading/manipulating the attached docx file. I could not able to read/manipulate when the table has merged cells in it . Below is the code. I want the tables inside the attached document into a new docx document.AsposeTableProblem.zip (41.7 KB)

Table dstTable = null;
	try {
		Table scrTable = (Table) sectionNode;
		dstTable = builder.startTable();
		RowCollection srcRows = scrTable.getRows();
		for (int j = 0; j < srcRows.getCount(); j++) {
			LOGGER.info(MessageFormat.format("\tStart of Row {0}", j));
			CellCollection srcCells = srcRows.get(j).getCells();
			Row dstTableRow = new Row(dstDoc);
			dstTable.appendChild(dstTableRow);
			for (int k = 0; k < srcCells.getCount(); k++) {
				String cellText = srcCells.get(k).toString(SaveFormat.TEXT).trim();
				LOGGER.info(MessageFormat.format("\t\tContents of Cell:{0} = \"{1}\"", k, cellText));
				Cell dstTableCell = new Cell(dstDoc);
				dstTableRow.appendChild(dstTableCell);
				Cell srcTableCell = srcCells.get(k);
				
				//Check whether source cell is merged or not
				//System.out.println("MERGED CELL :::: "+printCellMergeType(srcTableCell));
				
				boolean isHorizontallyMerged = srcTableCell.getCellFormat().getHorizontalMerge() != CellMerge.NONE;
				boolean isVerticallyMerged = srcTableCell.getCellFormat().getVerticalMerge() != CellMerge.NONE;
				
				System.out.println("isHorizontallyMerged :::"+isHorizontallyMerged + "Vertically merged ::: "+isVerticallyMerged);

Regards,
Krsna

@contactkrsna1

We have tested the scenario using the latest version of Aspose.Words for Java 19.11 and noticed that CellFormat.VerticalMerge and CellFormat.HorizontalMerge properties return correct values. Please use the latest version of Aspose.Words for Java 19.11.

If you still face problem, please attach the following resources here for testing:

  • Please attach the output Word file that shows the undesired behavior.
  • Please attach the expected output Word file that shows the desired behavior.
  • Please create a simple Java application ( source code without compilation errors ) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.