【问题标题】:Right alignment of text in table cell表格单元格中的文本右对齐
【发布时间】:2018-12-03 13:27:24
【问题描述】:

我像这样填充单词表(下面的代码)。我想在变量运行中插入文本,向右对齐。我尝试了很多东西,但没有任何效果。你能帮忙吗?

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 + "...");
}

【问题讨论】:

    标签: aspose aspose.words


    【解决方案1】:

    您可以使用以下代码右对齐表格单元格中的所有段落。

    Document doc = new Document("D:\\temp\\table.docx");
    
    Table table = doc.getFirstSection().getBody().getTables().get(0);
    
    for (Paragraph para : (Iterable<Paragraph>) table.getLastRow().getLastCell().getParagraphs())
    {
        para.getParagraphFormat().setAlignment(ParagraphAlignment.RIGHT);
    }
    
    doc.save("D:\\Temp\\18.11.docx");
    

    希望,这会有所帮助。我与 Aspose 一起担任开发人员宣传员。

    【讨论】:

      猜你喜欢
      • 2015-01-03
      • 2014-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-07
      • 2018-04-22
      • 1970-01-01
      相关资源
      最近更新 更多