本文整理汇总了C#中Document.AppendDocument方法的典型用法代码示例。如果您正苦于以下问题:C# Document.AppendDocument方法的具体用法?C# Document.AppendDocument怎么用?C# Document.AppendDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Document
的用法示例。
在下文中一共展示了Document.AppendDocument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
string FilePath = @"..\..\..\Sample Files\";
string SrcFileName = FilePath + "Joining Mutiple documents 1.docx";
string DestFileName = FilePath + "Joining Mutiple documents 2.docx";
// The document that the other documents will be appended to.
Document dstDoc = new Document();
// We should call this method to clear this document of any existing content.
dstDoc.RemoveAllChildren();
int recordCount = 1;
for (int i = 1; i <= recordCount; i++)
{
// Open the document to join.
Document srcDoc = new Document(SrcFileName);
// Append the source document at the end of the destination document.
dstDoc.AppendDocument(srcDoc, ImportFormatMode.UseDestinationStyles);
Document doc2 = new Document(DestFileName);
dstDoc.AppendDocument(doc2, ImportFormatMode.UseDestinationStyles);
// 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)
dstDoc.Sections[i].HeadersFooters.LinkToPrevious(false);
}
dstDoc.Save(DestFileName);
}
示例2: Main
static void Main(string[] args)
{
// The document that the other documents will be appended to.
Document dstDoc = new Document();
// We should call this method to clear this document of any existing content.
dstDoc.RemoveAllChildren();
int recordCount = 1;
for (int i = 1; i <= recordCount; i++)
{
// Open the document to join.
Document srcDoc = new Document("src.doc");
// Append the source document at the end of the destination document.
dstDoc.AppendDocument(srcDoc, ImportFormatMode.UseDestinationStyles);
Document doc2 = new Document("Section.ModifyPageSetupInAllSections.doc");
dstDoc.AppendDocument(doc2, 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)
dstDoc.Sections[i].HeadersFooters.LinkToPrevious(false);
}
dstDoc.Save("updated.doc");
}
示例3: Run
public static void Run()
{
// ExStart:ConvertNumPageFields
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_JoiningAndAppending();
string fileName = "TestFile.Destination.doc";
Document dstDoc = new Document(dataDir + fileName);
Document srcDoc = new Document(dataDir + "TestFile.Source.doc");
// Restart the page numbering on the start of the source document.
srcDoc.FirstSection.PageSetup.RestartPageNumbering = true;
srcDoc.FirstSection.PageSetup.PageStartingNumber = 1;
// Append the source document to the end of the destination document.
dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting);
// After joining the documents the NUMPAGE fields will now display the total number of pages which
// Is undesired behavior. Call this method to fix them by replacing them with PAGEREF fields.
ConvertNumPageFieldsToPageRef(dstDoc);
// This needs to be called in order to update the new fields with page numbers.
dstDoc.UpdatePageLayout();
dataDir = dataDir + RunExamples.GetOutputFilePath(fileName);
dstDoc.Save(dataDir);
// ExEnd:ConvertNumPageFields
Console.WriteLine("\nDocument appended successfully with conversion of NUMPAGE fields with PAGEREF fields.\nFile saved at " + dataDir);
}
示例4: Run
public static void Run()
{
// ExStart:KeepSourceTogether
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_JoiningAndAppending();
string fileName = "TestFile.DestinationList.doc";
Document dstDoc = new Document(dataDir + fileName);
Document srcDoc = new Document(dataDir + "TestFile.Source.doc");
// Set the source document to appear straight after the destination document's content.
srcDoc.FirstSection.PageSetup.SectionStart = SectionStart.Continuous;
// Iterate through all sections in the source document.
foreach (Paragraph para in srcDoc.GetChildNodes(NodeType.Paragraph, true))
{
para.ParagraphFormat.KeepWithNext = true;
}
dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting);
dataDir = dataDir + RunExamples.GetOutputFilePath(fileName);
dstDoc.Save(dataDir);
// ExEnd:KeepSourceTogether
Console.WriteLine("\nDocument appended successfully while keeping the content from splitting across two pages.\nFile saved at " + dataDir);
}
示例5: Run
public static void Run()
{
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_JoiningAndAppending();
string fileName = "TestFile.Destination.doc";
Document dstDoc = new Document(dataDir + fileName);
Document srcDoc = new Document(dataDir + "TestFile.Source.doc");
// Remove the headers and footers from each of the sections in the source document.
foreach (Section section in srcDoc.Sections)
{
section.ClearHeadersFooters();
}
// Even after the headers and footers are cleared from the source document, the "LinkToPrevious" setting
// for HeadersFooters can still be set. This will cause the headers and footers to continue from the destination
// document. This should set to false to avoid this behavior.
srcDoc.FirstSection.HeadersFooters.LinkToPrevious(false);
dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting);
dataDir = dataDir + RunExamples.GetOutputFilePath(fileName);
dstDoc.Save(dataDir);
Console.WriteLine("\nDocument appended successfully with source header footers removed.\nFile saved at " + dataDir);
}
示例6: Run
public static void Run()
{
// ExStart:UpdatePageLayout
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_JoiningAndAppending();
string fileName = "TestFile.Destination.doc";
Document dstDoc = new Document(dataDir + fileName);
Document srcDoc = new Document(dataDir + "TestFile.Source.doc");
// If the destination document is rendered to PDF, image etc or UpdatePageLayout is called before the source document
// Is appended then any changes made after will not be reflected in the rendered output.
dstDoc.UpdatePageLayout();
// Join the documents.
dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting);
// For the changes to be updated to rendered output, UpdatePageLayout must be called again.
// If not called again the appended document will not appear in the output of the next rendering.
dstDoc.UpdatePageLayout();
dataDir = dataDir + RunExamples.GetOutputFilePath(fileName);
// Save the joined document to PDF.
dstDoc.Save(dataDir);
// ExEnd:UpdatePageLayout
Console.WriteLine("\nDocument appended successfully with updated page layout after appending the document.\nFile saved at " + dataDir);
}
示例7: Run
public static void Run()
{
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_JoiningAndAppending();
Document dstDoc = new Document(dataDir + "TestFile.Destination.doc");
Document srcDoc = new Document(dataDir + "TestFile.SourcePageSetup.doc");
// Set the source document to continue straight after the end of the destination document.
// If some page setup settings are different then this may not work and the source document will appear
// on a new page.
srcDoc.FirstSection.PageSetup.SectionStart = SectionStart.Continuous;
// To ensure this does not happen when the source document has different page setup settings make sure the
// settings are identical between the last section of the destination document.
// If there are further continuous sections that follow on in the source document then this will need to be
// repeated for those sections as well.
srcDoc.FirstSection.PageSetup.PageWidth = dstDoc.LastSection.PageSetup.PageWidth;
srcDoc.FirstSection.PageSetup.PageHeight = dstDoc.LastSection.PageSetup.PageHeight;
srcDoc.FirstSection.PageSetup.Orientation = dstDoc.LastSection.PageSetup.Orientation;
dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting);
dstDoc.Save(dataDir + "TestFile.DifferentPageSetup Out.doc");
Console.WriteLine("\nDocument appended successfully with different page setup.\nFile saved at " + dataDir + "TestFile.DifferentPageSetup Out.doc");
}
示例8: Run
public static void Run()
{
// ExStart:ListUseDestinationStyles
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_JoiningAndAppending();
string fileName = "TestFile.DestinationList.doc";
Document dstDoc = new Document(dataDir + fileName);
Document srcDoc = new Document(dataDir + "TestFile.SourceList.doc");
// Set the source document to continue straight after the end of the destination document.
srcDoc.FirstSection.PageSetup.SectionStart = SectionStart.Continuous;
// Keep track of the lists that are created.
Hashtable newLists = new Hashtable();
// Iterate through all paragraphs in the document.
foreach (Paragraph para in srcDoc.GetChildNodes(NodeType.Paragraph, true))
{
if (para.IsListItem)
{
int listId = para.ListFormat.List.ListId;
// Check if the destination document contains a list with this ID already. If it does then this may
// Cause the two lists to run together. Create a copy of the list in the source document instead.
if (dstDoc.Lists.GetListByListId(listId) != null)
{
List currentList;
// A newly copied list already exists for this ID, retrieve the stored list and use it on
// The current paragraph.
if (newLists.Contains(listId))
{
currentList = (List)newLists[listId];
}
else
{
// Add a copy of this list to the document and store it for later reference.
currentList = srcDoc.Lists.AddCopy(para.ListFormat.List);
newLists.Add(listId, currentList);
}
// Set the list of this paragraph to the copied list.
para.ListFormat.List = currentList;
}
}
}
// Append the source document to end of the destination document.
dstDoc.AppendDocument(srcDoc, ImportFormatMode.UseDestinationStyles);
dataDir = dataDir + RunExamples.GetOutputFilePath(fileName);
// Save the combined document to disk.
dstDoc.Save(dataDir);
// ExEnd:ListUseDestinationStyles
Console.WriteLine("\nDocument appended successfully without continuing any list numberings.\nFile saved at " + dataDir);
}
示例9: Main
public static void Main(string[] args)
{
// The path to the documents directory.
string dataDir = Path.GetFullPath("../../../Data/");
// Load the destination and source documents from disk.
Document dstDoc = new Document(dataDir + "TestFile.Destination.doc");
Document srcDoc = new Document(dataDir + "TestFile.Source.doc");
// Append the source document to the destination document while keeping the original formatting of the source document.
dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting);
dstDoc.Save(dataDir + "TestFile Out.docx");
}
示例10: Run
public static void Run()
{
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_JoiningAndAppending();
Document dstDoc = new Document(dataDir + "TestFile.Destination.doc");
Document srcDoc = new Document(dataDir + "TestFile.Source.doc");
// Append the source document to the destination document using no extra options.
dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting);
dstDoc.Save(dataDir + "TestFile.SimpleAppendDocument Out.docx");
Console.WriteLine("\nSimple document append.\nFile saved at " + dataDir + "TestFile.SimpleAppendDocument Out.docx");
}
示例11: Run
public static void Run()
{
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_JoiningAndAppending();
Document dstDoc = new Document(dataDir + "TestFile.DestinationList.doc");
Document srcDoc = new Document(dataDir + "TestFile.SourceList.doc");
// Append the content of the document so it flows continuously.
srcDoc.FirstSection.PageSetup.SectionStart = SectionStart.Continuous;
dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting);
dstDoc.Save(dataDir + "TestFile.ListKeepSourceFormatting Out.doc");
Console.WriteLine("\nDocument appended successfully with lists retaining source formatting.\nFile saved at " + dataDir + "TestFile.ListKeepSourceFormatting Out.doc");
}
示例12: Run
public static void Run()
{
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_QuickStart();
// Load the destination and source documents from disk.
Document dstDoc = new Document(dataDir + "TestFile.Destination.doc");
Document srcDoc = new Document(dataDir + "TestFile.Source.doc");
// Append the source document to the destination document while keeping the original formatting of the source document.
dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting);
dstDoc.Save(dataDir + "TestFile Out.docx");
Console.WriteLine("\nDocument appended successfully.\nFile saved at " + dataDir + "TestFile Out.docx");
}
示例13: Run
public static void Run()
{
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_JoiningAndAppending();
Document dstDoc = new Document(dataDir + "TestFile.Destination.doc");
Document srcDoc = new Document(dataDir + "TestFile.Source.doc");
// Set the appended document to start on a new page.
srcDoc.FirstSection.PageSetup.SectionStart = SectionStart.NewPage;
// Append the source document using the original styles found in the source document.
dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting);
dstDoc.Save(dataDir + "TestFile.JoinNewPage Out.doc");
Console.WriteLine("\nDocument appended successfully with new section start.\nFile saved at " + dataDir + "TestFile.JoinNewPage Out.doc");
}
示例14: Run
public static void Run()
{
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_JoiningAndAppending();
Document dstDoc = new Document(dataDir + "TestFile.Destination.doc");
Document srcDoc = new Document(dataDir + "TestFile.Source.doc");
// Unlink the headers and footers in the source document to stop this from continuing the headers and footers
// from the destination document.
srcDoc.FirstSection.HeadersFooters.LinkToPrevious(false);
dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting);
dstDoc.Save(dataDir + "TestFile.UnlinkHeadersFooters Out.doc");
Console.WriteLine("\nDocument appended successfully with unlinked header footers.\nFile saved at " + dataDir + "TestFile.UnlinkHeadersFooters Out.doc");
}
示例15: Run
public static void Run()
{
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_JoiningAndAppending();
// Load the documents to join.
Document dstDoc = new Document(dataDir + "TestFile.Destination.doc");
Document srcDoc = new Document(dataDir + "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(dataDir + "TestFile.UseDestinationStyles Out.doc");
Console.WriteLine("\nDocument appended successfully with use destination styles option.\nFile saved at " + dataDir + "TestFile.UseDestinationStyles Out.doc");
}