用于文档生成的 Office Interop 替代方案
目前,我们正在使用 Office interop 从 Office 2003 中的模板(word、excel 和 powerpoint)生成文档。 这似乎令人不悦(请参阅 office-interop-with-64bit -windows-in-asp-net),虽然它工作正常,但我会更高兴有一个受支持的解决方案。
有什么非黑客方法可以做到这一点? 要求
- 仅限 Office 2003。 (不允许使用 Office XML / Office 2007 兼容包)
- 必须从 ASP.NET 运行服务器端
- 必须能够创建 Word、Excel 和 Office 2007 兼容包 来自用户提供的 .dot、.xlt 和 .pot 模板的 Powerpoint 文档
- 必须能够通过在某些点替换某些文本(例如姓名、地址等)来进一步自定义文档
- 免费或非常低的成本。 我无法提出采购订单来更换正在运行的系统,因为某些网站上有四个人认为这是一个肮脏的黑客行为;)
我不确定是否有更好的方法。 有没有?
At the moment we're using office interop to generate documents from templates in office 2003 (word, excel & powerpoint). This seems to be rather frowned upon (see office-interop-with-64bit-windows-in-asp-net) and whilst it works fine I would be happier with a supported solution.
What non hacky method is there to do this? Requirements are
- Office 2003 only. (No office xml / office 2007 compatability pack allowed)
- Must run server side from ASP.NET
- Must be able to create Word, Excel & Powerpoint documents from user supplied .dot, .xlt and .pot templates
- Must be able to further customise the docouments by replacing certain text at certain points e.g. names, addresses etc
- Free or very low cost. I'm not going to be able to raise a purchase order to replace a working system on the grounds that four people on some website thought it was a dirty hack ;)
I'm not sure there is a better way. Is there?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我刚刚发布此问题作为有关自动化 Office 的另一个问题的答案,但我认为这也是对这个问题的合适回答(特别是因为您正在寻找免费或低成本的解决方案)。
我在使用 Microsoft Excel、Word 和 PowerPoint 通过 Web 服务中的互操作将 Office 文档打印为 PDF 格式时遇到了无穷无尽的问题(性能差、进程挂起、进程崩溃等)。 我也遇到过问题,我怀疑是由于看不见的对话框造成的(可能文件已损坏,已设置只读建议,文件受密码保护,或其他)。
我知道有一些不使用 Office 的工具可用,但它们非常昂贵。 我的解决方案是改用自动化 OpenOffice。 OpenOffice 似乎更加稳定,并且我已经将挂起的进程等抛在了后面。
因此,虽然我想我是在说“不要将 Microsoft Office 自动化”,但我并不是建议您完全放弃自动化;而是建议您完全放弃自动化。 只是我在 OpenOffice 自动化方面比 Microsoft Office 取得了更多的成功。
I just posted this as an answer to another question about automating Office, but I think it's a suitable response to this question too (especially since you are looking for a free or low cost solution).
I've had no end of problems (poor performance, hanging processes, crashing processes etc) using Microsoft Excel, Word and PowerPoint through interop in a web service to print Office documents to PDF format. I too have faced problems that I suspect are because of invisible dialog boxes (maybe a file is corrupt, read-only recommended has been set, file is password protected, or whatever).
I know there are tools available that don't use Office, but they are very expensive. My solution was to switch to automating OpenOffice. OpenOffice seems to be much more stable, and I've left hanging processes and the like behind.
So, while I suppose I am saying "don't automate Microsoft Office", I'm not suggesting that you abandon automation altogether; just that I've had much more success automating OpenOffice than Microsoft Office.
Aspose 有许多 .NET 和 Java 组件,用于生成 Word、Excel 和 Powerpoint 文档
Aspose have a number of components in .NET and Java for generating Word, Excel and Powerpoint documents
您应该查看 Aspose 提供的产品。 有许多不同的文件格式组件允许您创建和操作 PDF 和 Microsoft Office 文档,而无需在服务器上安装 Office:
Software Artisans 有一些类似的组件,可以读取和写入 Word 和 Excel 文档:
You should take a look at the products available from Aspose. There are a number of different file format components that allow you to create and manipulate PDF and Microsoft Office documents without requiring Office to be installed on the server:
Software Artisans have some similar components that can read and write Word and Excel documents:
看看 http://npoi.codeplex.com/
我用它来创建 Excel 文档。 也支持ppt和word。
Take a look at http://npoi.codeplex.com/
I use it to create excel documents. supports ppt and word as well.
如果您有 SQL Server,您可以查看 SQL Server Reporting Services
If you have SQL Server, you could look at SQL Server Reporting Services
SpreadsheetGear for .NET 可以处理 Excel 文件的生成。 我们专注于电子表格,因此没有 Word 或 PowerPoint 生成。
您可以此处查看 ASP.NET 示例并下载免费试用版此处。
免责声明:我拥有 SpreadsheetGear LLC
SpreadsheetGear for .NET can handle the Excel file generation. We focus on spreadsheets so we do not have Word or PowerPoint generation.
You can see ASP.NET samples here and download a free trial here.
Disclaimer: I own SpreadsheetGear LLC
我们完成此操作的一种方法(但不使用模板文件)是创建文档模板并将其保存为 Word、Excel 或 ppt 文档,但采用的格式使文档保留为人类可读的文本。 因此,对于 Word 和 Excel,另存为 mht。
然后,您可以将模板作为字符串读取,并使用良好的老式字符串操作函数对其进行处理(替换占位符文本,添加任何您需要执行的行),然后将字符串保存为 .doc、.xls 或 .ppt(无论哪个程序创建了它)文件,它都应该在该应用程序中作为文档正确打开,并且所有格式都完好无损。
提示一,将模板保存到 Word 后,您必须在文本编辑器中检查模板。 Word 会不加区别地添加换行符,因此它可能会换行占位符或在其中添加其他格式,您可能需要清理这些格式。
One way we have done this, but not with template files is to create your document template and save it as a word, excel, or ppt document, but in a format where the document remains in human readable text. So for Word and Excel save as mht.
Then you can read in the template as a string, and process it with good old fashioned string manipulation functions (replace placeholder text, add rows whatever you need to do) then save the string as a .doc, .xls, or .ppt (which ever program created it) file and it should open right back up as a document in that application with all your formatting intact.
One tip, you have to check your template in a text editor after you save it in Word. Word will indiscriminately add line breaks so it may line break your placeholders or put other formatting inside them which you may have to clean up.
看看 OWC(办公网络组件),它们是为您想要做的事情而设计的!
我不知道它们是否可以使用模板,因为自从我使用它们以来,它已经很长时间了,但我们过去常常动态生成电子表格,然后将它们二进制写入响应流以在浏览器中显示它们。
我不确定它们是否完全满足您的要求,但至少值得作为一个开始进行研究。
Have a look at OWC (office web components) these were designed for what you are looking to do!
I don't know if they can work with templates as it's ages since i have used them but we used to generate spread sheets on the fly then binary write them to the response stream to display them in the browser.
I'm not sure if they will completely meet your requirements but worth looking into as a start at least.