Vertical Cell Alignment Across multiple pages

I want the text of cell1 to bottom align. This works, until the table row spans multiple pages. See attached screenshot of output Docx.


How can I get cell1 to bottom align onto the next page in this instance?

Thanks.

Code is as follows:

com.aspose.words.Document doc = new com.aspose.words.Document();
DocumentBuilder docBuilder = new DocumentBuilder(doc);
Font font = docBuilder.getFont();
font.setSize(10);
font.setName(“Arial”);

docBuilder.startTable();
Cell labelCell = docBuilder.insertCell();
labelCell.getCellFormat().setVerticalAlignment(CellVerticalAlignment.BOTTOM);
docBuilder.write(“Cell 1”);

docBuilder.insertCell();
docBuilder.write(“Cell 2 \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n”);
docBuilder.write(“Cell 2 \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n”);
docBuilder.write(“End cell 2”);
docBuilder.endTable();


Hi Steven,


Thanks for your inquiry. Please note that Aspose.Words mimics the same behavior as MS Word does. If you create the same table using MS Word, you will get the same bottom alignment output.

Please manually create your expected Word document using Microsoft Word and attach it here for our reference. We will investigate how you want your final Word output be generated like. We will then provide you more information on this along with code.

Please see attached.


The goal here is to get Cell 1 text to bottom align after the table row extends to page 2.

Hi Steven,


Thanks for sharing the detail. You are inserting the empty paragraphs in the expected document. See the attached image for detail. Please insert the empty paragraphs in the table’s cell to get the required output.

Is there a way, using Aspose to say, “Insert paragraphs until the text in Cell 1 bottom aligns with bottom of cell 2”?

Hi Steven,


Thanks for your inquiry. Please use following code example to get the desired output. Hope this helps you.

<pre style=“color: rgb(0, 0, 0); font-family: “Courier New”; font-size: 9pt;”>com.aspose.words.Document doc = new com.aspose.words.Document();
DocumentBuilder docBuilder = new DocumentBuilder(doc);
Font font = docBuilder.getFont();
font.setSize(10);
font.setName(“Arial”);

docBuilder.startTable();
Cell labelCell = docBuilder.insertCell();
docBuilder.write(“Cell 1”);

Cell secondCell = docBuilder.insertCell();
docBuilder.write(“Cell 2 \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n);
docBuilder.write(“Cell 2 \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n);
docBuilder.write(“End cell 2”);
docBuilder.endTable();

for (Paragraph paragraph : (Iterable)secondCell.getChildNodes(NodeType.PARAGRAPH, true))
{
labelCell.insertBefore(paragraph.deepClone(false), labelCell.getFirstParagraph());
}

doc.save(MyDir + “Out v16.12.0.docx”);

OK I think I know what I want to accomplish here, along the lines of where you are going.


I want to insert paragraph nodes into cell one, until I have hit the bottom. How can I write code that will say, “Insert paragraph nodes until I have increased the height of the table, then stop”

Hi Steven,


Thanks for your inquiry. In this case, we suggest you following solution. Hope this helps you.

<pre style=“color: rgb(0, 0, 0); font-family: “Courier New”; font-size: 9pt;”>com.aspose.words.Document doc = new com.aspose.words.Document();
DocumentBuilder docBuilder = new DocumentBuilder(doc);
Font font = docBuilder.getFont();
font.setSize(10);
font.setName(“Arial”);

Table table = docBuilder.startTable();
Cell labelCell = docBuilder.insertCell();
docBuilder.write(“Cell 1”);

Cell secondCell = docBuilder.insertCell();
docBuilder.write(“Cell 2 \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n);
docBuilder.write(“Cell 2 \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n);
docBuilder.write(“End cell 2”);
docBuilder.endTable();
docBuilder.insertParagraph();
docBuilder.startBookmark(“bookmark”);
docBuilder.endBookmark(“bookmark”);

doc.updatePageLayout();
BookmarkStart bs = doc.getRange().getBookmarks().get(“bookmark”).getBookmarkStart();

LayoutCollector layoutCollector = new LayoutCollector(doc);
LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);

Object renderObject = layoutCollector.getEntity(bs);
layoutEnumerator.setCurrent(renderObject);

double position = layoutEnumerator.getRectangle().getY();

System.out.println(position);

while(true)
{
Paragraph paragraph = new Paragraph(doc);
labelCell.insertBefore(paragraph, labelCell.getFirstParagraph());

layoutCollector = new LayoutCollector(doc);
layoutEnumerator = new LayoutEnumerator(doc);

renderObject = layoutCollector.getEntity(bs);
layoutEnumerator.setCurrent(renderObject);
System.out.println(layoutEnumerator.getRectangle().getY());
if(layoutEnumerator.getRectangle().getY() > position)
{
break;
}
}
doc.save(MyDir + “Out v16.12.0.docx”);

Thanks for the solution. This gets me very very close, but I’m still seeing an issue when the table spans multiple pages.


How can we tweak that logic to say to go off the length of the document and not the table. Insert paragraph until document rectangle etc has increased in Y, then stop.

Thanks!

Hi Steven,


Thanks for your inquiry. Please share your input and expected output Word documents. We will then provide you more information about your query.

OK I’m not sure we’re going down the right path so I am going to try this again.


Attached are two Word Documents. One, where cell one bottom aligns as expected, because the table fits well within one page. The Second, you will notice cell one bottom aligns at the bottom of page one, but cell 2 text goes to the next page. I am trying to get cell one text to go to the bottom, inline with bottom of cell 2.

Here is the code I am using:

com.aspose.words.Document doc = new com.aspose.words.Document();
DocumentBuilder docBuilder = new DocumentBuilder(doc);
Font font = docBuilder.getFont();
font.setSize(10);
font.setName(“Arial”);

docBuilder.startTable();
Cell labelCell = docBuilder.insertCell();
labelCell.getCellFormat().setVerticalAlignment(CellVerticalAlignment.BOTTOM);
docBuilder.write(“Cell 1”);

docBuilder.insertCell();
docBuilder.write(“Cell 2 Text \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n”);
docBuilder.write(“Cell 2 More text\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n”);
docBuilder.write(“End cell 2”);
docBuilder.endTable();

doc.save(documentPath);




Hi Steven,

Thanks for your inquiry. According to your required output, we already shared two code examples in this forum thread. These examples generate your desired output. Are you facing any issue while using them? Please try the shared code examples and let us know if you have any more queries.