Alternative to Office Interop for document generation

旧巷老猫 提交于 2019-11-27 21:37:06

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 have a number of components in .NET and Java for generating Word, Excel and Powerpoint documents

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:

File Format Components (Aspose)

Software Artisans have some similar components that can read and write Word and Excel documents:

Software Artisans OfficeWriter

Take a look at http://npoi.codeplex.com/ I use it to create excel documents. supports ppt and word as well.

Windward Reports does exactly what you want (disclaimer, I'm the CTO at Windward). With Windward you design your documents in Word, Excel, or PowerPoint and then our engine merges that template with the data to create the final document. The engine is available in Java and .NET and does NOT use Office on the server so it's very fast and does not have the issues you get using interop.

If you have SQL Server, you could look at SQL Server Reporting Services

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

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.

OneSHOT

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!