将MS Access报告导入C#



你能帮我解决一个小问题吗?非常感谢:(

所以我有一个访问应用程序,我正在转换成C#。它实际上相当巨大,并且由于访问非常有限而使用了多访问数据库。现在我遇到的一个问题是用C#做报告。我知道可以从Access将报告导出为XML格式,但问题是客户端想要一个不支持SQL Server Reporting服务的SQL Server Express版本(据我所知(。那么,无论如何都有可能将这些报告导入C#中吗?或者至少只有布局?

我正在使用适用于Visual Studio 2017 的Microsoft RDLC报表设计器

谢谢你抽出时间!

编辑:或者,我可以使用C#构建报告吗?

简短的回答是

Access报告在每一个方面都非常特定于Access,并且与RDLC非常不同。

下面是我和我的一个同事为在.Net中创建的报告做的一个例子,它完全模仿了旧样本Northwind数据库的报告:

Northwind.NET

我以前从未听说过这个,但听起来很有趣。我在谷歌上搜索了一下,发现了这个。

MainForm类是应用程序,是开始自上而下评估代码的好地方。此应用程序只执行三项任务。当浏览。。。按钮,它会将报告加载到列表框中。隐藏收缩复制代码

// we have a valid file name so we now need to
// populate the list box with available reports
listBoxReports.Items.Clear();
// create an application object.
MsAccess.Application app = new MsAccess.Application();
// open the access database file.
app.OpenCurrentDatabase(dlg.FileName, false, "");
string sql = "SELECT [Name] FROM MSysObjects WHERE Type = -32764";
dao.Database db = app.CurrentDb();
// query the database for all the reports.  all this data is
// contained in the MSysObejcts table which is invisible through
// the table listing in access.
dao.Recordset rs = db.OpenRecordset(sql, Type.Missing, Type.Missing, Type.Missing);
// go through and add all the reports to the list box.
while (!rs.EOF) {
listBoxReports.Items.Add(rs.Fields[0].Value);
rs.MoveNext();
}
// clean up
rs.Close();
rs = null;
db.Close();
db = null;
app.CloseCurrentDatabase();
app = null;

当打印。。。按钮,则打开所选报告并将其发送到默认打印机。隐藏复制代码

string report = listBoxReports.SelectedItem.ToString();
// create an application object.
MsAccess.Application app = new MsAccess.Application();
// open the access database file.
app.OpenCurrentDatabase(textBoxAccess.Text.Trim(), false, "");
app.Visible = false;
// open the report
app.DoCmd.OpenReport(report, 
Microsoft.Office.Interop.Access.AcView.acViewPreview, Type.Missing, 
Type.Missing, MsAccess.AcWindowMode.acWindowNormal, Type.Missing);
// print the report to the default printer.
app.DoCmd.PrintOut(MsAccess.AcPrintRange.acPrintAll, Type.Missing, 
Type.Missing, MsAccess.AcPrintQuality.acHigh, Type.Missing, Type.Missing);
// cleanup
app.CloseCurrentDatabase();
app = null;

最后,单击"保存"按钮时,所选报告将以HTML形式保存在与Access数据库文件相同的目录中。隐藏复制代码

// create an application object.
MsAccess.Application app = new MsAccess.Application();
// open the access database file.
app.OpenCurrentDatabase(textBoxAccess.Text.Trim(), false, "");
app.Visible = false;
// open the report
app.DoCmd.OpenReport(report, Microsoft.Office.Interop.Access.AcView.acViewPreview, 
Type.Missing, Type.Missing, MsAccess.AcWindowMode.acWindowNormal, Type.Missing);
// export the report to an HTML file
app.DoCmd.OutputTo(MsAccess.AcOutputObjectType.acOutputReport, 
report, "HTML (*.html)", fileName, Type.Missing, Type.Missing, Type.Missing);
// cleanup
app.CloseCurrentDatabase();
app = null;

最后,

1)From the main menu select Project > Add Reference.
2)Go to the COM tab. Scroll down and select Microsoft Access 11.0 Object Library.
3)Click Select and then click OK.
using MsAccess = Microsoft.Office.Interop.Access;

顺便说一句,可以考虑将Access Tables和Queries导入Python或R。如果您使用的是SQL Server Express,我想钱是一个问题。Python和R都是100%免费的,并且都可以很好地使用Access。最后,Python和R都有非常非常强大的报告工具。

你能直接导入它们吗?不。据我所知,没有任何工具可以。您应该能够在ReportViewer中重新创建它们,尽管这很乏味。

对我来说,标记为答案的帖子是不正确的。这个问题没有直接的答案。哪里没有副本&可以在这里制作糊状溶液。但是,我已经解决了类似的问题,将MS Access应用程序转换为C#程序。使用报表的大多数耗时任务都是格式化报表的外观。我使用Crystal Reports和DevExpress报表解决方案将报表导入到他们的报表环境中。他们工作得很好,为你制作了所有的格式。从零开始格式化所有报告可以节省大量无聊的时间。但是,您需要为报表修复查询和数据库连接。因为MS Access使用了自己的SQL语法。但对于程序员来说,这些任务更有趣。

最新更新