彩票走势图

Aspose.Words文档合并实现方法(含C#、VB代码)

原创|其它|编辑:郝浩|2012-11-01 16:27:32.000|阅读 10860 次

概述:使用Aspose.Words实现文档合并是非常简单的,Aspose.Words提供了一个特殊的Document.AppendDocument方法实现这个目的,并用于连接两个文档。

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

使用Aspose.Words实现文档合并是非常简单的,Aspose.Words提供了一个特殊的Document.AppendDocument方法实现这个目的,并用于连接两个文档。

这个方法将所需文档部分从源文档复制到目标文档。这就消除了任何在自动化中所需要的分节符插入。

C#

// The document that the other documents will be appended to.
Document doc = new Document();
// We should call this method to clear this document of any existing content.
doc.RemoveAllChildren();

int recordCount = 5;
for (int i = 1; i <= recordCount; i++)
{
    // Open the document to join.
    Document srcDoc = new Document(@"C:\DetailsList.doc");

    // Append the source document at the end of the destination document.
    doc.AppendDocument(srcDoc, ImportFormatMode.UseDestinationStyles);

    // In automation you were required to insert a new section break at this point, however in Aspose.Words we
    // don't need to do anything here as the appended document is imported as separate sectons already.

    // If this is the second document or above being appended then unlink all headers footers in this section
    // from the headers and footers of the previous section.
    if (i > 1)
        doc.Sections[i].HeadersFooters.LinkToPrevious(false);
}
 

Visual Basic

' The document that the other documents will be appended to.
Dim doc As New Document()
' We should call this method to clear this document of any existing content.
doc.RemoveAllChildren()

Dim recordCount As Integer = 5
For i As Integer = 1 To recordCount
    ' Open the document to join.
    Dim srcDoc As New Document("C:\DetailsList.doc")

    ' Append the source document at the end of the destination document.
    doc.AppendDocument(srcDoc, ImportFormatMode.UseDestinationStyles)

    ' In automation you were required to insert a new section break at this point, however in Aspose.Words we
    ' don't need to do anything here as the appended document is imported as separate sectons already.

    ' If this is the second document or above being appended then unlink all headers footers in this section
    ' from the headers and footers of the previous section.
    If i > 1 Then
        doc.Sections(i).HeadersFooters.LinkToPrevious(False)
    End If
Next i

标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn

文章转载自:慧都控件网

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP