可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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?
回答1:
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.
回答2:
Aspose have a number of components in .NET and Java for generating Word, Excel and Powerpoint documents
回答3:
Take a look at http://npoi.codeplex.com/
I use it to create excel documents. supports ppt and word as well.
回答4:
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.
回答5:
If you have SQL Server, you could look at SQL Server Reporting Services
回答6:
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
回答7:
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
回答8:
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.
回答9:
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.