Explorar el Código

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

master
coffeycathal_cp hace 15 años
padre
commit
949a0f3828
Se han modificado 2 ficheros con 12 adiciones y 26 borrados
  1. 10
    24
      ConsoleApplication3/Program.cs
  2. 2
    2
      DocX/Container.cs

+ 10
- 24
ConsoleApplication3/Program.cs Ver fichero

using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Novacode;
using System.Drawing; using System.Drawing;
using System.Xml.Linq;
using Novacode;
namespace ConsoleApplication3 namespace ConsoleApplication3
{ {
{ {
static void Main(string[] args) 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 Ver fichero

internal void GetParagraphsRecursive(XElement Xml, ref int index, ref List<Paragraph> paragraphs) 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. // 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") if (Xml.Name.LocalName == "p")
{ {

Cargando…
Cancelar
Guardar