本文整理汇总了C#中Document.ImportNode方法的典型用法代码示例。如果您正苦于以下问题:C# Document.ImportNode方法的具体用法?C# Document.ImportNode怎么用?C# Document.ImportNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Document
的用法示例。
在下文中一共展示了Document.ImportNode方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Topic
/// <summary>
/// Creates a topic.
/// </summary>
public Topic(Section section, string fixUrl)
{
mTopicDoc = new Document();
mTopicDoc.AppendChild(mTopicDoc.ImportNode(section, true, ImportFormatMode.KeepSourceFormatting));
mTopicDoc.FirstSection.Remove();
Paragraph headingPara = (Paragraph)mTopicDoc.FirstSection.Body.FirstChild;
if (headingPara == null)
ThrowTopicException("The section does not start with a paragraph.", section);
mHeadingLevel = headingPara.ParagraphFormat.StyleIdentifier - StyleIdentifier.Heading1;
if ((mHeadingLevel < 0) || (mHeadingLevel > 8))
ThrowTopicException("This topic does not start with a heading style paragraph.", section);
mTitle = headingPara.GetText().Trim();
if (mTitle == "")
ThrowTopicException("This topic heading does not have text.", section);
// We actually remove the heading paragraph because <h1> will be output in the banner.
headingPara.Remove();
mTopicDoc.BuiltInDocumentProperties.Title = mTitle;
FixHyperlinks(section.Document, fixUrl);
}
示例2: 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");
ImportFormatMode mode = ImportFormatMode.KeepSourceFormatting;
// Loop through all sections in the source document.
// Section nodes are immediate children of the Document node so we can just enumerate the Document.
foreach (Section srcSection in srcDoc)
{
// Because we are copying a section from one document to another,
// it is required to import the Section node into the destination document.
// This adjusts any document-specific references to styles, lists, etc.
//
// Importing a node creates a copy of the original node, but the copy
// is ready to be inserted into the destination document.
Node dstSection = dstDoc.ImportNode(srcSection, true, mode);
// Now the new section node can be appended to the destination document.
dstDoc.AppendChild(dstSection);
}
dataDir = dataDir + RunExamples.GetOutputFilePath(fileName);
// Save the joined document
dstDoc.Save(dataDir);
Console.WriteLine("\nDocument appended successfully with manual append operation.\nFile saved at " + dataDir);
}
示例3: DoPrepend
public static void DoPrepend(Document dstDoc, Document srcDoc, ImportFormatMode mode)
{
// Loop through all sections in the source document.
// Section nodes are immediate children of the Document node so we can just enumerate the Document.
ArrayList sections = new ArrayList(srcDoc.Sections.ToArray());
// Reverse the order of the sections so they are prepended to start of the destination document in the correct order.
sections.Reverse();
foreach (Section srcSection in sections)
{
// Import the nodes from the source document.
Node dstSection = dstDoc.ImportNode(srcSection, true, mode);
// Now the new section node can be prepended to the destination document.
// Note how PrependChild is used instead of AppendChild. This is the only line changed compared
// to the original method.
dstDoc.PrependChild(dstSection);
}
}
示例4: AppendDoc
/// <summary>
/// Append all docs in a list into one doc.
/// </summary>
/// <param name="AllDocs">list of all docs</param>
/// <returns>one doc contains all docs.</returns>
public static byte[] AppendDoc(List<Byte[]> AllDocs)
{
// MemoryStream newStream = new MemoryStream();
Document masterDocument = new Document();
foreach (Byte[] doc in AllDocs)
{
using (MemoryStream childStream = new MemoryStream(doc))
{
Document child = new Document(childStream);
foreach (Section section in child.Sections)
{
Section dstSection = (Section)masterDocument.ImportNode(section, true, ImportFormatMode.UseDestinationStyles);
masterDocument.Sections.Add(dstSection);
}
}
}
using (MemoryStream finalStream = new MemoryStream())
{
masterDocument.Save(finalStream, SaveFormat.Doc);
return finalStream.GetBuffer();
}
}
示例5: AppendDocument
//ExEnd
//ExStart
//ExFor:DocumentBase.ImportNode(Node,bool,ImportFormatMode)
//ExFor:ImportFormatMode
//ExId:CombineDocuments
//ExSummary:Shows how to manually append the content from one document to the end of another document.
/// <summary>
/// A manual implementation of the Document.AppendDocument function which shows the general
/// steps of how a document is appended to another.
/// </summary>
/// <param name="dstDoc">The destination document where to append to.</param>
/// <param name="srcDoc">The source document.</param>
/// <param name="mode">The import mode to use when importing content from another document.</param>
public void AppendDocument(Document dstDoc, Document srcDoc, ImportFormatMode mode)
{
// Loop through all sections in the source document.
// Section nodes are immediate children of the Document node so we can just enumerate the Document.
foreach (Section srcSection in srcDoc)
{
// Because we are copying a section from one document to another,
// it is required to import the Section node into the destination document.
// This adjusts any document-specific references to styles, lists, etc.
//
// Importing a node creates a copy of the original node, but the copy
// is ready to be inserted into the destination document.
Node dstSection = dstDoc.ImportNode(srcSection, true, mode);
// Now the new section node can be appended to the destination document.
dstDoc.AppendChild(dstSection);
}
}
示例6: SaveHtmlTopic
/// <summary>
/// Saves one section of a document as an HTML file.
/// Any embedded images are saved as separate files in the same folder as the HTML file.
/// </summary>
private static void SaveHtmlTopic(Section section, Topic topic)
{
Document dummyDoc = new Document();
dummyDoc.RemoveAllChildren();
dummyDoc.AppendChild(dummyDoc.ImportNode(section, true, ImportFormatMode.KeepSourceFormatting));
dummyDoc.BuiltInDocumentProperties.Title = topic.Title;
HtmlSaveOptions saveOptions = new HtmlSaveOptions();
saveOptions.PrettyFormat = true;
// This is to allow headings to appear to the left of main text.
saveOptions.AllowNegativeLeftIndent = true;
saveOptions.ExportHeadersFootersMode = ExportHeadersFootersMode.None;
dummyDoc.Save(topic.FileName, saveOptions);
}
示例7: InsertBlockAtBookamrk
public static void InsertBlockAtBookamrk(Document brokerPlusDot, string bookmarkName, Document MainDoc, int type)
{
BuildingBlock block = null;
string bmark = type == 0 ? bookmarkName.ToUpper() : (bookmarkName.ToUpper() + "_" + type.ToString());
foreach (BuildingBlock b in brokerPlusDot.GlossaryDocument.BuildingBlocks)
{
if (b.Name.ToUpper() == bmark)
{
block = b;
break;
}
}
//Create DocumentBuilder
DocumentBuilder builder = new DocumentBuilder(MainDoc);
//Move cursor to bookmark and insert paragraph break
if (!builder.MoveToBookmark(bookmarkName, false, true) || block == null)
{
return;
}
//builder.MoveToBookmark(bookmarkName);
builder.Writeln();
//Content of srcdoc will be inserted after this node
Node insertAfterNode = builder.CurrentParagraph.PreviousSibling;
//Content of first paragraph of srcDoc will be apended to this parafraph
Paragraph insertAfterParagraph = (Paragraph)insertAfterNode;
//Content of last paragraph of srcDoc will be apended to this parafraph
Paragraph insertBeforeParagraph = builder.CurrentParagraph;
//We will be inserting into the parent of the destination paragraph.
CompositeNode dstStory = insertAfterNode.ParentNode;
//Get list if current paragraph is list item
List list = null;
Color listFontColor = Color.Black;
if (insertAfterParagraph.IsListItem)
{
list = insertAfterParagraph.ListFormat.List;
listFontColor = insertAfterParagraph.ListFormat.ListLevel.Font.Color;
}
//Loop through all sections in the source document.
foreach (Section srcSection in block.Sections)
{
//Loop through all block level nodes (paragraphs and tables) in the body of the section.
foreach (Node srcNode in srcSection.Body)
{
//Do not insert node if it is a last empty paragarph in the section.
Paragraph para = srcNode as Paragraph;
//If current paragraph is first paragraph of srcDoc
//then appent its content to insertAfterParagraph
if (para != null && (para.Equals(block.FirstSection.Body.FirstParagraph)))
{
Paragraph dstParagraph = (Paragraph)MainDoc.ImportNode(para, true, ImportFormatMode.KeepSourceFormatting);
while (dstParagraph.HasChildNodes)
{
//Node dstNode = MainDoc.ImportNode(node, true, ImportFormatMode.KeepSourceFormatting);
insertAfterParagraph.AppendChild(dstParagraph.FirstChild);
}
if (!insertAfterParagraph.IsListItem && dstParagraph.IsListItem)
{
if (list == null)
{
list = dstParagraph.ListFormat.List;
}
insertAfterParagraph.ListFormat.List = list;
listFontColor = para.ListFormat.ListLevel.Font.Color;
}
//If subdocument contains only one paragraph
//then copy content of insertBeforeParagraph to insertAfterParagraph
//and remove insertBeforeParagraph
if ((block.FirstSection.Body.FirstParagraph.Equals(block.LastSection.Body.LastParagraph)))
{
while ((insertBeforeParagraph.HasChildNodes))
{
insertAfterParagraph.AppendChild(insertBeforeParagraph.FirstChild);
}
insertBeforeParagraph.Remove();
}
}
//If current paragraph is last paragraph of srcDoc
//then appent its content to insertBeforeParagraph
else if (para != null && (para.Equals(block.LastSection.Body.LastParagraph)))
{
Node tofix;
Node previouseNode = null;
foreach (Node node in para.ChildNodes)
{
Node dstNode = MainDoc.ImportNode(node, true, ImportFormatMode.KeepSourceFormatting);
if ((previouseNode == null))
{
//insertBeforeParagraph.InsertBefore(dstNode, insertBeforeParagraph.FirstChild);
tofix = insertBeforeParagraph.InsertBefore(dstNode, insertBeforeParagraph.FirstChild);
}
else
{
//insertBeforeParagraph.InsertAfter(dstNode, previouseNode);
tofix = insertBeforeParagraph.InsertAfter(dstNode, previouseNode);
}
//.........这里部分代码省略.........
示例8: SectionsImportSection
public void SectionsImportSection()
{
//ExStart
//ExId:SectionsImportSection
//ExSummary:Shows how to copy sections between documents.
Document srcDoc = new Document(MyDir + "Document.doc");
Document dstDoc = new Document();
Section sourceSection = srcDoc.Sections[0];
Section newSection = (Section)dstDoc.ImportNode(sourceSection, true);
dstDoc.Sections.Add(newSection);
//ExEnd
}
示例9: MigrateFrom2XImportSection
public void MigrateFrom2XImportSection()
{
Document srcDoc = new Document();
Document dstDoc = new Document();
//ExStart
//ExId:MigrateFrom2XImportSection
//ExSummary:This fragment shows how to insert a section from another document in Aspose.Words 3.0 or higher.
Section sourceSection = srcDoc.Sections[0];
Section newSection = (Section)dstDoc.ImportNode(sourceSection, true);
dstDoc.Sections.Add(newSection);
//ExEnd
}
示例10: _bgWork_DoWork
//.........这里部分代码省略.........
{
dr["課程座號" + cot] = coSel.SeatNo;
if((studRecDict.ContainsKey(coSel.StudentID)))
{
if (_classNameDict.ContainsKey(studRecDict[coSel.StudentID].RefClassID))
{
dr["班級" + cot] = _classNameDict[studRecDict[coSel.StudentID].RefClassID];
}
dr["姓名"+cot]=studRecDict[coSel.StudentID].Name;
if (studRecDict[coSel.StudentID].SeatNo.HasValue)
dr["座號" + cot] = studRecDict[coSel.StudentID].SeatNo.Value;
// 計算學生缺曠統計
int atCount = 0;
foreach (UDTAttendanceDef data in Global._CousreAttendList)
{
if (data.StudentID == coSel.StudentID)
atCount++;
}
dr["總計" + cot] = atCount;
SumCount += atCount;
}
string ssid = coSel.StudentID.ToString();
if (!Global._CourseStudentAttendanceIdxDict.ContainsKey(ssid))
Global._CourseStudentAttendanceIdxDict.Add(ssid, cot);
drTT["缺曠紀錄" + cot] = coSel.StudentID;
cot++;
}
dr["學生人數"] = coSelList.Count;
dr["缺曠總計"] = SumCount;
dt.Rows.Add(dr);
dtAtt.Rows.Add(drTT);
// 處理動態處理(缺曠)
Document docAtt = new Document();
docAtt.Sections.Clear();
docAtt.Sections.Add(docAtt.ImportNode(docTemplate.Sections[0], true));
_builder = new DocumentBuilder(docAtt);
docAtt.MailMerge.MergeField += new Aspose.Words.Reporting.MergeFieldEventHandler(MailMerge_MergeField);
docAtt.MailMerge.Execute(dtAtt);
Document doc1 = new Document();
doc1.Sections.Clear();
doc1.Sections.Add(doc1.ImportNode(docAtt.Sections[0], true));
doc1.MailMerge.Execute(dt);
doc1.MailMerge.RemoveEmptyParagraphs = true;
doc1.MailMerge.DeleteFields();
// 清除多餘欄位
int TabRowCount = doc1.Sections[0].Body.Tables[0].Rows.Count-1;
for (int idx = TabRowCount; idx >=cot; idx--)
{
doc1.Sections[0].Body.Tables[0].Rows.RemoveAt(idx);
}
docList.Add(doc1);
}
doc.Sections.Clear();
foreach (Document doc1 in docList)
doc.Sections.Add(doc.ImportNode(doc1.Sections[0], true));
string reportNameW = "課程缺曠統計表";
pathW = Path.Combine(System.Windows.Forms.Application.StartupPath + "\\Reports", "");
if (!Directory.Exists(pathW))
Directory.CreateDirectory(pathW);
pathW = Path.Combine(pathW, reportNameW + ".doc");
if (File.Exists(pathW))
{
int i = 1;
while (true)
{
string newPathW = Path.GetDirectoryName(pathW) + "\\" + Path.GetFileNameWithoutExtension(pathW) + (i++) + Path.GetExtension(pathW);
if (!File.Exists(newPathW))
{
pathW = newPathW;
break;
}
}
}
try
{
doc.Save(pathW, Aspose.Words.SaveFormat.Doc);
}
catch (Exception exow)
{
}
doc = null;
docList.Clear();
GC.Collect();
_bgWork.ReportProgress(100);
#endregion
}