Mar*_*oso 3 c# pdf asp.net ms-access oledbcommand
我正在用 C# 编写一个连接到 Access 数据库的 ASP.NET 应用程序,现在我希望它将报告导出为 PDF。这是我的代码,仅连接到 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!");
}
Run Code Online (Sandbox Code Playgroud)
我解决了自动化问题,我按照这个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
);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2265 次 |
| 最近记录: |