Remove spell check from template RRS feed

  • Question

  • Hello,

    I am working on code that takes .pptx template and replace text/images inside it depending on keywords.

    So I am using keyword like "%number%" and check it with code like:

    static void ReplacePlaceholderText(PresentationDocument document, MyData mydata) {
    	var elements = document.PresentationPart.Presentation.SlideIdList.ChildElements;
    	var slideParts = elements.Select(element => (SlidePart)document.PresentationPart.GetPartById((element as SlideId).RelationshipId));
    	var texts = slideParts.SelectMany(slidePart => slidePart.Slide.Descendants<Drawing.Text>());
    	foreach (var text in texts.Where(txt => !string.IsNullOrEmpty(txt.Text)))
    		text.Text = text.Text.Replace("%number%", mydata.Number ?? "");

    Thing is %number% is split inside XML into "%" "number" and "%" with "number" attributed with "err = 1", e.g.:

      <a:bodyPr wrap="square" rtlCol="0">
    	  <a:rPr lang="en-US" dirty="0" smtClean="0"/>
    	  <a:rPr lang="en-US" dirty="0" err="1" smtClean="0"/>
    	  <a:rPr lang="en-US" dirty="0" smtClean="0"/>
    	<a:endParaRPr lang="en-US" dirty="0"/>

    Is there a way to disable error checking and therefore splitting text into paragraphs based on this with "err=1" attributes?

    Or am I using wrong approach overall and there is another way to perform such task?

    Thursday, December 3, 2015 10:44 AM

All replies

  • As temporary workaround for now I ran spell check and selected Ignore All and saved template. Now it contains text as intended. But such workaround is very painful for end-user. 

    I tried PowerTools for OpenXML, but their TextReplacer didn't work either without Ignore All in spell check.

    Thursday, December 3, 2015 11:34 AM
  • An important question for answer this is: could anything else be breaking up the run? Such as direct formatting (bold, italic, different font...)?

    If that's not a factor, then get all the Text descendants of the Paragraph, concatenate and search for the term. If it's found replace the entire paragraph's content with a single a:r a:t.

    Cindy Meister, Office Developer/Word MVP, <a href=""> my blog</a>

    Thursday, December 3, 2015 5:43 PM
  • Yep, I thought about such case. 

    For now I think informing users that each keyword must have 1 format may be good, but still it is probably fragile as something like occasional formatting of part of keyword and then fixing it back manually by user could result in visually "same" format, but inside OXML there will be multiple tags with some attributes, or even with same font style attributes, but just split into several tags.

    Friday, December 4, 2015 3:37 AM
  • Yes, definitely fragile. I'm more familiar with Word than PowerPoint and I know that in Word just having the support for document sharing turned on can cause these breakdowns as soon as the user starts doing things in the document.

    If you think about it, the applications' own Find/Replace have to deal with this, as well. If a term is searched and found with formatting somewhere internal then the formatting is usually lost or applies to the entire replacement. (In Word I know it's an internal algorithm based on percent of text formatted vs. not formatted, but I don't know the details.) So it would be valid for your solution to throw away formatting if the search term is found.

    Cindy Meister, Office Developer/Word MVP, <a href=""> my blog</a>

    Friday, December 4, 2015 5:19 PM