首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何修复"Microsoft Office Excel无法打开或保存更多文档,因为没有足够的可用内存或磁盘空间“?

如何修复"Microsoft Office Excel无法打开或保存更多文档,因为没有足够的可用内存或磁盘空间“?
EN

Stack Overflow用户
提问于 2012-12-07 15:30:24
回答 1查看 9.8K关注 0票数 1

我正在尝试将我网站中的数据集导出到excel。代码在本地机器上运行良好,但当我部署相同的代码来获胜时。服务器im收到以下错误:

我使用了以下代码:

代码语言:javascript
复制
    DataSet ds = new DataSet("New_DataSet");
    DataTable dt = new DataTable("New_DataTable");

    string constr = ConfigurationSettings.AppSettings["ConnectionInfo"];
    SqlConnection con = new SqlConnection(constr);
    con.Open();

    string sql = "SELECT * FROM Table1";
    SqlCommand cmd = new SqlCommand(sql, con);
    SqlDataAdapter adptr = new SqlDataAdapter();

    adptr.SelectCommand = cmd;
    adptr.Fill(dt);
    con.Close();

    ds.Tables.Add(dt);
    MyExcel.Application oXL;
    MyExcel.Workbook oWB;
    MyExcel.Worksheet oSheet;
    MyExcel.Range oRange;

//Worksheet = excelApp.Worksheets;// <--重要部分// Worksheet= sheets.Open(...);

代码语言:javascript
复制
    oXL = new MyExcel.Application();

    oXL.Visible = true;
    oXL.DisplayAlerts = false;
    oWB = oXL.Workbooks.Add(System.Type.Missing);
    //oWB = oXL.Workbooks.Add(System.Type.Missing);

    oSheet = (MyExcel.Worksheet)oWB.ActiveSheet;
    oSheet.Name = "Customers";

    int rowCount = 1;
    foreach (DataRow dr in dt.Rows)
    {
        rowCount += 1;
        for (int i = 1; i < dt.Columns.Count + 1; i++)
        {
            // Add the header the first time through 
            if (rowCount == 2)
            {
                oSheet.Cells[1, i] = dt.Columns[i - 1].ColumnName;
            }
            oSheet.Cells[rowCount, i] = dr[i - 1].ToString();
        }
    }

    // Resize the columns 
    oRange = oSheet.get_Range(oSheet.Cells[1, 1],
                  oSheet.Cells[rowCount, dt.Columns.Count]);
    oRange.EntireColumn.AutoFit();

    // Save the sheet and close 


    oWB.SaveAs("test.xlsx", MyExcel.XlFileFormat.xlWorkbookNormal, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing,
        MyExcel.XlSaveAsAccessMode.xlExclusive, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing);

    oSheet = null;
    oRange = null;
    oWB = null;
    oXL = null;

     oWB.Close(false, System.Type.Missing, System.Type.Missing);
    Marshal.FinalReleaseComObject(oWB);
    Marshal.FinalReleaseComObject(oXL);

    oXL.Quit();
    Marshal.ReleaseComObject(oSheet);
    Marshal.ReleaseComObject(oSheet);


    GC.WaitForPendingFinalizers();
    GC.Collect();
    GC.WaitForPendingFinalizers();
    GC.Collect();

我没有得到任何解决这个问题的办法。有人能帮上忙吗?

EN

回答 1

Stack Overflow用户

发布于 2012-12-07 17:34:06

如果您已经检查过是否有足够的可用空间,那么唯一的其他问题可能是权限。

希望这个链接对你有用:

http://www.codeproject.com/Questions/87128/Unable-to-write-data-runtime-in-Excel-app-using-c

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13758777

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档