Переглянути джерело

Fixed a bug that was causing Paragraphs defined inside <snd> tags from being populated.

master
coffeycathal_cp 15 роки тому
джерело
коміт
949a0f3828
2 змінених файлів з 12 додано та 26 видалено
  1. 10
    24
      ConsoleApplication3/Program.cs
  2. 2
    2
      DocX/Container.cs

+ 10
- 24
ConsoleApplication3/Program.cs Переглянути файл

@@ -2,8 +2,9 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Novacode;
using System.Drawing;
using System.Xml.Linq;
using Novacode;
namespace ConsoleApplication3
{
@@ -11,31 +12,16 @@ namespace ConsoleApplication3
{
static void Main(string[] args)
{
// Create a new document.
using (DocX document = DocX.Create(@"Test.docx"))
{
// Add Headers to the document.
document.AddHeaders();
// Get the default Header.
Header header = document.Headers.odd;
String filename = @"C:\Users\cathal\Downloads\ExternalAssessmentT.docx";
// Insert a Paragraph into the Header.
Paragraph p0 = header.InsertParagraph();
// Append place holders for PageNumber and PageCount into the Header.
// Word will replace these with the correct value foreach Page.
p0.Append("Page (");
p0.AppendPageNumber(PageNumberFormat.normal);
p0.Append(" of ");
p0.AppendPageCount(PageNumberFormat.normal);
p0.Append(")");
p0.ReplaceText("Page (", "Monster <");
p0.ReplaceText(")", ">");
using (DocX doc = DocX.Load(filename))
{
doc.ReplaceText("{Company Name}", "Penn Inc.", false);
doc.ReplaceText("{Primary Contact}", "John Smith", false);
// Save the document.
document.Save();
doc.AddCoreProperty("dc:subject", "CLE-OP55555");
doc.SaveAs(@"C:\Users\cathal\Downloads\ExternalAssessmentT2.docx");
}
}
}

+ 2
- 2
DocX/Container.cs Переглянути файл

@@ -87,8 +87,8 @@ namespace Novacode
internal void GetParagraphsRecursive(XElement Xml, ref int index, ref List<Paragraph> paragraphs)
{
// sdtContent are for PageNumbers inside Headers or Footers, don't go any deeper.
if (Xml.Name.LocalName == "sdtContent")
return;
//if (Xml.Name.LocalName == "sdtContent")
// return;
if (Xml.Name.LocalName == "p")
{

Завантаження…
Відмінити
Зберегти