所以我真的不能使用Excel对象模型来使用服务器端?

时间:2022-01-10 16:11:31

I'm trying to develop a c#/asp.net application to extract data from a SQL server and have it formatted in an excel spreadsheet. I have been practicing with excel object model and recently stumbled upon this: http://support.microsoft.com/kb/257757 Considerations for server-side Automation of Office

我正在尝试开发一个c#/ asp.net应用程序来从SQL服务器中提取数据并将其格式化为excel电子表格。我一直在练习excel对象模型,最近偶然发现了这个问题:http://support.microsoft.com/kb/257757服务器端自动化Office的注意事项

From what I understand I really can't use Excel Object models? And if not what are other solutions/advice besides whats suggested in this article and 3rd party apps I can use?

从我的理解,我真的不能使用Excel对象模型?如果不是除了本文中提出的最新解决方案/建议以及我可以使用的第三方应用程序,还有什么?

3 个解决方案

#1


3  

From that article:

从那篇文章:

Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

Microsoft目前不推荐也不支持任何无人参与的非交互式客户端应用程序或组件(包括ASP,ASP.NET,DCOM和NT服务)的Microsoft Office应用程序自动化,因为Office可能会出现不稳定的行为和/或Office在此环境中运行时出现死锁或死锁。

What this means is that Microsoft won't explicitly prevent you from trying (the licensing allows you to try.) However, if there is a problem, it's up to you to figure out how to fix it.

这意味着微软不会明确阻止您尝试(许可允许您尝试。)但是,如果存在问题,由您决定如何解决它。

There is a better option:

有一个更好的选择:

Create Excel (.XLS and .XLSX) file from C#

从C#创建Excel(.XLS和.XLSX)文件

This will allow you to create the file for download without having to use Excel automation on the server side.

这将允许您创建要下载的文件,而无需在服务器端使用Excel自动化。

#2


3  

I can recommend the SpreadsheetGear library, it has all the Excel functions in one managed dll:

我可以推荐SpreadsheetGear库,它在一个托管dll中包含所有Excel函数:

http://www.spreadsheetgear.com/

http://www.spreadsheetgear.com/

#3


2  

You 'can' use Excel automation on the server side. However you will be breaching licences ,may run into security problems and generally experience other odd behaviour, especially if you have more than one user using it at a time. I would suggest that you dont do it.

您可以在服务器端使用Excel自动化。但是,您将违反许可证,可能会遇到安全问题并且通常会遇到其他奇怪的行为,尤其是如果您有多个用户一次使用它。我建议你不要这样做。

  1. If the data you want to write is simple enough just do it as a csv

    如果您要编写的数据足够简单,只需将其作为csv即可

  2. If not and you really have to write a spreadsheet look for a 3rd party component that writes excel files. I only know of one off the top of my head and thats Aspose.Cells, but that is quite expensive.

    如果没有,你真的必须写一个电子表格,寻找编写excel文件的第三方组件。我只知道我的头顶上的一个,那就是Aspose.Cells,但这是非常昂贵的。

#1


3  

From that article:

从那篇文章:

Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

Microsoft目前不推荐也不支持任何无人参与的非交互式客户端应用程序或组件(包括ASP,ASP.NET,DCOM和NT服务)的Microsoft Office应用程序自动化,因为Office可能会出现不稳定的行为和/或Office在此环境中运行时出现死锁或死锁。

What this means is that Microsoft won't explicitly prevent you from trying (the licensing allows you to try.) However, if there is a problem, it's up to you to figure out how to fix it.

这意味着微软不会明确阻止您尝试(许可允许您尝试。)但是,如果存在问题,由您决定如何解决它。

There is a better option:

有一个更好的选择:

Create Excel (.XLS and .XLSX) file from C#

从C#创建Excel(.XLS和.XLSX)文件

This will allow you to create the file for download without having to use Excel automation on the server side.

这将允许您创建要下载的文件,而无需在服务器端使用Excel自动化。

#2


3  

I can recommend the SpreadsheetGear library, it has all the Excel functions in one managed dll:

我可以推荐SpreadsheetGear库,它在一个托管dll中包含所有Excel函数:

http://www.spreadsheetgear.com/

http://www.spreadsheetgear.com/

#3


2  

You 'can' use Excel automation on the server side. However you will be breaching licences ,may run into security problems and generally experience other odd behaviour, especially if you have more than one user using it at a time. I would suggest that you dont do it.

您可以在服务器端使用Excel自动化。但是,您将违反许可证,可能会遇到安全问题并且通常会遇到其他奇怪的行为,尤其是如果您有多个用户一次使用它。我建议你不要这样做。

  1. If the data you want to write is simple enough just do it as a csv

    如果您要编写的数据足够简单,只需将其作为csv即可

  2. If not and you really have to write a spreadsheet look for a 3rd party component that writes excel files. I only know of one off the top of my head and thats Aspose.Cells, but that is quite expensive.

    如果没有,你真的必须写一个电子表格,寻找编写excel文件的第三方组件。我只知道我的头顶上的一个,那就是Aspose.Cells,但这是非常昂贵的。