wordpress hit counter
Introducing TextReplacer: A New Class for PowerTools for Open XML - OpenXML Developer - Blog - OpenXML Developer
Goodbye and Hello

OpenXmlDeveloper.org is Shutting Down

There is a time for all good things to come to an end, and the time has come to shut down OpenXmlDeveloper.org.

Screen-casts and blog posts: Content on OpenXmlDeveloper.org will be moving to EricWhite.com.

Forums: We are moving the forums to EricWhite.com and StackOverflow.com. Please do not post in the forums on OpenXmlDeveloper.org. Instead, please post in the forums at EricWhite.com or at StackOverflow.com.

Please see this blog post for more information about my plans moving forward.  Cheers, Eric

Introducing TextReplacer: A New Class for PowerTools for Open XML

Introducing TextReplacer: A New Class for PowerTools for Open XML

  • Comments 1

This page has been moved.  You can find this content at the following link: Introducing TextReplacer: A New Class for PowerTools for Open XML

OpenXmlDeveloper.org is shutting down as an active site.  See this blog post at EricWhite.com for more information.

Attachment: TextReplacer.zip
  • Hi Eric.  First let me thank you for the great work.  PowerTools has saved us a lot of time when manipulating Word documents.  However, I encountered an issue where I was looping through a Dictionary of Codes and their replacement values where 5 out of the 6 Codes had Empty Strings ("") as the Values.  The first Code was processed fine in the the WmlSearchAndReplaceTransform() routine where it determines the contents of TextValue and checks if it is empty:

                           XElement paragraphWithConsolidatedRuns = new XElement(W.p,

                               groupedAdjacentRunsWithIdenticalFormatting.Select(g =>

                                   {

                                       if (g.Key == "DontConsolidate")

                                           return (object)g;

                                       string textValue = g.Select(r => r.Element(W.t).Value).StringConcatenate();

                                       XAttribute xs = null;

                                       if (textValue[0] == ' ' || textValue[textValue.Length - 1] == ' ')

                                           xs = new XAttribute(XNamespace.Xml + "space", "preserve");

                                       return new XElement(W.r,

                                           g.First().Elements(W.rPr),

                                           new XElement(W.t, xs, textValue));

                                   }));

    The second time through, the code set the TextValue to empty string and caused an Index Out of Bounds error when it performed the second check in the If statement since it is computes (0 - 1 = -1) for the Index value.

    I ended up changin the If statement to check for the length of textValue:  textValue.Length == 0

    What do you think about this?  I didn't really try to figure out what all the code above was doing, so this might not be the best approach.

Page 1 of 1 (1 items)