Hi,
I populate word table like this (code below). And I would like to insert text in variable run aligned to the right. I have tried many things but nothing works. Can you please help?
var entryTable = bm.getBookmarkStart().getAncestor(com.aspose.words.NodeType.TABLE);
if (entryTable != null) {
var myArray = ['A', 'B', 'C', 'D', 'E'];
var passes = myArray.length;
var index = 1;
while (...(id, myArray[0]+index)!="")
{
var cRow = entryTable.getLastRow().deepClone(true);
for (var j = 0; j < passes; j++) {
var run = cRow.getCells().get(j).getFirstParagraph().getRuns().get(0).deepClone(true);
var key = ...(id, myArray[j]+index);
run.setText(key);
cRow.getCells().get(j).removeAllChildren();
cRow.getCells().get(j).ensureMinimum();
cRow.getCells().get(j).getParagraphs().get(0).appendChild(run);
}
index++;
entryTable.appendChild(cRow);
}
entryTable.getRows().get(1).remove();
} else {
log.warn(LOG_PREFIX + "...");
}
@helpMeWithThisProblemPlease
Thanks for your inquiry. Please iterate over paragraph nodes of table’s cell and set the ParagraphFormat.Alignment property as ParagraphAlignment.RIGHT to get the desired output.
Thank you for your reply. Shouldn’t this be enough:
cRow.getCells().get(j).getParagraphs().get(0).appendChild(run);
cRow.getCells().get(j).getParagraphs().get(0).ParagraphFormat.Alignment = "ParagraphAlignment.RIGHT";
Except I get this error:
TypeError: Cannot set property “Alignment” of undefined to “ParagraphAlignment.RIGHT”
I also tried:
cRow.getCells().get(j).getParagraphs().get(0).ParagraphFormat.Alignment = "ParagraphAlignment.RIGHT";
cRow.getCells().get(j).getParagraphs().get(0).appendChild(run);
If I try:
cRow.getCells().get(j).getParagraphs().get(0).ParagraphFormat.Alignment = ParagraphAlignment.RIGHT;
I get:
ReferenceError: “ParagraphAlignment” is not defined.
If I add:
var paragraphFormat = builder.ParagraphFormat;
I get:
TypeError: Cannot read property “ParagraphFormat” from undefined
Please, can you be more specific?
@helpMeWithThisProblemPlease
Thanks for your inquiry. Please set the paragraph alignment as shown below.
cRow.getCells().get(j).getParagraphs().get(0).getParagraphFormat().setAlignment(ParagraphAlignment.RIGHT);
We suggest you please read the following article.
Paragraph Formatting
Thank you for your reply.
I should have said that I also tried:
cRow.getCells().get(j).getParagraphs().get(0).getParagraphFormat().setAlignment(ParagraphAlignment.RIGHT);
cRow.getCells().get(j).getParagraphs().get(0).getParagraphFormat().setAlignment(String(ParagraphAlignment.RIGHT));
And got:
ReferenceError: “ParagraphAlignment” is not defined.
And:
cRow.getCells().get(j).getParagraphs().get(0).getParagraphFormat().setAlignment("ParagraphAlignment.RIGHT");
And got:
InternalError: Cannot convert ParagraphAlignment.RIGHT to java.lang.Integer
What do I miss? Is there some javapackage which must be imported or somethig like this?
@helpMeWithThisProblemPlease
Thanks for your inquiry. Perhaps, you are using older version of Aspose.Words. Please use the latest version of Aspose.Words for Java 18.11.
Moreover, please check Aspose.Words for Java 18.11 - API Reference.