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

Stylename; does this work, and if so how do you apply it?

Oct 25, 2012 at 2:46 PM

I see the stylename property on paragraphs, but I can't seem to make anything work. Here's the code I'm using;

Dim AssumptionsHeading As Paragraph = NewDoc.InsertParagraph

AssumptionsHeading.StyleName = "Heading 3"                     

AssumptionsHeading.Append("Assumptions")

The paragraphs are created, but they don't carry the Heading style. I am starting with a template document that applies numbering and builds a TOC from the heading styles, so I can't simply apply font/size/color properties.

TIA for any insights.

Nov 14, 2012 at 3:12 AM

Came across the same issue. StyleName seems to be broken?

Nov 14, 2012 at 9:48 AM

Actually I did get this working afterwards; the problem was with the syntax I was using. These all work as expected;

p.StyleName = "Heading1"
p.StyleName = "Heading2"
p.StyleName = "Heading3"
p.StyleName = "Normal"

Nov 14, 2012 at 9:50 AM

I tried:

StyleName = "Caption";

which does not seem to work.

Thanks for replying.

Apr 1, 2013 at 5:32 PM
I can't make Stylename work, using this code:
 public MemoryStream Export(IEnumerable<OfficeReportRow> rows)
        {
            MemoryStream stream = new MemoryStream();
            using (var document = DocX.Create(stream))
            {
                Paragraph p = document.InsertParagraph();
                p.StyleName = "Heading1";
                p.Append("TEST");
                document.Save();
            }

            return stream;
        }
Any ideas?
Sep 26, 2013 at 2:10 PM
Hi noocyte,

Are you sure "Heading1" style exists in your docx template?

For example, when I load a template with stylename "Título 1" (i'm from Spain), the stylename i'm use is "Ttulo1", that is the name xml doc file use when I convert my template in a XML Word Document.

I hope I explained...