以文化中立的方式设置 Word 2007 的行距
我在 Word 2007 中设置行距时遇到问题。Word 2007 默认为双倍行距或行间有额外的空格。以前,我一直成功地使用与此类似的东西(在 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);
}
但是,当尝试在某些区域/文化设置(例如意大利语和德语)下应用它时,这会被破坏。我相信这是因为“无间距”需要使用目标语言,而不是硬编码为英语。因此,我试图找出一种以更便携的方式应用相同更改的方法。
我尝试过筛选各种枚举,例如“WdBuiltinStyle”,但似乎找不到一个可以完成与“No Spacing”相同的事情。
这里有人知道如何做到这一点吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如何使用
您的代码不设置行间距,它设置应用了特定行间距的样式。
引用被问及如何解决这个问题的人的话,因为这是公认的答案:
What about using
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:
正如 Joey 所建议的,解决方案是使用 Word 的内置样式。我通过将以下内容应用于我的 Word._Application 对象解决了这个问题:
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: