2

I am searching for solution of this problem almost 3 days already. I have a Word document with placeholders. And we have our own implementation of how to parse word document templates and replace placeholders with content. But I ran into a problem, that Paragraph list doesn't contain all of the contents from word document. I am getting all Paragraph type descendants of OpenXmlPartRootElement.

var paragraphs = document.Descendants().OfType<Paragraph>().ToList();

Then I am checking for specific placeholder.

paragraphs.Count(x => x.InnerText.Contains("some placeholder"));

There's 3 same placeholders in document, but this statement finds only two of them. This corrupts all document and it is half parsed because of this.

Placeholders and texts in Word document are stored in a table.

Is it sort of bug in library or should I consider getting content in a different way?

Chamila Maddumage
  • 3,304
  • 2
  • 32
  • 43
alalambda
  • 323
  • 3
  • 15
  • You need to provide more information about how this document is structured. Where are the paragraphs that aren't being "found"? Are they in text boxes (drawing objects), for example? Without knowing this, it's not possible to help. Try looking at the raw Word Open XML and locate these placeholders. – Cindy Meister Mar 15 '19 at 22:38
  • Possibly related to the issue described here - https://stackoverflow.com/questions/28697701/openxml-tag-search/28719853#28719853 – petelids Mar 18 '19 at 12:40
  • Document is structured only in a very big simple table with 4 columns. We changed our parser realization a little bit. But after that some of texts still wasn't found by parser. Moving texts around, deleting rows and adding new ones helped. So there definitely was some issue with Word table, which I still can't figure out. – alalambda Mar 21 '19 at 10:03

1 Answers1

0

Try specifying culture in Contains method.

Leon
  • 147
  • 2
  • 7