这是我的代码:
try
        {
            DataSet Ds = new DataSet();
            Ds.ReadXml(System.AppDomain.CurrentDomain.BaseDirectory + @"\DataSet.xml");
            Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.ApplicationClass();
            Microsoft.Office.Interop.Excel._Workbook xBk = excel.Workbooks.Add(true);
            Microsoft.Office.Interop.Excel._Worksheet xSt = (Microsoft.Office.Interop.Excel._Worksheet)xBk.ActiveSheet;
            Microsoft.Office.Interop.Excel.Range excelCell = null;
            try
            {
                DataTable Dt = Ds.Tables[1];
                int RowLoc;
                for (int i = 0; i < Dt.Columns.Count; ++i)
                {
                    string tmp = Dt.Rows[0][i].ToString();
                    RowLoc = 0;
                    for (int j = 0; j < Dt.Rows.Count; ++j)
                    {
                        if (tmp == Dt.Rows[j][i].ToString())
                        {
                            if (RowLoc < j)
                            {
                                for (int CurrCol = 0; CurrCol < i; ++CurrCol)
                                {
                                    if (Dt.Rows[j - 1][CurrCol].ToString() != Dt.Rows[j][CurrCol].ToString())
                                    {
                                        tmp = Dt.Rows[j][i].ToString();
                                        RowLoc = j;
                                        xSt.Cells[j + 1, i + 1] = tmp;
                                        break;
                                    }
                                }
                                excelCell = xSt.get_Range(excel.Cells[RowLoc + 1, i + 1], excel.Cells[j+1, i + 1]);
                                excelCell.Select();
                                excelCell.Merge(false);
                                excelCell.Value2 = tmp;
                                tmp = Dt.Rows[RowLoc][i].ToString();
                                RowLoc = j;
                            }
                            else
                            {
                                tmp = Dt.Rows[j][i].ToString();
                                RowLoc = j;
                                xSt.Cells[j + 1, i + 1] = tmp;
                            }
                        }
                        else
                        {
                            tmp = Dt.Rows[j][i].ToString();                                                       
                            RowLoc = j;
                            xSt.Cells[j + 1, i + 1] = tmp; 
                        }
                    }
                }
                excel.Visible = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                excelCell = null;
                xBk = null;
                xSt = null;
                excel = null;
                GC.Collect();
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }

解决方案 »

  1.   

    请问是什么原因造成的。尝试过给aspnet  iisuser加工作目录权限等,没有用。不理解,磁盘空间和内存都是正常的,为什么会报 磁盘内存不足呢?
      

  2.   

    我前几天通过以下方法解决了这个问题:
    环境:windows2003 + excel 2007 + IIS6.0
    首先没有使用模拟
    找到组件服务里面的excel组件,选属性,进入安全页里面
    将“启动和激活权限”改为自定义,并添加network service (如果是IIS5 则为aspnet) 
    将“访问权限”改为自定义,并添加network service (如果是IIS5 则为aspnet) 
    你试试看
      

  3.   

    查了一下资料,office不支持server端的automation。
    http://support.microsoft.com/default.aspx?scid=kb;EN-US;257757
    谢谢大家的关注
      

  4.   

    to lxd2006() :
    谢谢你的提示,我刚刚按照步骤作了一下,结果依然。我想问问  “首先没有使用模拟”   是什么意思?不太明白。  呵呵
      

  5.   

    另外 你注意看看是不是把ASPNET和network Service 都设置上了,如果是就去掉多余的,我当时就是多设了ASPNET造成的
    如果还不行,建议换个机器和其他版本的EXCEL试试
      

  6.   

    System.AppDomain.CurrentDomain.BaseDirectory 不建议用这个,如果写应用程序用这个我想是应该的,但是你要是写ASP.NET用这个恐怕就有点问题了
      

  7.   

    var xl = new ActiveXObject("Excel.Application");//加上这句就不会出错了!
    xl.DefaultSaveFormat = Microsoft.Office.Interop.Excel.XlFileFormat.xlExcel8;
    var oBook = xl.Workbooks.Add(); 
      

  8.   

    可能是那个WEB服务器所在的盘空间不够吧