【问题标题】:Save Access file in .net在 .net 中保存访问文件
【发布时间】:2011-08-22 15:25:08
【问题描述】:

如何将 .net 中的 Access 报告保存到用户的电脑?我尝试过使用 Access.SaveAsAXL、Docmd.OutputTo 和其他一些方法,但无济于事。以下是我最近的尝试。

 string dbname = "D:\\filename.mdb";

        Microsoft.Office.Interop.Access.Application oAccess = new Microsoft.Office.Interop.Access.Application();
        oAccess.OpenCurrentDatabase(dbname, true);
        oAccess.Visible = true;
        var acFormatXLS = "Microsoft Excel (*.xls)";
        string id = "tblJobs.JobID=" + (Convert.ToInt32(GetMaxJobID())).ToString();

        try
        {
          oAccess.Run("BuildXAxisTimeLine", Convert.ToInt32(GetMaxJobID()));

          oAccess.SaveAsAXL(Microsoft.Office.Interop.Access.AcObjectType.acReport, "rptChartData", "D:\\report.xls");
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
            //oAccess.CloseCurrentDatabase();
        }

我收到的错误是:

hresult e_fail 已从对 com 组件的调用中返回

任何帮助将不胜感激。谢谢。

【问题讨论】:

    标签: c# .net visual-studio ms-access


    【解决方案1】:

    以下代码解决了我的问题。将它放在上面所示的 try 部分中,而不是 oAccess.SaveAsAxl 代码行和 .Run 代码行的正下方。

    oAccess.DoCmd.OpenReport("rptChartData", Microsoft.Office.Interop.Access.AcView.acViewPreview, null,id);
                  oAccess.DoCmd.OutputTo(Microsoft.Office.Interop.Access.AcOutputObjectType.acOutputReport, "rptChartData", acFormatXLS, "D:\\reportname.pdf",false, null, null);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-17
      • 1970-01-01
      • 2015-06-28
      • 1970-01-01
      • 2018-02-01
      • 1970-01-01
      相关资源
      最近更新 更多