创建Excel文件时出现问题 [英] Problem in creation excel file

查看:193
本文介绍了创建Excel文件时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我写了一段代码,将数据从数据集"传输到Excel文件.它在开发机器上工作正常,但是当我在服务器上发布它并从任何其他机器上运行它时,excel文件都无法生成.任何机构都可以在这方面帮助我..是编码问题还是权限问题.
我做了如下编码:

Hi
I have written a code to transfer the data from Data Set to Excel file. Its works fine on the development machine but when i publish it on server and run it from any other machine excel file fails to generate. can any body help me on this ..Is it a coding problem or a permission problem.
I did coding as follows:

public void ExportDataToExcel(DataSet dsData, ExportStyle style)
        {
            Microsoft.Office.Interop.Excel.ApplicationClass excel = null;
            Microsoft.Office.Interop.Excel.Workbooks workbooks = null;
            Microsoft.Office.Interop.Excel.Workbook workbook = null;
            try
            {
                _listrow = new SortedList();
                excel = new Microsoft.Office.Interop.Excel.ApplicationClass();
                workbooks = excel.Workbooks;
                workbook = workbooks.Add(true);
                ExportCurrentData(excel, dsData, style);
                _listrow = null;
                Microsoft.Office.Interop.Excel._Worksheet worksheet = (Microsoft.Office.Interop.Excel._Worksheet)excel.ActiveSheet;
                worksheet.Activate();
                excel.Visible = true;
            }
            catch (Exception ee)
            {
                throw ee;
            }
            finally
            {
                if (workbook != null) Marshal.ReleaseComObject(workbook);
                if (workbooks != null) Marshal.ReleaseComObject(workbooks);
                if (excel != null) Marshal.ReleaseComObject(excel);
                workbook = null;
                workbooks = null;
                excel = null;
            }
        }







thanks in advance.

推荐答案

您的代码正在使用实际的Excel来创建工作表,这需要在您的服务器上安装Excel.

有一些Excel组件可以执行此操作,并且不需要安装Office并可以与多个用户更好地进行缩放.
Your code is using actual Excel to create the worksheets, this requires Excel to be installed on your server.

There are Excel components which do this and don''t require Office to be installed and scale better with multiple users.


我们的服务器中已经安装了MS Office 2010.但这无济于事.
we have already MS office 2010 installed in our server. But its not helping ..


看看这篇MSDN文章 ^ ].
Have a look at this MSDN article Working with the Office XP Primary Interop Assemblies[^].


这篇关于创建Excel文件时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆