亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將 MS Access 報告導入 C#

將 MS Access 報告導入 C#

C#
慕田峪7331174 2021-11-07 20:16:01
你能幫我解決一個小問題嗎?這將不勝感激 :)所以我有一個正在轉換為 C# 的訪問應用程序。它實際上非常龐大,并且由于訪問非常有限,因此使用了多個訪問數據庫?,F在我遇到的一個問題是用 C# 做報告。我知道可以從 Access 將報告導出為 XML 格式,但問題是客戶想要一個不支持 SQL Server 報告服務的 SQL Server Express 版本(據我所知)。那么無論如何都可以將這些報告導入到 C# 中嗎?或者至少只有布局?我正在為 Visual Studio 2017 使用 Microsoft RDLC 報告設計器謝謝你的時間!編輯:或者有什么替代方法可以用來用 C# 構建報告?
查看完整描述

3 回答

?
慕姐4208626

TA貢獻1852條經驗 獲得超7個贊

簡短的回答是No

Access 報告在每一件事上都非常特定于 Access,與 RDLC 非常不同。

這是我和我的一個同事為在 .Net 中創建的報告所做的示例,該示例完全模仿了舊示例 Northwind 數據庫的報告:

北風網


查看完整回答
反對 回復 2021-11-07
?
紅顏莎娜

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 都有非常、非常、非常強大的報告工具。


查看完整回答
反對 回復 2021-11-07
?
呼喚遠方

TA貢獻1856條經驗 獲得超11個贊

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


查看完整回答
反對 回復 2021-11-07
  • 3 回答
  • 0 關注
  • 218 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號