本文主要介紹如何在FastReport.NET中用一個插件來連接XLSX 文件作為數據源。

FastReport .Net官方最新版免費下載試用,曆史版本下載,在線文檔和幫助文件下載-慧都網
若要使用它,必須首先生成項目:
С:\Program Files (x86)\FastReports\FastReport.Net\Extras\Core\FastReport.Data\FastReport.Data.Excel
構建項目後,您需要通過以下兩種方式之一将插件添加到應用程序中。
- 通過設計器連接插件:

FastReport.NET
- 在啟動項目時将插件添加為依賴項,并使用以下命令在代碼中注冊它:FastReport.Utils.RegisteredObjects.AddConnection(typeof(ExcelDataConnection));要創建與Excel的連接,您需要單擊設計器中的“數據”選項卡,然後選擇“添加數據源”項。在出現的窗口中,單擊“新建連接”按鈕。要進行連接,您需要 .XLSX 文件。
如果訪問文件沒有問題,則在單擊“下一步”按鈕後将顯示表列表。連接表時,必須選中表名稱左側的框。之後,您可以完成連接。

FastReport.NET
數據源連接完成後,需要将波段連接到該波段。
最終報表将使用從創建的 Excel 連接到的數據。
從代碼連接到 Excel 的示例:
// Create ExcelDataConnection instance var connection = new ExcelDataConnection();
// Set connection string connection.ConnectionString = @"C:\Matrix With Rows Only.xlsx"; // Initialize all table connection.CreateAllTables();
// Set name connection connection.Name = "NewConnection";
// Create Report instance var report = new Report();
// Add connection to report report.Dictionary.Connections.Add(connection);
// Set connection show connection.Enabled = true;
// Choose all tables and connect it to the report foreach (TableDataSource table in connection.Tables) { table.Enabled = true; }
執行此代碼,我們可以在設計器中看到與表的新連接。這将顯示在可用連接列表中。值得注意的是,“工作表”的名稱用作表名稱,列的名稱用作字段名稱。
本次FastReport.NET使用教程就介紹到這裡了, 更多産品授權信息點擊查看FastReport.NET價格,或者咨詢慧都在線客服。
FastReport .Net正版購買,FastReport .Net授權價格咨詢,FastReport .Net官方授權經銷商-慧都網
,








