本文整理汇总了C#中Aspose.Words.Document.AppendDocument方法的典型用法代码示例。如果您正苦于以下问题:C# Document.AppendDocument方法的具体用法?C# Document.AppendDocument怎么用?C# Document.AppendDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Aspose.Words.Document
的用法示例。
在下文中一共展示了Document.AppendDocument方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AppendDocumentFromAutomation
public void AppendDocumentFromAutomation()
{
//ExStart
//ExId:AppendDocumentFromAutomation
//ExSummary:Shows how to join multiple documents together.
// The document that the other documents will be appended to.
Aspose.Words.Document doc = new Aspose.Words.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.
Aspose.Words.Document srcDoc = new Aspose.Words.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);
}
//ExEnd
}
示例2: AppendAllDocumentsInFolder
public void AppendAllDocumentsInFolder()
{
// Delete the file that was created by the previous run as I don't want to append it again.
File.Delete(MyDir + "Document.AppendDocumentsFromFolder Out.doc");
//ExStart
//ExFor:Document.AppendDocument(Document, ImportFormatMode)
//ExSummary:Shows how to use the AppendDocument method to combine all the documents in a folder to the end of a template document.
// Lets start with a simple template and append all the documents in a folder to this document.
Aspose.Words.Document baseDoc = new Aspose.Words.Document();
// Add some content to the template.
DocumentBuilder builder = new DocumentBuilder(baseDoc);
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;
builder.Writeln("Template Document");
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Normal;
builder.Writeln("Some content here");
// Gather the files which will be appended to our template document.
// In this case we add the optional parameter to include the search only for files with the ".doc" extension.
ArrayList files = new ArrayList(Directory.GetFiles(MyDir, "*.doc"));
// The list of files may come in any order, let's sort the files by name so the documents are enumerated alphabetically.
files.Sort();
// Iterate through every file in the directory and append each one to the end of the template document.
foreach (string fileName in files)
{
// We have some encrypted test documents in our directory, Aspose.Words can open encrypted documents
// but only with the correct password. Let's just skip them here for simplicity.
FileFormatInfo info = FileFormatUtil.DetectFileFormat(fileName);
if (info.IsEncrypted)
continue;
Aspose.Words.Document subDoc = new Aspose.Words.Document(fileName);
baseDoc.AppendDocument(subDoc, ImportFormatMode.UseDestinationStyles);
}
// Save the combined document to disk.
baseDoc.Save(MyDir + "Document.AppendDocumentsFromFolder Out.doc");
//ExEnd
}
示例3: AppendDocument
public void AppendDocument()
{
//ExStart
//ExFor:Document.AppendDocument(Document, ImportFormatMode)
//ExSummary:Shows how to append a document to the end of another document.
// The document that the content will be appended to.
Aspose.Words.Document dstDoc = new Aspose.Words.Document(MyDir + "Document.doc");
// The document to append.
Aspose.Words.Document srcDoc = new Aspose.Words.Document(MyDir + "DocumentBuilder.doc");
// Append the source document to the destination document.
// Pass format mode to retain the original formatting of the source document when importing it.
dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting);
// Save the document.
dstDoc.Save(MyDir + "Document.AppendDocument Out.doc");
//ExEnd
}