c# - 将 Access 报告导出为 PDF

标签 c# asp.net ms-access pdf oledbcommand

我正在用 C# 编写一个连接到 Access 数据库的 ASP.NET 应用程序,现在我希望它将报告导出为 PDF。这是我只连接到 Access 的代码,我正在考虑运行 Access 宏或使用 Microsoft.Office.Interop.Access.Application DoCmd.OutputTo 运行命令,但我不知道如何使用它。有帮助吗?

string user = "myUser";
string pass = "myPass";
string host = "myHost";
OleDbConnection connection = new OleDbConnection(@"Provider = Microsoft.ACE.OLEDB.12.0; Data Source = myPath");
string _command = ...; //I don't know what put here

try
{
    OleDbCommand command = new OleDbCommand(_command, connection);
    command.CommandText = ...; //I don't know what put here
    int temp = command.ExecuteNonQuery();
    Console.WriteLine("PDF created!");
 }

最佳答案

我用自动化解决了我的问题,我遵循了这个 https://support.microsoft.com/en-us/help/317114/how-to-automate-microsoft-access-by-using-visual-c (由 Erik von Asmuth 建议)现在我可以将报告导出为 PDF 格式。我现在的代码:

using Microsoft.Office.Interop.Access;

Application access = new Microsoft.Office.Interop.Access.Application();
access.OpenCurrentDatabase(@"C:\Desktop\MyDB.accdb", false);

access.DoCmd.OutputTo(AcOutputObjectType.acOutputReport, 
    "Dati", //ReportName
    ".pdf", //OutputType
    @"C:\Desktop\Test.pdf",  //outupuFile
    System.Reflection.Missing.Value,
    System.Reflection.Missing.Value,
    System.Reflection.Missing.Value,
    AcExportQuality.acExportQualityPrint
);

关于c# - 将 Access 报告导出为 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45412411/

相关文章:

c# - 套接字异常 : recvfrom failed: ECONNRESET (Connection reset by peer) occurs

ms-access - 将多行转换为具有唯一键的列

java - Java 8 中删除了 JDBC-ODBC 桥,最好的替代方案是什么?

c# - process.start从ASP页面开始,exe文件放在哪里

c# - 获取错误作为无效的列名称 C#.NET

C++ Builder - 多线程数据库更新

c# - 如何将 TreeViewItems 添加到 TreeView 控件

C# PHP 样式数组键

c# - 为 ASP.Net MVC 2 创建 RESTful 按钮

asp.net - 利用Active Directory的REST API的授权方法