2017-06-20 91 views
-1

以下是我要生成的格式:的Aspose爪哇 - 添加下面的列表值表

enter image description here

從我有限的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,那麼縮進將會丟失。我想維護列表的縮進,但也添加下面的列表值

無論如何要做到這一點?

回答

0

@Furqan,

您需要設置表leftindent上屬性您的要求。請檢查以下示例代碼片段。

我是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");