代码:
Excel.Application app = new Excel.ApplicationClass();
app.Visible = true;在 WinForm 中可以打开 Excel;但在 asp.net 的 Web项目报告 没有权限什么的, 请问
asp.net 中打开 Excel 要怎么配置权限?

解决方案 »

  1.   

    using Infragistics.Excel; (引入命名空间) #region void ExportToExcel(DataTable table)导出到Excel
        /// <summary>
        /// 导出到Excel          要是DataSet才是这种方法.
        /// </summary>
        /// <param name="table"></param>
        private void ExportToExcel(DataTable table)
        {
            string strExcelName;
            Workbook workbook = new Workbook();
            workbook.Worksheets.Add("文本数据");
            workbook.ActiveWorksheet = workbook.Worksheets["文本数据"];        int colCount = table.Columns.Count;
            if (colCount < 1)
            {        }
            for (int i = 0; i < colCount; i++)
            {
                string colName = table.Columns[i].ColumnName;
                workbook.ActiveWorksheet.Rows[0].Cells[i].Value = colName;
            }
            for (int i = 0; i < table.Rows.Count; i++)
            {
                object[] cellsValue = table.Rows[i].ItemArray;
                for (int j = 0; j < colCount; j++)
                {
                    workbook.ActiveWorksheet.Rows[i + 1].Cells[j].Value = cellsValue[j].ToString();
                }
            }
            workbook.ActiveWorksheet.Rows[table.Rows.Count + 2].Cells[0].Value = "合计:";
            workbook.ActiveWorksheet.Rows[table.Rows.Count + 2].Cells[1].Value = sum3.ToString();
            workbook.ActiveWorksheet.Rows[table.Rows.Count + 2].Cells[2].Value = sum4.ToString();        MemoryStream stream = new MemoryStream();
            BIFF8Writer.WriteWorkbookToStream(workbook, stream);
            Byte[] bytearray = (Byte[])Array.CreateInstance(typeof(byte), (int)stream.Length);
            stream.Position = 0;
            stream.Read(bytearray, 0, (int)stream.Length);
            stream.Close();
            Response.Clear();        strExcelName = "worksheet";        Response.AddHeader("content-disposition", "attachment; filename=" + strExcelName + ".xls");
            Response.BinaryWrite(bytearray);
            Response.End();
        }    #endregion
      

  2.   

    我现只是要 打开 Excel 程序, 
    就是asp.net 页面上的一个按钮, 就打开 Excel 程序;这个在 Asp.net 中怎么实现?谢!
      

  3.   

    楼主需要到 控制面板->管理工具->组件配置中为Microsoft Excel配置一下DCOM权限
    让IUSER_机器名这个用户能够有远程启动Excel的权限就可以了
      

  4.   

    你不是想在客户端打开吧?
    客户端的话建议放弃,因为关系到客户端安全级别的问题
    一般是不可能所有用户都把自己的权限调低,让你在客户端打开excel程序的方法有很多,如果上面的问题你能克服的话,到网上搜一下用javascript操作excel就有很多
      

  5.   

    回 memoriccell(记忆细胞) 
    你好!我按你的 设置了 
    控制面板->管理工具->组件服务 ..\Microsoft Excel应用程序 右键\属性
    安全 页中  将启动和激活权限设为 自定义, 点击 "编辑", 在打开的对话框中将  IUSER_机器名
    的 远程启动Excel的权限 打开.但是,每当我关闭 组件服务 窗体后, 再打开检查: 启动和激活权限又变为 "使用默认值"。
    还是不能在 Asp.net 中创建 Excel.
      

  6.   

    另:我只想在 WEB 服务器上 生成 Excel 文件, 
    然后再下载到客户端!请问我的问题出在那里?
    谢谢回复!
      

  7.   

    还有个问题:在我的电脑上 导入 Com -> Microsoft Excel 11.0 Object Library 库
    有源文件中去不能引用 Microsoft.Office.Interop.Excel 命名空间, 
    只可以引用 Microsoft.Office.Core 命名空间, 不引用任何命名空间, 打开 Excel 程序也没有问题。但是:同样的程序放在 同事的电脑上就行不通, 同事电脑上就可以 引用  Microsoft.Office.Interop.Excel 命名空间, 而且只能引用这个空间后 才能打开 Excel 程序.我们俩电脑装的都是 WindowxXP + Office2003请问问题出在哪?谢复!
      

  8.   

    aq_boy() 的问题我电脑上好像没有, 我的可以 引入 Microsoft.Office.Interop.Excel 啊