原創(chuàng)|其它|編輯:郝浩|2012-11-01 16:27:32.000|閱讀 10891 次
概述:使用Aspose.Words實現(xiàn)文檔合并是非常簡單的,Aspose.Words提供了一個特殊的Document.AppendDocument方法實現(xiàn)這個目的,并用于連接兩個文檔。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
使用Aspose.Words實現(xiàn)文檔合并是非常簡單的,Aspose.Words提供了一個特殊的Document.AppendDocument方法實現(xiàn)這個目的,并用于連接兩個文檔。
這個方法將所需文檔部分從源文檔復制到目標文檔。這就消除了任何在自動化中所需要的分節(jié)符插入。
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
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都控件網(wǎng)