Docx or OpenXML or Interop - choice confusion

Oct 28, 2015 at 5:58 AM
Edited Oct 28, 2015 at 5:59 AM
I am making a web application which will take unformatted lengthy word documents and apply defined formatting on its various parts like
  1. defined color and font on header, sub-header, and footer.
  2. Change the bullets to particular type of bullets
  3. Format the table of defined format of background, foreground, font,color etc.
OpenXml is overcomplicated for lengthy documents.
Interop has its own problems.
I found http://docx.codeplex.com
which I think my be useful and easy but I doubt if it has all the options

Can someone please suggest which one I should choose.
Developer
Oct 29, 2015 at 8:17 AM
Worst case scenario you can do mix of DocX and OpenXML. Most of the things should be possible with DocX. Some may not and unless you will write code to do that you may need to go for OpenXML. Take a look at the source codes. There is an Example section which if you run it generates lots of different examples. It should give you an example of what's possible what not. I do have a plan on making some blogs on DocX to include those examples for easy to use form but just didn't had time.
Marked as answer by atulonweb on 1/7/2016 at 9:26 PM
Dec 24, 2015 at 6:36 AM
Thank you very much for replying.

I used DocX for document formatting.
It was working fine untill I got a requirement to color the bullet points.
I dont find any way in DocX to color the bullets points, it colors the text for that bullet.

Has anybody done something like this?

Thanks,
Atul
Developer
Dec 24, 2015 at 7:04 AM
It's not currently in DocX but what you can do is:
  • Create in Word a document with bullet points - save it
Or you can of course:
  • Create the first bullet points in Docx (very simple doc)
  • Add to this document color of the bullet points - save it as other document
Compare 2 documents for changes and then simply add that functionality to DocX. Seeing as this is small change there shouldn't be much work for you and you could still continue using DocX.
Marked as answer by atulonweb on 1/8/2016 at 3:22 AM
Jan 8, 2016 at 10:25 AM
Edited Jan 8, 2016 at 10:26 AM
Thank you very much for the help. I did the way you suggested and I am able to achieve this. Below is the code, maybe help ful to some one else.

Add this function in list.cs class.

/// <summary>
    /// sets the color of bullet point
    /// </summary>
    /// <param name="c"></param>
    public void SetColor(Color c)
    {
        IEnumerable<XElement> lstcolornodes = Document.numbering.Root.Descendants().Where(xElement => xElement.Name.LocalName == "color");
        if (lstcolornodes != null && lstcolornodes.Count() > 0)
        {
            foreach (var item in lstcolornodes)
            {
                item.SetAttributeValue(XName.Get("val", DocX.w.NamespaceName), c.ToHex());

            }
        }
        else
        {
            IEnumerable<XElement> lstrprnodes = Document.numbering.Root.Descendants().Where(xElement => xElement.Name.LocalName == "rPr");
            if (lstrprnodes != null && lstrprnodes.Count() > 0)
            {
                foreach (var item in lstrprnodes)
                {
                    item.Add(new XElement(XName.Get("color", DocX.w.NamespaceName), new XAttribute(DocX.w + "val", c.ToHex())));
                }
            }
        }
    }
and to use this..
      foreach (var item in document.Lists)
            {
                item.SetColor(Color.Yellow);
            }
Feb 4, 2016 at 12:40 PM
Hi,

While updating an existing document I am facing an issue.
I am setting left indentation using Style.xml

<w:ind w:left="0" w:hanging="0"/> for Heading1
is giving left indent to 0 for one document

and -1.38 for another document.

Any body has any idea where else can be setting.