原創(chuàng)|其它|編輯:郝浩|2012-09-18 11:57:57.000|閱讀 848 次
概述:當(dāng)我們復(fù)制一個(gè)文件的某些內(nèi)容到另一個(gè)文件時(shí),我們經(jīng)常會(huì)對(duì)ImportFormat模式進(jìn)行選擇。ImportFormatMode.KeepSourceFormatting將保留在源文件中使用的原始格式的,而ImportFormatMode.UseDestinationStyles會(huì)使用在目標(biāo)文檔中定義的格式。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門(mén)軟控件火熱銷售中 >>
當(dāng)我們復(fù)制一個(gè)文件的某些內(nèi)容到另一個(gè)文件時(shí),我們經(jīng)常會(huì)對(duì)Aspose.Words .NET 導(dǎo)入模式進(jìn)行選擇。
ImportFormatMode.KeepSourceFormatting將保留在源文件中使用的原始格式的,而ImportFormatMode.UseDestinationStyles會(huì)使用在目標(biāo)文檔中定義的格式。微軟Word也在復(fù)制內(nèi)容到另一個(gè)文件時(shí),提供了此選項(xiàng)選擇。
那么,Aspose.Words for .NET又是如何實(shí)現(xiàn)這兩種模式的選擇的呢?答案就在下面:
保留原格式的代碼如下:
C#
// Load the documents to join.
Document dstDoc = new Document(gDataDir + "TestFile.Destination.doc");
Document srcDoc = new Document(gDataDir + "TestFile.Source.doc");
// Keep the formatting from the source document when appending it to the destination document.
dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting);
// Save the joined document to disk.
dstDoc.Save(gDataDir + "TestFile.KeepSourceFormatting Out.docx");
Visual Basic
' Load the documents to join.
Dim dstDoc As New Document(gDataDir & "TestFile.Destination.doc")
Dim srcDoc As New Document(gDataDir & "TestFile.Source.doc")
' Keep the formatting from the source document when appending it to the destination document.
dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting)
' Save the joined document to disk.
dstDoc.Save(gDataDir & "TestFile.KeepSourceFormatting Out.docx")
運(yùn)行以上代碼后,目標(biāo)文件不存在的格式也被復(fù)制過(guò)來(lái)了
而我們使用目標(biāo)格式就不會(huì)有新的格式被創(chuàng)建,代碼如下:
C#
// Load the documents to join.
Document dstDoc = new Document(gDataDir + "TestFile.Destination.doc");
Document srcDoc = new Document(gDataDir + "TestFile.Source.doc");
// Append the source document using the styles of the destination document.
dstDoc.AppendDocument(srcDoc, ImportFormatMode.UseDestinationStyles);
// Save the joined document to disk.
dstDoc.Save(gDataDir + "TestFile.UseDestinationStyles Out.doc");
Visual Basic
' Load the documents to join.
Dim dstDoc As New Document(gDataDir & "TestFile.Destination.doc")
Dim srcDoc As New Document(gDataDir & "TestFile.Source.doc")
' Append the source document using the styles of the destination document.
dstDoc.AppendDocument(srcDoc, ImportFormatMode.UseDestinationStyles)
' Save the joined document to disk.
dstDoc.Save(gDataDir & "TestFile.UseDestinationStyles Out.doc")
效果圖如下:
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都控件網(wǎng)