如何使用 OLE 绕过 MSWord 搜索和替换中的 255 个字符限制
我正在使用(在 Delphi win32 应用程序中)OLE 在 Word 文档中执行搜索和替换。
用户准备一个文件,其中包含一些文本标签,将它们括在“{”和“}”中,并保存该文件。
像这样的东西
亲爱的{NAME},
我想告诉你{WHAT_I_DID_LAST_WEEK}
当然,NAME
和 WHAT_I_DID_LAST_WEEK
是长度可能超过 255 的数据库字段。
所以现在通过使用搜索并替换为OLE 我收到字符串参数太长错误(似乎 255 是可用的最长字符串)。
有没有简单的方法可以解决这个问题?
我想到的一些自制解决方案是:
1)截断到255(好的一个;))可能会在末尾附加“...”
2)对于每个需要替换超过255个字符的“标签”,我可以先插入更多标签,例如{WHAT_I_DID_LAST_WEEK_1}{WHAT_I_DID_LAST_WEEK_2}{WHAT_I_DID_LAST_WEEK_N}
然后一次替换 255 个字符
(1) 是一个快速的解决方案,至少用户不会收到错误,但当然不是很好
(2) 可能会起作用,但这是一种解决方法,我更喜欢另一种解决方案。
可能另一个解决方案是不使用 OLE Serach&Replace 而是使用另一个函数。
I am using (in a Delphi win32 application) OLE to perform search and replace in Word Documents.
THe user prepares a file with some textual tags enclosing them in "{" and "}" and saves the file.
Something like
Dear {NAME},
I want to tell you {WHAT_I_DID_LAST_WEEK}
Of course NAME
and WHAT_I_DID_LAST_WEEK
are DB fields that can be longer than 255.
So now by using Search and replace with OLE i get a STRING PARAMETER TOO LONG error (it seems 255 is the longest string usable there).
Is there an easy way to get rid of the problem?
Some home made solutons I thought of are:
1) truncate to 255 (good one ;) ) may be appending "..." at the end
2) for every "tag" that requires a replace of more than 255 chars I could first insert more tags like {WHAT_I_DID_LAST_WEEK_1}{WHAT_I_DID_LAST_WEEK_2}{WHAT_I_DID_LAST_WEEK_N}
and then replace 255 chars at a time
(1) is a quick solution, at least user doesn't recieve the error, but of course it is not very good
(2) would probably work but it is a workaround, I would prefer another solution.
May be another solution is not use OLE Serach&Replace but use another function.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们使用 AWordApp.Selection.TypeText(strValue) 和循环来替换值字符串长于 255 个字符的标签...
问候
we use AWordApp.Selection.TypeText(strValue) and loop for replacing tags that have value string longer then 255 chars ...
regards