line-breaks - 如何在合并字段中的每个项目之间放置换行符(出于格式化目的)
问题描述
我有一个附加到我需要重新格式化的 SQL 查询的邮件合并。'action_name' 字段已插入并正常工作。[编辑:澄清一下,所有数据都出现在一个名为“action_name”的合并字段名称下]。
例如,它会出现在这样的字母中:
PersonA, You are missing the following items: 'A, B, C, D, E and F.'
PersonB, You are missing the following items: 'A and B'
PersonC, You are missing the following items: 'A'
PersonD, You are missing the following items: 'A, B, C and D'
当然,每个人都会收到自己的信件,因此他们只会看到自己丢失的物品。
当我们把信交给其他部门时,他们每次都必须手动按回车键来重新格式化信,使其看起来像这样:
PersonA, You are missing the following items:
'A,
B,
C,
D,
E,
F'
在这个例子中我只会做 PersonA。我想你应该已经明白了。
如何使用邮件合并(或 SQL 代码)中的代码执行此操作,以便其他人不必手动执行此操作?我已经知道 \v 垂直格式不适用于此。我读到它是针对东亚语言的。感谢您的任何提示!
解决方案
根据您的描述,“A、B、C、D、E 和 F”和“A 和 B”都是通过单个合并字段输出的。Word 没有在此类内容中插入中断的字段编码机制。如果输出是由单独的合并字段生成的,那么插入中断将是微不足道的。当然,您可以在 mailmerge 主文档中添加一个宏来自动执行合并后处理。例如,以下宏拦截“合并到单个文档”操作以执行所有处理:
Sub MailMergeToDoc()
Application.ScreenUpdating = False
ActiveDocument.MailMerge.Execute
With ActiveDocument.Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchWildcards = True
.Text = "('[A-Z],)"
.Replacement.Text = "^l\1"
.Execute Replace:=wdReplaceAll
.Text = "([A-Z],) "
.Replacement.Text = "\1^l"
.Execute Replace:=wdReplaceAll
.Text = "([A-Z]) and ([A-Z])"
.Replacement.Text = "\1,^l\2"
.Execute Replace:=wdReplaceAll
End With
Application.ScreenUpdating = True
End Sub
推荐阅读
- javascript - 使用 turn.js 库时页面不翻页
- google-cloud-platform - 如何自定义 GCP 数据流模板?
- flutter - 如何在 Flutter Windows 应用程序中打开 PDF 文件
- reactjs - 开发时在 Github 页面上托管 React 项目
- javascript - 由于访问控制检查,无法加载带有数据的 JS 客户端/Python 服务器 XMLHttpRequest 帖子
- javascript - 如果输入值为零,则仅通过正则表达式禁用按钮
- c++ - 如何用c++解压?
- javascript - 使用 Node JS 动态编辑 word 文档并替换文本和图像占位符
- python - Python Asyncio 中的请求返回“无”
- java - 无法使用 jsoup 获取页面内容