以文化中立的方式设置 Word 2007 的行距

发布于 2024-10-11 20:29:15 字数 637 浏览 5 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不再让梦枯萎 2024-10-18 20:29:15

如何使用

Selection.ParagraphFormat.LineSpacingRule = WdLineSpacing.wdLineSpaceSingle;

您的代码不设置行间距,它设置应用了特定行间距的样式。

引用被问及如何解决这个问题的人的话,因为这是公认的答案:

正如 Joey 所建议的,解决方案是使用 Word 的内置样式。我
通过将以下内容应用于我的 Word._Application 解决了此问题
对象:

oWord.ActiveWindow.Selection.ParagraphFormat.LineSpacingRule = Word.WdLineSpacing.wdLineSpaceSingle;
oWord.ActiveWindow.Selection.ParagraphFormat.SpaceAfter = 0.0F;

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;
煮茶煮酒煮时光 2024-10-18 20:29:15

正如 Joey 所建议的,解决方案是使用 Word 的内置样式。我通过将以下内容应用于我的 Word._Application 对象解决了这个问题:

oWord.ActiveWindow.Selection.ParagraphFormat.LineSpacingRule = Word.WdLineSpacing.wdLineSpaceSingle;
oWord.ActiveWindow.Selection.ParagraphFormat.SpaceAfter = 0.0F;

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文