WtFudgE
WtFudgE

Reputation: 5228

c# Interop Word Document add Style

I want to add style to a paragraph, but depending on the word language version I have to use a different name. Now I'm creating an application for multiple users, and if they have an english version i can use "Header 1", but if they don't the style is not recognized. I was wondering what I should do, should I add a new style? I've been looking into this but I can't figure out how.

So on my dutch version i use:

selection.TypeParagraph();
object kop1 = "Kop1";
selection.set_Style(kop1);
selection.TypeText("test");

but english i need:

selection.TypeParagraph();
object kop1 = "Header 1";
selection.set_Style(kop1);
selection.TypeText("test");

I actually need this to create a content table, I can't create a content table if I don't use the styles, right? Otherwise my content tables says it has no content.

I make the content table using:

object start = adoc.Content.End - 1;
Range rangeForTOC = adoc.Range(ref start, ref missing);
TableOfContents toc = adoc.TablesOfContents.Add(rangeForTOC, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
adoc.TablesOfContents[1].TabLeader = WdTabLeader.wdTabLeaderDots;
adoc.TablesOfContents.Format = WdTocFormat.wdTOCClassic;
toc.Update();

Any ideas?

Upvotes: 1

Views: 5684

Answers (2)

Shital Shah
Shital Shah

Reputation: 68708

You might want to use Word.WdBuiltinStyle enumeration instead of language specific strings. For example use Word.WdBuiltinStyle.wdStyleHeading1 in your above code.

Another way to solve this issue is to add your own template and use the styles defined in that template. In this case you supply your template in your distribution.

For using pre-defined table generation styles, also see this answer: Setting Word 2007 table style designs in code

Upvotes: 4

Micah Armantrout
Micah Armantrout

Reputation: 6971

For one I would use DocX (no Com)

Here is info about styling.

Upvotes: 1

Related Questions