Spread 是一款很出色的表格控件,Spread 可以使開發人員把具有兼容 Microsoft Excel 的電子表格添加到程序中。ActiveReports 提供了一個非常靈活的、簡單的報表環境。下面將展示怎樣在 ActiveReports 中使用 Spread for WinForm。和其他三方控件一樣,Spread 控件也可以在 ActiveReports 中當作自定義控件使用,只是拖拖拽拽這么簡單。但是怎樣在 ActiveReports 中使用 Spread 全部的對象模型(例如方法、屬性等)?不幸的是,因為 ActiveReports 仍然把 Spread 當作自定義控件,這樣在設計時的 Spread 設計時功能的使用會受到很多限制(類似于標準控件)。那么該怎樣解決這個問題呢??
下面我們就進行一個快速展示:?
一、??? 為了給大家一個直觀的影響,我們先給出應用到的控件截圖:?
1.??????? Spread,ActiveReports 中使用 Spread for WinForm 截圖展示。?
2.??????? NewActiveReport,我們就是在它上面添加 Spread 控件。?
?
3.??????? Viewer,我們會在 viewer 上面調用我們的 NewActiveReport。?
?
二、 有了上面的零部件,下面我們就開始組裝了~?
1.??????? 為了美觀,我們對NewActiveReport做了一些加工,這里不詳細介紹。從工具箱中拖拽 Spread 到 NewActiveReport實例中,Spread 對象會作為一個自定義控件添加到報表中,ActiveReports 把 Spread 當作自定義控件,所以目前 Spread 為灰色。(紅色矩形內部即為 Spread )?
?
?
2.在報表的開始實踐中轉化自定義控件為 Spread 對象,代碼如下:
fpSpread1=(FarPoint.Win.FpSpread)customControl.Control;
?
3.在報表開始事件 或 Spread 控件添加的區域的格式化事件中訪問 Spread 對象的屬性。你可以添加、刪除、定制表單,單元格,行,甚至給 Spread 綁定數據源。
fpSpread1 = (FarPoint.Win.Spread.FpSpread)customControl1.Control;
??????????? FarPoint.Win.Spread.SheetView newsheet = new FarPoint.Win.Spread.SheetView();
??????????? newsheet.SheetName = "Active Reports";
??????????? newsheet.ColumnCount =4;
??????????? newsheet.RowCount = 5;
????????? fpSpread1.Sheets.Add(newsheet);
4.??????? 現在創建一個 ActiveReports 實例,調用報表實例運行方法,在查看器中觀察報表。
NewActiveReport1 rpt = new NewActiveReport1();
rpt.Run();
viewer1.Document = rpt.Document;
就這樣,我們成功的在在 ActiveReports 中使用 Spread for WinForm。
?
本文轉自 powertoolsteam 51CTO博客,原文鏈接:http://blog.51cto.com/powertoolsteam/762462,如需轉載請自行聯系原作者