Excel file generation on server without Excel inst

2019-07-07 00:34发布

问题:

I am using Microsoft.Office.Interop.Excel and generating Excel files using the SaveAs method. This all works correctly on computer with Excel installed. However, my server does not have Excel installed.

How can I generate my files?

回答1:

If you generate a file using Interop you need to install Excel on the server.

Microsoft doesn't support installing Excel (or Word) on the server. Instead you should download the Office Open XML SDK from Microsoft and use that library to generate Excel 2007 documents. This library does not require Excel to be installed on the server: http://msdn.microsoft.com/en-us/office/ee441239.aspx



回答2:

If you are talking about Excel prior to MS Office 2010, there is no set of "client libraries" that can be used to create Office documents.
"Interop" assemblies are just .net wrappers around Microsoft's unmanaged code, that make the Excel API available to .net clients.
You will have to install MSOffice on the server.

EDIT: A similar question here: Excel dll for Microsoft.Office.Interop.Excel



回答3:

If you can afford a third party library, Spreadsheetgear is a good investement.



回答4:

I'd recommend FileHelpers library to read and write Excel (and others) files.

"The FileHelpers are a free and easy to use .NET library to import/export data from fixed length or delimited records in files, strings or streams."

It works well for me, give it a try.



回答5:

If you are ok with the new Open Office Xml format (xlsx) I would highly recommend taking a look at the free .Net library EPPlus. It is easy to use and has a ton of features.



回答6:

If you just need data in the files and no graphs etc, I would just go with XML or CSV format. Both are open formats and don't require interop binaries.