This project has moved. For the latest updates, please go here.

Manipulate Tables a LOT faster :)

Sep 12, 2014 at 2:03 PM
Hi everyone !

First of all thanks for this library. I've not been using it for long but it really does the job !

I just wanted to share something I came across just now :

Basically I am using tables as "bookmarks" to speed up my ReplaceText and know where I am in my document, with way more flexibility than the InsertBookmark.

Worked fine enough, although things were getting a little slow as my doc grew larger. A matter of seconds (~10s), but still... Well digging a bit in the source code I found that a single style-related line was decelerating the whole thing so much !

In Table.cs, I replaced in the constructor " internal Table(DocX document, XElement xml) ":
if (style != null)
            {
                XAttribute val = style.Attribute(XName.Get("val", DocX.w.NamespaceName));

                if (val != null)
                {
                    try
                    {
                        design = (TableDesign)Enum.Parse(typeof(TableDesign), val.Value.Replace("-", string.Empty));
                    }

                    catch (Exception)
                    {
                        design = TableDesign.Custom;
                    }
                }
                else
                    design = TableDesign.None;
            }
by

if (style != null)
            {
                XAttribute val = style.Attribute(XName.Get("val", DocX.w.NamespaceName));

                if (val != null)
                {
                        design = TableDesign.Custom;
                }
                else
                    design = TableDesign.None;
            }
Now it's almost instantaneous and with the same result, so I guess there must be something wrong with :
design = (TableDesign)Enum.Parse(typeof(TableDesign), val.Value.Replace("-", string.Empty));
Possibly in the exception management since I couldn't reach the "catch" even if an exception was raised.

I don't really have time to investigate the matter any further but it really sped up my code so I hope it can help others =)