红颜莎娜
在今天之前我从未听说过这个,但这听起来很有趣。我做了一些谷歌搜索,并遇到了这个。MainForm 类是应用程序,是开始对代码进行自上而下评估的好地方。此应用程序仅执行三项任务。当浏览...按钮被按下时,它会将报告加载到列表框中。隐藏收缩复制代码// we have a valid file name so we now need to// populate the list box with available reportslistBoxReports.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 uprs.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 reportapp.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);// cleanupapp.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 reportapp.DoCmd.OpenReport(report, Microsoft.Office.Interop.Access.AcView.acViewPreview, Type.Missing, Type.Missing, MsAccess.AcWindowMode.acWindowNormal, Type.Missing);// export the report to an HTML fileapp.DoCmd.OutputTo(MsAccess.AcOutputObjectType.acOutputReport, report, "HTML (*.html)", fileName, Type.Missing, Type.Missing, Type.Missing);// cleanupapp.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;顺便说一句,考虑将访问表和查询导入 Python 或 R。如果您使用 SQL Server Express,我猜钱是一个问题。Python 和 R 都是 100% 免费的,并且都可以与 Access 完美配合。最后,Python 和 R 都有非常、非常、非常强大的报告工具。