本文整理汇总了C#中Document.AppendChild方法的典型用法代码示例。如果您正苦于以下问题:C# Document.AppendChild方法的具体用法?C# Document.AppendChild怎么用?C# Document.AppendChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Document
的用法示例。
在下文中一共展示了Document.AppendChild方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ChildNestingTest
public void ChildNestingTest()
{
var document = new Document();
var docElem = document.CreateElement("docElem");
var comment = document.CreateComment("commentElem");
document.AppendChild(comment);
document.AppendChild(docElem);
Assert.Equals(2, document.ChildNodes.Length);
}
示例2: 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);
}
示例3: 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);
}
示例4: Run
public static void Run()
{
// ExStart:InsertBarcodeImage
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_WorkingWithImages();
// Create a blank documenet.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// The number of pages the document should have.
int numPages = 4;
// The document starts with one section, insert the barcode into this existing section.
InsertBarcodeIntoFooter(builder, doc.FirstSection, 1, HeaderFooterType.FooterPrimary);
for (int i = 1; i < numPages; i++)
{
// Clone the first section and add it into the end of the document.
Section cloneSection = (Section)doc.FirstSection.Clone(false);
cloneSection.PageSetup.SectionStart = SectionStart.NewPage;
doc.AppendChild(cloneSection);
// Insert the barcode and other information into the footer of the section.
InsertBarcodeIntoFooter(builder, cloneSection, i, HeaderFooterType.FooterPrimary);
}
dataDir = dataDir + "Document_out.docx";
// Save the document as a PDF to disk. You can also save this directly to a stream.
doc.Save(dataDir);
// ExEnd:InsertBarcodeImage
Console.WriteLine("\nBarcode image on each page of document inserted successfully.\nFile saved at " + dataDir);
}
示例5: GenerateCreditContractTemplate
private void GenerateCreditContractTemplate()
{
using (var document = WordprocessingDocument.Create(_templateDocPath, WordprocessingDocumentType.Document, true))
{
var mainPart = document.AddMainDocumentPart();
var doc = new Document();
var body = new Body();
AddParagraph(body, JustificationValues.Center, SetBoldRunProperties(new RunProperties()), "��������� �������");
AddParagraph(body, JustificationValues.Left, new RunProperties(), string.Empty);
var runs = new List<Run>
{
GenerateRun(new RunProperties(), "�"),
GenerateRun(new RunProperties(), ContractNumberPlace)
};
AddParagraph(body, JustificationValues.Left, runs);
runs = new List<Run>
{
GenerateRun(new RunProperties(), DaymonthPlace),
GenerateRun(new RunProperties(), YearPlace)
};
AddParagraph(body, JustificationValues.Left, runs);
AddParagraph(body, JustificationValues.Left, new RunProperties(), string.Empty);
runs = new List<Run>
{
GenerateRun(new RunProperties(), "���� \"��� ��������\", ����� ��������� \"��������\", � ���� ��������� �������, ������������(-��) �� ��������� ������, � ����� �������, � "),
GenerateRun(new RunProperties(), CustomerPlace),
GenerateRun(new RunProperties(), ", ����� ���������(-��) \"�������\", � ������ �������, ��������� ��������� ������� � ���������.")
};
AddParagraph(body, JustificationValues.Both, runs);
//1. ������� ��������
AddParagraph(body, JustificationValues.Left, new RunProperties(), string.Empty);
AddParagraph(body, JustificationValues.Center, new RunProperties() { Italic = new Italic(), Bold = new Bold() }, "1. ������� ��������");
//1.1
runs = new List<Run>
{
GenerateRun(new RunProperties(), "1.1. �������� ������������� �������� � ������� � �� ��������, ��������������� ���������, ������ "),
GenerateRun(new RunProperties(), CreditPlace),
GenerateRun(new RunProperties(), " (����� � ������) "),
GenerateRun(new RunProperties(), "� ����� "),
GenerateRun(new RunProperties(), CreditSumPlace),
GenerateRun(new RunProperties(), " ������ c "),
GenerateRun(new RunProperties(), SincePlace),
GenerateRun(new RunProperties(), " �� "),
GenerateRun(new RunProperties(), UntilPlace),
GenerateRun(new RunProperties(), "."),
// GenerateRun(new RunProperties(), "�� _____________________________________________________________. (������� ������������� �������)")
};
AddParagraph(body, JustificationValues.Both, runs);
//1.2
runs = new List<Run>
{
GenerateRun(new RunProperties(), "1.2. ���������� ������ �� ����������� �������� ��������������� � ������� "),
GenerateRun(new RunProperties(), PercentRatePlace),
GenerateRun(new RunProperties(), " ��������� �������.")
};
AddParagraph(body, JustificationValues.Both, runs);
//1.3
AddParagraph(body, JustificationValues.Both, new RunProperties(), "1.3. ��� ��������������� �� �������� ���������� ��������� � ����� " +
"� ����������� �������� ������������� ��������(-��) �� ������ �����: " +
" ��������� ����� (����� �������), ���������, �������, �������������� � ����� " +
"� �����������/������������� ��������. ");
//2. ������� � ����� ��������� �������
AddParagraph(body, JustificationValues.Left, new RunProperties(), string.Empty);
AddParagraph(body, JustificationValues.Center, new RunProperties() { Italic = new Italic(), Bold = new Bold() }, "2. ������� � ����� ��������� �������");
runs = new List<Run>
{
GenerateRun(new RunProperties(), "2.1. ������� ������ �������� ���������� �� ������ ����� ���������� ����������� ��������. " +
"��� ���� ������ ������ ���� ���������� "),
GenerateRun(new RunProperties(), PaymentDayPlace),
GenerateRun(new RunProperties(), " ����� ���� �����, �� �� �����, ��� �� 10 ���� �� ���� �������.")
};
AddParagraph(body, JustificationValues.Both, runs);
AddParagraph(body, JustificationValues.Both, new RunProperties(), "2.2. ����� �������������� �������, ������������� ��� ������� ��������� ���� " +
"������������� ��������, �������� ������ ����� �������� ��������� �� " +
"�������� ���������� � ��������������� ���������, ����� - �������� �� " +
"����������� ���������� ���������, " +
"� � ���������� ����� - �������� ����� �����.");
doc.AppendChild(body);
mainPart.Document = doc;
}
}
示例6: 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);
}
}
示例7: GenerateContractTemplate
//.........这里部分代码省略.........
};
AddParagraph(body, JustificationValues.Left, runs);
runs = new List<Run>
{
GenerateRun(new RunProperties(), "Дата рождения: "),
GenerateRun(new RunProperties(), BirthDayPlace)
};
AddParagraph(body, JustificationValues.Left, runs);
runs = new List<Run>
{
GenerateRun(new RunProperties(), "Номер документа, удостоверяющего личность: "),
GenerateRun(new RunProperties(), DocumentNumberPlace)
};
AddParagraph(body, JustificationValues.Left, runs);
AddParagraph(body, JustificationValues.Left, new RunProperties(), string.Empty);
//Место жительства
AddParagraph(body, JustificationValues.Left, SetBoldRunProperties(new RunProperties() { Underline = new Underline() }), "Место жительства");
runs = new List<Run>
{
GenerateRun(new RunProperties(), "Город: "),
GenerateRun(new RunProperties(), CityPlace)
};
AddParagraph(body, JustificationValues.Left, runs);
runs = new List<Run>
{
GenerateRun(new RunProperties(), "Улица: "),
GenerateRun(new RunProperties(), StreetPlace)
};
AddParagraph(body, JustificationValues.Left, runs);
runs = new List<Run>
{
GenerateRun(new RunProperties(), "Дом: "),
GenerateRun(new RunProperties(), StreetNumberPlace)
};
AddParagraph(body, JustificationValues.Left, runs);
runs = new List<Run>
{
GenerateRun(new RunProperties(), "Квартира: "),
GenerateRun(new RunProperties(), FlatPlace)
};
AddParagraph(body, JustificationValues.Left, runs);
AddParagraph(body, JustificationValues.Left, new RunProperties(), string.Empty);
//Информация о кредите
//Место жительства
AddParagraph(body, JustificationValues.Left, SetBoldRunProperties(new RunProperties() { Underline = new Underline() }), "Информация о кредите");
runs = new List<Run>
{
GenerateRun(new RunProperties(), "Название: "),
GenerateRun(new RunProperties(), CreditNamePlace)
};
AddParagraph(body, JustificationValues.Left, runs);
runs = new List<Run>
{
GenerateRun(new RunProperties(), "Сумма: "),
GenerateRun(new RunProperties(), SumPlace)
};
AddParagraph(body, JustificationValues.Left, runs);
runs = new List<Run>
{
GenerateRun(new RunProperties(), "Срок, мес: "),
GenerateRun(new RunProperties(), MonthCountPlace)
};
AddParagraph(body, JustificationValues.Left, runs);
AddParagraph(body, JustificationValues.Left, new RunProperties(), string.Empty);
//
runs = new List<Run>
{
GenerateRun(new RunProperties(), "Я, "),
GenerateRun(new RunProperties(), FioPlace),
GenerateRun(new RunProperties(), ":")
};
AddParagraph(body, JustificationValues.Left, runs);
AddParagraph(body, JustificationValues.Both, new RunProperties(), "1) подтверждаю, что информация, содержащаяся в заявлении, достоверна;");
AddParagraph(body, JustificationValues.Both, new RunProperties(), "2) предоставляю Банку право проверки предоставленной мною информации;");
AddParagraph(body, JustificationValues.Both, new RunProperties(), "3) соглашаюсь, что кредит будет предоставлен в случае прохождения соответствующих проверок, " +
"проводимых Банком в соответствии с его локальными нормативными правовыми актами, при этом, Банк " +
"вправе отказать мне в предоставлении кредита без указания причин;");
AddParagraph(body, JustificationValues.Both, new RunProperties(), "4) соглашаюсь, что Банк вправе отказать мне в заключении кредитного договора и в предоставлении кредита, если " +
"в случае проведения после принятия решения о выдаче кредита сверки оригиналов документов на " +
"предоставление кредита и их электронных копий в Банке будет выявлено несоответствие, " +
"препятствующее выдаче кредита;");
AddParagraph(body, JustificationValues.Both, new RunProperties(), "5) соглашаюсь, что при отказе в предоставлении кредита оригинал заявления на получение " +
"кредита не возвращается;");
AddParagraph(body, JustificationValues.Left, new RunProperties(), string.Empty);
runs = new List<Run>
{
GenerateRun(new RunProperties(), DaymonthPlace),
GenerateRun(new RunProperties(), YearPlace)
};
AddParagraph(body, JustificationValues.Right, runs);
doc.AppendChild(body);
mainPart.Document = doc;
}
}
示例8: 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);
}
示例9: AssignSectionProperties
/// <summary>
/// Assigns the section properties.
/// </summary>
/// <param name="document">The document.</param>
/// <param name="secProperties">The sec properties.</param>
private void AssignSectionProperties(Document document, SectionProperties secProperties)
{
if (document == null)
{
throw new ArgumentNullException("document");
}
if (secProperties != null)
{
PageSize pageSize = secProperties.Descendants<PageSize>().FirstOrDefault();
if (pageSize != null)
{
pageSize.Remove();
}
PageMargin pageMargin = secProperties.Descendants<PageMargin>().FirstOrDefault();
if (pageMargin != null)
{
pageMargin.Remove();
}
document.AppendChild(new Paragraph(new ParagraphProperties(new SectionProperties(pageSize, pageMargin))));
}
}
示例10: GenerateContractTemplate
private void GenerateContractTemplate()
{
using (var document = WordprocessingDocument.Create(_templateDocPath, WordprocessingDocumentType.Document, true))
{
var mainPart = document.AddMainDocumentPart();
var doc = new Document();
var body = new Body();
AddParagraph(body, JustificationValues.Center, SetBoldRunProperties(new RunProperties()), "Депозитный договор");
AddParagraph(body, JustificationValues.Left, new RunProperties(), string.Empty);
var runs = new List<Run>
{
GenerateRun(new RunProperties(), "№"),
GenerateRun(new RunProperties(), ContractNumberPlace)
};
AddParagraph(body, JustificationValues.Left, runs);
runs = new List<Run>
{
GenerateRun(new RunProperties(), DaymonthPlace),
GenerateRun(new RunProperties(), YearPlace)
};
AddParagraph(body, JustificationValues.Left, runs);
AddParagraph(body, JustificationValues.Left, new RunProperties(), string.Empty);
runs = new List<Run>
{
GenerateRun(new RunProperties(), "Банк \"Три толстяка\", далее именуемый \"Банк\", в лице Чугаинова Кирилла, действующего(-ей) на основании Устава, с одной стороны, и "),
GenerateRun(new RunProperties(), CustomerPlace),
GenerateRun(new RunProperties(), ", далее именуемый(-ая) \"Вкладчик\", с другой стороны, заключили настоящий договор о следующем.")
};
AddParagraph(body, JustificationValues.Both, runs);
//1. Предмет договора
AddParagraph(body, JustificationValues.Left, new RunProperties(), string.Empty);
AddParagraph(body, JustificationValues.Center, new RunProperties() { Italic = new Italic(), Bold = new Bold() }, "1. Предмет договора");
//1.1
runs = new List<Run>
{
GenerateRun(new RunProperties(), "1.1. Вкладчик вносит, а Банк принимает в порядке и на условиях, предусмотренных Договором, денежные средства в размере "),
GenerateRun(new RunProperties(), SumPlace),
GenerateRun(new RunProperties(), " рублей"),
GenerateRun(new RunProperties(), " с "),
GenerateRun(new RunProperties(), SincePlace),
GenerateRun(new RunProperties(), " по "),
GenerateRun(new RunProperties(), UntilPlace),
GenerateRun(new RunProperties(), ".")
};
AddParagraph(body, JustificationValues.Both, runs);
//1.2
runs = new List<Run>
{
GenerateRun(new RunProperties(), "1.2. Банк начисляет Вкладчику проценты на сумму Депозита, внесенного в соответствии с условиями Договора, по ставке "),
GenerateRun(new RunProperties(), PercentRatePlace),
GenerateRun(new RunProperties(), " процентов годовых.")
};
AddParagraph(body, JustificationValues.Both, runs);
AddParagraph(body, JustificationValues.Both, new RunProperties(), "Проценты на сумму Депозита начисляются со дня, следующего за днем внесения Депозита на " +
"депозитный счет, по день возврата суммы Депозита Вкладчику включительно. При исчислении " +
"процентов и Срока депозита количество дней в месяце и году принимается равным календарному " +
"числу дней (365 дней или 366 дней соответственно).");
//1.3
AddParagraph(body, JustificationValues.Both, new RunProperties(), "1.3. Выплата Банком процентов по вкладу осуществляется по истечении Срока депозита.");
// AddParagraph(body, JustificationValues.Both, new RunProperties(), "1.4. Сумма Депозита и начисленные проценты в день окончания Срока депозита перечисляются на " +
doc.AppendChild(body);
mainPart.Document = doc;
}
}
示例11: CreateFromScratch
public void CreateFromScratch()
{
//ExStart
//ExFor:Node.GetText
//ExFor:CompositeNode.RemoveAllChildren
//ExFor:CompositeNode.AppendChild
//ExFor:Section
//ExFor:Section.#ctor
//ExFor:Section.PageSetup
//ExFor:PageSetup.SectionStart
//ExFor:PageSetup.PaperSize
//ExFor:SectionStart
//ExFor:PaperSize
//ExFor:Body
//ExFor:Body.#ctor
//ExFor:Paragraph
//ExFor:Paragraph.#ctor
//ExFor:Paragraph.ParagraphFormat
//ExFor:ParagraphFormat
//ExFor:ParagraphFormat.StyleName
//ExFor:ParagraphFormat.Alignment
//ExFor:ParagraphAlignment
//ExFor:Run
//ExFor:Run.#ctor(DocumentBase)
//ExFor:Run.Text
//ExFor:Inline.Font
//ExSummary:Creates a simple document from scratch using the Aspose.Words object model.
// Create an "empty" document. Note that like in Microsoft Word,
// the empty document has one section, body and one paragraph in it.
Document doc = new Document();
// This truly makes the document empty. No sections (not possible in Microsoft Word).
doc.RemoveAllChildren();
// Create a new section node.
// Note that the section has not yet been added to the document,
// but we have to specify the parent document.
Section section = new Section(doc);
// Append the section to the document.
doc.AppendChild(section);
// Lets set some properties for the section.
section.PageSetup.SectionStart = SectionStart.NewPage;
section.PageSetup.PaperSize = PaperSize.Letter;
// The section that we created is empty, lets populate it. The section needs at least the Body node.
Body body = new Body(doc);
section.AppendChild(body);
// The body needs to have at least one paragraph.
// Note that the paragraph has not yet been added to the document,
// but we have to specify the parent document.
// The parent document is needed so the paragraph can correctly work
// with styles and other document-wide information.
Paragraph para = new Paragraph(doc);
body.AppendChild(para);
// We can set some formatting for the paragraph
para.ParagraphFormat.StyleName = "Heading 1";
para.ParagraphFormat.Alignment = ParagraphAlignment.Center;
// So far we have one empty paragraph in the document.
// The document is valid and can be saved, but lets add some text before saving.
// Create a new run of text and add it to our paragraph.
Run run = new Run(doc);
run.Text = "Hello World!";
run.Font.Color = System.Drawing.Color.Red;
para.AppendChild(run);
// As a matter of interest, you can retrieve text of the whole document and
// see that \x000c is automatically appended. \x000c is the end of section character.
Console.WriteLine("Hello World!\x000c", doc.GetText());
// Save the document.
doc.Save(MyDir + "Section.CreateFromScratch Out.doc");
//ExEnd
Assert.AreEqual("Hello World!\x000c", doc.GetText());
}