本文介绍了从ASP.Net C#导入Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从GridView传输数据.到Excel.

I am trying to transfer data from GridView  to Excel.

在下面的代码中,我能够在Excel中传输Grid View Header详细信息.

In my below code I am able to transfer Grid View Header details in Excel.

但是我无法传输Grid View数据.我可以看到文字以"表示.

But the Grid View data I am not able to Transfer. I can see the  text is coming as "".

我尝试使用ToString();但是结果是一样的.

I tried with ToString(); but result is same.

试图使用值,但无法引用使用System.Windows.Form".

Tried to use value but cannot reference Using System.Windows.Form..

我如何可以将数据从gridview传输到Excel:

How I  can transfer the data from gridview to Excel:

受保护的void XGENExportToExcel2()
    {
       // 创建Excel对象.
       Microsoft.Office.Interop.Excel._Application应用程序=新的Microsoft.Office.Interop.Excel.Application();
 protected void XGENExportToExcel2()
    {
        // Creating a Excel object.
        Microsoft.Office.Interop.Excel._Application app = new Microsoft.Office.Interop.Excel.Application();

推荐答案

这似乎是一个网络应用,您正在尝试将Office与之配合使用.为此,需要在服务器上安装Office.尽管此类程序开发可以相对轻松地在客户端系统上实现,但存在许多复杂性 如果自动化是从服务器端代码(例如Microsoft Active Server Pages(ASP),ASP.NET,DCOM或Windows NT服务)进行的,则可能发生这种情况.
 如果使用Office的服务器端自动化,则会遇到一些问题.像用户身份的弹性和稳定性,服务器端的安全性等等.

This appears to be a web app and you're trying to use Office with it.  For that to work Office would need to be installed on the server. Although such programmatic development can be implemented on a client system with relative ease, a number of complications can occur if Automation takes place from server-side code such as Microsoft Active Server Pages (ASP), ASP.NET, DCOM, or a Windows NT service.
 If using server-side Automation of Office, you'll meet some problems. Like user identity resiliency and stability, server-side security and so on.

Microsoft当前不建议并且不支持通过任何无人参与的非交互式客户端应用程序或组件(包括ASP,ASP.NET,DCOM和NT Services)使Microsoft Office应用程序自动化.可能展示 在这种环境下运行Office时行为不稳定和/或出现死锁.

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.

有关详细信息,请参阅Office的服务器端自动化的注意事项
我建议您可以使用某些第三方库来处理Office.
或使用Microsoft的OPenXML.
使用Open XML SDK 2.0生成Excel 2010工作簿
https://msdn.microsoft.com/en-us/library /office/hh180830(v=office.14).aspx

 For more detailed information, please refer to  Considerations for server-side Automation of Office
 I would suggest that you could use some 3rd-party library to do with Office. 
 Or using OPenXML from Microsoft.
Generating Excel 2010 Workbooks by using the Open XML SDK 2.0
https://msdn.microsoft.com/en-us/library/office/hh180830(v=office.14).aspx

最诚挚的问候,

克里斯汀


这篇关于从ASP.Net C#导入Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 23:44
查看更多