Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Line Spacing for Word 2007, in Culturally Neutral Way

I am having trouble setting the line spacing in Word 2007. Word 2007 defaults to double spacing or to having extra space between lines. Previously, I have always used something similar to this with success (In C#):

//No spacing when using Word version > 2003
//Word 2003 = "11.0"
//Word 2007 = "12.0"
Word.Application appVersion = new Word.Application();
string sVersion = appVersion.Version.ToString();
if (sVersion != "11.0")
{
    object noSpacingStyle = "No Spacing";
    oWord.ActiveWindow.Selection.set_Style(ref noSpacingStyle);
}

But, this is breaking when trying to apply it under some regional/cultural settings, such as Italian and German. I believe this is because "No Spacing" needs to be in the target language, instead of hardcoded as English. So, I am trying to figure out a way to apply this same change in a more portable way.

I've tried sifting through the various enumerations, such as "WdBuiltinStyle," but can't seem to find one that accomplishes the same thing as "No Spacing."

Does anyone here know how to accomplish this?

like image 290
campbelt Avatar asked Nov 19 '25 22:11

campbelt


1 Answers

What about using

Selection.ParagraphFormat.LineSpacingRule = WdLineSpacing.wdLineSpaceSingle;

Your code does not set the line spacing, it sets a style that has certain line spacing applied to it.

Quoting from the person asked how they solved it, since this is the accepted answer:

As Joey suggested, the solution is to use Word's built in styles. I resolved this by applying the following to my Word._Application object:

oWord.ActiveWindow.Selection.ParagraphFormat.LineSpacingRule = Word.WdLineSpacing.wdLineSpaceSingle;
oWord.ActiveWindow.Selection.ParagraphFormat.SpaceAfter = 0.0F;
like image 65
Joey Avatar answered Nov 21 '25 13:11

Joey