创建 Word 文档并从 .NET 应用程序添加图像
我需要一种生成Word文档(从模板或其他东西)并在特定位置插入图像的方法。有人对执行此操作的最佳方法有任何指示吗?
几年前,我参与了一个使用.NET 1.1中的办公自动化的项目,它确实糟糕得无法形容。我假设 OA 要么得到了改进,要么被更好的解决方案所取代,但我在谷歌上没有找到太多建议。
编辑以澄清,这将在网络或共享点服务器上运行
I need a way of generating a word document (from a template or something) and inserting an image at a specific place. Does anyone have any pointers on the best way to do this?
I worked on a project that used Office Automation in .NET 1.1 a few years ago, and it was really unspeakably poor. I'm assuming OA has either been improved or been superceeded by a better solution, but I'm not finding much advice on google.
Edit to clarify, this will be running on a web or sharepoint server
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
或者,如果您不需要生成适用于 Word 2007 之前版本的 Word 文档,则可以使用 OpenXML SDK 创建您的 Word 文档。全部都是托管代码,我认为比 OA 更容易使用。
Alternatively, and if you do not need to generate word documents that will work with versions prior to Word 2007, you could use the OpenXML SDK to create your Word Document. It's all managed code and way easier in my opinion to use than OA.
做过类似的事情后,我建议不要这样做。服务器环境中的办公自动化存在缺陷。此外,COM Interop 需要交互式用户,即没有“无头”模式。
按照 Gimly 的建议使用 OpenXML,这将是更干净的方法。
Having done something very similar, I would advise against it. Office Automation within a server environment is buggy. Further the COM Interop requires an interactive user, i.e. there is no 'headless' mode.
Use OpenXML as suggested by Gimly, this would be cleaner approach.
以下行会将图像添加到 Word 文档中。
这里,link 应该为 false,save 应该为 true。范围应该是您需要添加图像的位置。
此链接应该有助于处理互操作性。
Following line would add the image to word document.
Here, link should be false and save should be true. Range should be the location where you need to add image.
This link should help out dealing with the Interop.