用Aspose.Words從HTML中插入一個表

來源於慧都控件網

Aspose.Words使用DocumentBuilder.InsertHtml方法,就可以支持插入爲一個HTML源中的文檔插入內容。 輸入可以是一個完整的HTML頁面或只是一個部分片段。使用這種方法我們可以利用表元素如< table >、< tr >、< td >爲我們的文檔插入表。

C#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Document doc = new Document();
DocumentBuilder builder =new DocumentBuilder(doc);
  
// Insert the table from HTML. Note that AutoFitSettings does not apply to tables
// inserted from HTML.
builder.InsertHtml("<table>"               
                   "<tr>"                  +
                   "<td>Row 1, Cell 1</td>"+
                   "<td>Row 1, Cell 2</td>"+
                   "</tr>"                 +
                   "<tr>"                  
                   "<td>Row 2, Cell 2</td>"
                   "<td>Row 2, Cell 2</td>"
                   "</tr>"                 +
                   "</table>");
  
doc.Save(MyDir +"DocumentBuilder.InsertTableFromHtml Out.doc");

Visual Basic

1
2
3
4
5
6
7
8
Dim doc As NewDocument()
Dim builder As NewDocumentBuilder(doc)
  
' Insert the table from HTML. Note that AutoFitSettings does not apply to tables
' inserted from HTML.
builder.InsertHtml("<table>"& "<tr>" & "<td>Row 1, Cell 1</td>" & "<td>Row 1, Cell 2</td>" & "</tr>" & "<tr>"& "<td>Row 2, Cell 2</td>"& "<td>Row 2, Cell 2</td>"& "</tr>" & "</table>")
  
doc.Save(MyDir & "DocumentBuilder.InsertTableFromHtml Out.doc")
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章