來源於慧都控件網
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 New Document()
Dim
builder As 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" ) |