gpt4 book ai didi

c# - 将 Access 报告导出为 PDF

转载 作者:太空宇宙 更新时间:2023-11-03 22:55:51 25 4
gpt4 key购买 nike

我正在用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com