使用vbscript将xml文件导入到word文档模板
我希望有人能够帮助我完成我想做的事情,我已经浏览了互联网,但没有找到任何完全符合我想要的东西。
我想做的是使用 SQL Server 2000 DB 中的数据创建一个 Word 文档。此时我已经创建了Word文档,将其另存为网页,然后将生成的代码复制到asp页面并插入数据库中的数据。当访问网页时,然后打开一个 Word 文档供用户打印等。
这工作正常,但是保存的 Word 文档丢失了很多格式,并且打开时看起来不像预期的那样。
我想知道是否有某种方法可以创建一个word文档,然后使用vbscript将xml数据插入到word文档中?与邮件合并类似,但使用 xml 作为源并通过 vbscript 进行。
谢谢
I'm hoping someone is able to help me with what I am trying to do, I have looked around the internet but haven't found anything that does exactly what I want.
What I am trying to do is create a Word Document using data from a SQL Server 2000 DB. At the minute I have created the Word Document, saved it as a webpage and then copied the generated code to an asp page and inserted the data from the DB. When visited the webpage then opens a word document for the user to print etc.
This works fine however the saved word document loses a lot of the formatting and doesn't look as intended when it is opened.
I was wondering if there was some way that I could create a word document and then insert xml data into the word document all using vbscript? Similar to a mail merge but using xml as the source and doing it through vbscript.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Word 支持以 *.xml 格式保存文档,因此您可以将数据进行 XSL 转换为该架构,也可以将 Word XML 模板加载到 XML 库(例如
MSXML2
)中并插入您的文档。使用 DOM 函数获取数据。然后,您可以将生成的 XML 写入浏览器,如果您将内容类型标头设置为application/vnd.ms-word
之类的内容,浏览器可能会下载该文档并自动将其加载到新的 Word 实例中在客户端。我使用 Excel 和 Excel 的 XML 电子表格格式完成了非常类似的事情。
Word supports saving documents in an *.xml format, so you could either do an XSL transform of your data to this schema or you could load a Word XML template into an XML library such as
MSXML2
and insert your data using the DOM functions. You could then write the resulting XML to the browser and if you set the content type header to something likeapplication/vnd.ms-word
the browser may download the document and automatically load it into a new Word instance on the client side.I have done a very similar thing using Excel and Excel's XML Spreadsheet formats.
查看 Word 的自定义 xml 数据绑定。您将 xml 数据注入 xml 部分,并通过 XPath 将文档中的内容控件绑定到它。 Word 将动态更新文档内容以匹配 xml 部分中的数据。
Have a look at Word's custom xml data binding. You inject your xml data into an xml part, and bind content controls in the document to it, via XPath. Word will update the contents of the document dynamically to match the data in the xml part.