【问题标题】:Aspose Java - Add Table below a list valueAspose Java - 在列表值下方添加表格
【发布时间】:2017-06-20 12:24:36
【问题描述】:

以下是我要生成的格式:

根据我对 API 的有限经验,我知道如何制作列表

ListFormat listFormat = builder.getListFormat();
listFormat.setList(document.getLists().add(ListTemplate.NUMBER_DEFAULT));
builder.writeln("Component Specification")
listFormat.setListLevelNumber(1);
builder.writeln("Raw Material Specification")

现在如何从列表过渡到下表? 写一个新行会添加数字,即使是在表格的单元格中。

如果我将 listformat 设置为 null,那么缩进就会丢失。我想保持列表的缩进,但还要在该列表值下方添加表格

无论如何要这样做?

【问题讨论】:

    标签: java aspose.words


    【解决方案1】:

    @Furqan,

    您需要根据您的要求设置 Table LeftIndent 属性。请检查以下示例代码 sn-p。

    我是 Aspose 的开发布道师 Tilal Ahmad。

    Document doc= new Document();
    DocumentBuilder builder= new DocumentBuilder(doc);
    
    ListFormat listFormat = builder.getListFormat();
    listFormat.setList(doc.getLists().add(ListTemplate.NUMBER_DEFAULT));
    builder.writeln("Component Specification");
    builder.getListFormat().listIndent();
    builder.getListFormat().getListLevel().setNumberStyle(NumberStyle.ARABIC);
    builder.getListFormat().getListLevel().setNumberFormat("\u0000.\u0001");
    builder.writeln("Raw Material Specification");
    builder.getListFormat().removeNumbers();
    
    Table table = new Table(doc);
    
    // Add the table to the document.
    doc.getFirstSection().getBody().appendChild(table);
    
    Row row1 = new Row(doc);
    row1.getRowFormat().setAllowBreakAcrossPages(true);
    table.appendChild(row1);
    
    
    // Create a cell and add it to the row
    Cell cell1 = new Cell(doc);
    cell1.getCellFormat().getShading()
            .setBackgroundPatternColor(Color.LIGHT_GRAY);
    cell1.getCellFormat().setWidth(50);
    
    // Add a paragraph to the cell as well as a new run with some text.
    cell1.appendChild(new Paragraph(doc));
    cell1.getFirstParagraph().appendChild(new Run(doc, "Col1"));
    
    // Add the cell to the row.
    row1.appendChild(cell1);
    
    // We would then repeat the process for the other cells and rows in the
    // table.
    // We can also speed things up by cloning existing cells and rows.
    row1.appendChild(cell1.deepClone(false));
    row1.getLastCell().appendChild(new Paragraph(doc));
    row1.getLastCell().getFirstParagraph()
            .appendChild(new Run(doc, "Col2"));
    
    row1.appendChild(cell1.deepClone(false));
    row1.getLastCell().appendChild(new Paragraph(doc));
    row1.getLastCell().getFirstParagraph()
            .appendChild(new Run(doc, "Col3"));
    
    
    Row row = new Row(doc);
    row.getRowFormat().setAllowBreakAcrossPages(true);
    table.appendChild(row);
    
    // Create a cell and add it to the row
    Cell cell = new Cell(doc);
    cell.getCellFormat().setWidth(50);
    
    // Add a paragraph to the cell as well as a new run with some text.
    cell.appendChild(new Paragraph(doc));
    cell.getFirstParagraph()
            .appendChild(new Run(doc, "Row 1, Cell 1 Text"));
    
    // Add the cell to the row.
    row.appendChild(cell);
    
    row.appendChild(cell.deepClone(false));
    row.getLastCell().appendChild(new Paragraph(doc));
    row.getLastCell().getFirstParagraph()
            .appendChild(new Run(doc, "Row 1, Cell 2 Text"));
    
    row.appendChild(cell.deepClone(false));
    row.getLastCell().appendChild(new Paragraph(doc));
    row.getLastCell().getFirstParagraph()
            .appendChild(new Run(doc, "Row 1, Cell 3 Text"));
    // Add left indent to the table.
    table.setLeftIndent(60);
    
    
    doc.save("E:/Data/Test1.docx");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-22
      • 2020-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多