将字符串插入Word文档
在Word文档中插入大量文本的最佳方法是什么?我有一个预定义的模板,其中包含标题、标题页等,我想在某个点插入文本。你看,我正在数据库中查询这段文本。如果我查询数据库然后将数据库插入书签,它将以相反的顺序插入。例如,如果我在数据库中查询前两行...,
Column A Column B
Text1 1
Text2 2
它将在书签处显示 Text2 2 Text1 1。我还尝试在文档中查找“变量”(即:#variable)并在每个查询中使用 Find.Replace,然后将 #variable 添加到末尾。不过,我在格式化它时遇到了严重的麻烦。有什么想法吗?
What is the best way to insert alot of text into a word document? I have a predefined template that has a header, title page, etc, and I want to insert text at a certain point. You see, I am querying a database for this text. If I query the DB and then insert the database at a bookmark, it inserts it in reverse order. For instance if I query my database for the first two rows of...
Column A Column B
Text1 1
Text2 2
It will appear Text2 2 Text1 1 at the bookmark. I've also tried looking for a "variable" in the document (ie: #variable) and using Find.Replace with each query, then adding #variable to the end. I am having terrible trouble formatting it though. Any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我写了一些这样的东西 - 使用书签 - 但通过反向读取字段来解决相反的问题,这意味着文档以正确的顺序出现。
一般来说,我并不是说这是最好的解决方案,而是说它足够一致,可以以这种方式工作。
I have written something that does this in this way - using bookmarks - but gets around the reverse problem by reading the fields in reverse, meaning that the document comes out in the right order.
I am not saying that this is the best solution, as a rule, but that it is consistent enough to work this way.
您可以随时将结果放入列表中,然后对列表进行排序,而不是直接将其插入。这样您就可以按正确的顺序插入文本。
如果您希望它按照它在数据库中出现的顺序排列,那么您可以通过创建第二个列表对其进行排序,然后从列表 1 的末尾开始将每个项目放入列表 2 中。这样您就颠倒了顺序。
它看起来像这样:
如果您不能按照第一个答案所述操作,希望这会有所帮助。
Rather than just inserting it straight in you can always place the results into a list then sort the list. That way you can insert the text in the right order.
If you want it in the order it appears in the database then you can sort it by creating a second list, then starting from the end of list 1 place each item into list 2. That way you will have reversed the order.
It would look something like this:
Hopefully this helps if you can't do what the first answer said.