要吧你要操作的Excel文件加上Asp用户操作权限吧关注

解决方案 »

  1.   

    对,Excel.Application abc=new Excel.Application ();语句不认。
      

  2.   

    再模板点右键-属性-安全-添加 ***\VS Developers 然后赋权限
      

  3.   

    难道要把磁盘改为ntfs之后再用吗
      

  4.   

    在web.config中加入
    <identity impersonate="true"/>
      

  5.   

    http://support.microsoft.com/default.aspx?scid=kb;EN-US;288366
      

  6.   

    在web.config文件添加一句 <identity impersonate="true"/>以启用模拟身份,因为默认ASPNET这个用户是没有权限访问Excel.Application(),当启用模拟身份后所有页面将会使用匿名Internet用户帐户(IUSR_machinename)这个用户名的权限执行,这样就能成功访问Excel.Application()并在ASP.NET中操作Excel
      

  7.   

    string filename=Server.MapPath(".")+"\\bin\\ac.xls";
    FileInfo mode=new FileInfo(Server.MapPath(".")+"\\bin\\normal.xls");
    mode.CopyTo(filename);
    Excel.Application myExcel=new Excel.Application ( );
    myExcel.Visible =false;
    myExcel.Cells[5,5]="'"+"123";
    我上边的这个代码每次执行第一次后就提示excel不可再用了,怎么办?》??????
      

  8.   

    能帮我修改上边的代码吗????????????????就是要实现把数据填入ac.xls中,而normal.xls就是一个模板
      

  9.   

    string filename=Server.MapPath(".")+"\\bin\\ac.xls";
    //string filename="ac.xls";
    FileInfo mode=new FileInfo(Server.MapPath(".")+"\\bin\\normal.xls");
    mode.CopyTo(filename);
    Excel.Application myExcel=new Excel.Application ( );
    object missing=Missing.Value;
    myExcel.Application.Workbooks.Open(filename,missing,missing,missing,missing,
    missing,missing,missing,missing,missing,missing, missing,missing); 
    myExcel.Visible =false;
    myExcel.Cells[5,5]="'"+"123"; 
    这是我写的完整代码
      

  10.   

    正是,excel用一次就再也不能用了,怎么放,
      

  11.   

    Excel.Application  m_xlApp = null;
    if (m_xlApp != null){
        m_xlApp.ActiveWorkbook.Close(false,missing,missing);
    }
      

  12.   

    string FileName = Server.MapPath(".")+"\\bin\\ac.xls";Excel.Application excel = null;
    Excel.Workbooks workbooks = null;
    Excel.Workbook workbook = null;
    Excel.Sheets sheets = null;
    Excel.Worksheet worksheet = null;excel = new Excel.ApplicationClass();
    workbooks = excel.Workbooks;
    workbook = workbooks.Open(FileName, System.Type.Missing,<参数......>);
    sheets = workbook.Sheets;
    worksheet = (Excel.Worksheet)sheets[1];
    Application对象是没有Cells的
    请看清层次关系用System.Runtime.InteropServices.Marshal.ReleaseComObject释放掉不用的COM对象
      

  13.   

    我是不是还要写一个断语句在生成的ac.xls每次下载到本地后自动删除,但如何写呢,唉,帮到底吧,不好意思了,
      

  14.   

    Workbook 有SaveAs方法 可以保存文件保存一个临时文件  SaveAsFile将文件以二进制读到缓存 
    删除文件
    然后把缓存数据送到客户端
      

  15.   

    用你们给的进程杀不掉啊,有一个excel进程杀不掉
      

  16.   

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.IO ;
    using System.Reflection ;
    using System.Runtime.InteropServices;
    using System.Runtime .InteropServices .Expando ;
    using Excel;namespace WebApplication3
    {
    /// <summary>
    /// WebForm1 的摘要说明。
    /// </summary>
    public class WebForm1 : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.Button Button1;

    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面

    } #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.Button1.Click += new System.EventHandler(this.Button1_Click);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void Button1_Click(object sender, System.EventArgs e)
    {
    string filename=Server.MapPath(".")+"\\bin\\af.xls";
    //string filename="ac.xls";
    FileInfo sTemplate=new FileInfo(Server.MapPath(".")+"\\bin\\normal.xls");
    sTemplate.CopyTo(filename,true);
    object missing=Missing.Value;
    Excel.Application excel = null;
    Excel.Workbooks workbooks = null;
    Excel.Workbook workbook = null;
    Excel.Sheets sheets = null;
    Excel.Worksheet worksheet = null;
    Excel.Range oCells=null;

     
    excel = new Excel.ApplicationClass(); excel.Visible = false;
    excel.DisplayAlerts = false; workbooks = excel.Workbooks;
    workbook = workbooks.Open(filename,missing,missing,missing,missing,
    missing,missing,missing,missing,missing,missing, missing,missing);
    sheets = workbook.Worksheets;
    worksheet = (Excel.Worksheet)sheets[1];
    worksheet.Name  = "First Sheet";
    oCells = worksheet.Cells; //DumpData(dt, oCells);            worksheet.Cells[5,5]="'"+"99999999";
    workbook.Save ();  
    //worksheet.SaveAs(filename);  
               // workbook.Close();            //Quit Excel and thoroughly deallocate everything
                excel.Quit();
                System.Runtime.InteropServices.Marshal .ReleaseComObject(oCells) ;
    System.Runtime.InteropServices.Marshal .ReleaseComObject(worksheet);
                System.Runtime.InteropServices.Marshal .ReleaseComObject(sheets) ;
    System.Runtime.InteropServices.Marshal .ReleaseComObject(workbook);
                System.Runtime.InteropServices.Marshal .ReleaseComObject(workbooks) ;
    System.Runtime.InteropServices.Marshal .ReleaseComObject(excel);
                excel = null ; workbooks = null ; workbook = null;
                sheets = null ; worksheet = null ; oCells = null;
                System.GC.Collect();            Response.Redirect(filename);

    } }
    }我的这个代码在asp.net中执行,因为excel进程处理不了,下载功能就实现不了,帮忙啊,谢谢了!!!!!!!!!!!!!!!!!!!!!!公司赶任务啊!!!!!!!!
      

  17.   

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.IO ;
    using System.Reflection ;
    using System.Runtime.InteropServices;
    using System.Runtime .InteropServices .Expando ;
    using Excel;namespace WebApplication3
    {
    /// <summary>
    /// WebForm1 的摘要说明。
    /// </summary>
    public class WebForm1 : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.Button Button1;

    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面

    } #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.Button1.Click += new System.EventHandler(this.Button1_Click);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void Button1_Click(object sender, System.EventArgs e)
    {
    string filename=Server.MapPath(".")+"\\bin\\af.xls";
    //string filename="ac.xls";
    FileInfo sTemplate=new FileInfo(Server.MapPath(".")+"\\bin\\normal.xls");
    sTemplate.CopyTo(filename,true);
    object missing=Missing.Value;
    Excel.Application excel = null;
    Excel.Workbooks workbooks = null;
    Excel.Workbook workbook = null;
    Excel.Sheets sheets = null;
    Excel.Worksheet worksheet = null;
    Excel.Range oCells=null;

     
    excel = new Excel.ApplicationClass(); excel.Visible = false;
    excel.DisplayAlerts = false; workbooks = excel.Workbooks;
    workbook = workbooks.Open(filename,missing,missing,missing,missing,
    missing,missing,missing,missing,missing,missing, missing,missing);
    sheets = workbook.Worksheets;
    worksheet = (Excel.Worksheet)sheets[1];
    worksheet.Name  = "First Sheet";
    oCells = worksheet.Cells; //DumpData(dt, oCells);            worksheet.Cells[5,5]="'"+"99999999";
    workbook.Save ();  
    //worksheet.SaveAs(filename);  
               // workbook.Close();            //Quit Excel and thoroughly deallocate everything
                excel.Quit();
                System.Runtime.InteropServices.Marshal .ReleaseComObject(oCells) ;
    System.Runtime.InteropServices.Marshal .ReleaseComObject(worksheet);
                System.Runtime.InteropServices.Marshal .ReleaseComObject(sheets) ;
    System.Runtime.InteropServices.Marshal .ReleaseComObject(workbook);
                System.Runtime.InteropServices.Marshal .ReleaseComObject(workbooks) ;
    System.Runtime.InteropServices.Marshal .ReleaseComObject(excel);
                excel = null ; workbooks = null ; workbook = null;
                sheets = null ; worksheet = null ; oCells = null;
                System.GC.Collect();            Response.Redirect(filename);

    } }
    }我的这个代码在asp.net中执行,因为excel进程处理不了,下载功能就实现不了,帮忙啊,谢谢了!!!!!!!!!!!!!!!!!!!!!!公司赶任务啊!!!!!!!!