3 回答

TA貢獻1842條經驗 獲得超13個贊
在今天之前我從未聽說過這個,但這聽起來很有趣。我做了一些谷歌搜索,并遇到了這個。
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;
順便說一句,考慮將訪問表和查詢導入 Python 或 R。如果您使用 SQL Server Express,我猜錢是一個問題。Python 和 R 都是 100% 免費的,并且都可以與 Access 完美配合。最后,Python 和 R 都有非常、非常、非常強大的報告工具。

TA貢獻1856條經驗 獲得超11個贊
至于我,標記為答案的帖子是不正確的。這個問題沒有直接的答案。哪里沒有復制和粘貼解決方案可以在這里制作。但是,我已經解決了類似的問題,將 MS Access 應用程序轉換為 C# 程序。大多數耗時的報告任務都是格式化報告的外觀。我使用 Crystal Reports 和 DevExpress 報告解決方案將報告導入到他們的報告環境中。他們很好地為您制作所有格式。并節省大量無聊的時間來從頭開始格式化所有報告。但是您需要修復報表的查詢和數據庫連接。因為 MS Access 使用了它自己的 SQL 語法。但對于程序員來說,這些是更有趣的任務。
- 3 回答
- 0 關注
- 218 瀏覽
添加回答
舉報