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?
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With