来源于慧都控件网
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"
)
|