通过 C# Environment.NewLine 在 MS Word 2007 表中插入换行符的奇怪问题

发布于 2024-09-06 15:46:21 字数 1240 浏览 2 评论 0原文

我使用 Visual Studio 2008、C# 创建了一个共享加载项。在 AddIn 中,我从数据库获取数据,将其填充到 Dictionary 对象中,然后使用 Word 的内置 FindReplace 将 WordTemplate 中的文本替换为数据库中的数据。

  Dictionary<string, string> myDBData = new Dictionary<string, string>();

某些数据库字段需要换行符(即多行数据),因此在将字典对象传递给查找替换例程之前,我在代码中使用 Environment.NewLine 插入换行符。

问题是,对于其中包含换行符的字段,只有当 [replacemefieldname] 占位符为 < 时,文本才会在世界模板内正确替换 em>在Word Table之外就像这样。

这 12 行位于 MS WORD 表之外:

Firm

Firm

Fluid

Fluid

Fluid

Fluid

Fluid

Fluid

Fluid

Fluid

Fluid

Fluid

如果 [replacemefieldname] 占位符位于 MS Word 表内,则多个文本字符串将在单行中呈现,如下所示。

牢固的液体流体流体流体流体流体流体流体流体

请参见以下截图(内部和外部桌子)。

如果我复制表格文本并粘贴到外面,那么新行也会正确呈现!

那么,除了Environment.NewLine之外,在将字符串传递到Word以对MS Word表格中存在的[replacemefieldname]占位符进行查找替换之前,我还应该在字符串的行之间放置哪些其他字符?

谢谢你

。 StackOverflow 的聪明人阻止我发布屏幕截图,因为我被视为“新用户”,所以这里的屏幕截图使我的问题更加清晰.. :)

http://img231.imageshack.us/img231/144/wrderr.png

I created a Shared AddIn using Visual Studio 2008, C#. In the AddIn, I get data from a database, populate it into a Dictionary object, and use Word's builtin FindReplace to replace text inside a WordTemplate with the data from the database.

  Dictionary<string, string> myDBData = new Dictionary<string, string>();

Some of the db fields need the newline character (i.e. multi-line data), so I insert a newline using Environment.NewLine in my code before passing the dictionary object to a find-replace routine.

The problem is, for fields that have the newline character in them, the text is getting replaced properly inside the world template only if the [replacemefieldname] placeholder is outside a Word Table like so.

These 12 lines are outside A MS WORD Table:

Firm

Firm

Fluid

Fluid

Fluid

Fluid

Fluid

Fluid

Fluid

Fluid

Fluid

Fluid

If the [replacemefieldname] placeholder is inside a MS Word Table, the the multiple text string is rendering in a single line like so.

Firm Firm Fluid Fluid Fluid Fluid Fluid Fluid Fluid Fluid Fluid Fluid

See following screenshot for both rendering (inside and outside table).

If I copy the table text and paste outside, then also the new lines render properly!!

So what other characters besides Environment.NewLine should I be placing in between the lines in the string before passing it on to Word to do find-replace for [replacemefieldname] placeholders that exist inside a MS Word Table ?

thank you

ps. The clever folks at StackOverflow are preventing me from posting screenshot since I'm deemed a "New User", so here is the screenshot that makes my question clearer.. :)

http://img231.imageshack.us/img231/144/wrderr.png

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文