用Aspose.Words从HTML中插入一个表

来源:互联网 发布:淘宝手机退货退款流程 编辑:程序博客网 时间:2024/06/01 10:44

来源于慧都控件网

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 =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");

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")
原创粉丝点击