using System; using System.Data; using System.Data.OleDb; using CustomControls.Design; using DevExpress.XtraReports.UI; namespace PatternDemo { static class Program { /// /// 应用程序的主入口点。 /// [STAThread] static void Main() { DataTable rs = new DataTable(); using (var odConnection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\Users\wangbc\Desktop\test.xlsx;Extended Properties='Excel 12.0;HDR=YES;IMEX=1;';")) { odConnection.Open(); using (OleDbCommand cmd = new OleDbCommand()) { cmd.Connection = odConnection; cmd.CommandType = CommandType.Text; cmd.CommandText = "SELECT * FROM [Sheet1$]"; using (OleDbDataAdapter oleda = new OleDbDataAdapter(cmd)) { oleda.Fill(rs); } } odConnection.Close(); } var report = new XtraReport(); report.DataSource = rs; /* 测试循环获取控件 */ //report.AfterPrint += (sender, args) => //{ // XtraReport xtraReport = (XtraReport)sender; // var a = xtraReport.Pages[0]; // NestedBrickIterator iterator = new NestedBrickIterator(a.InnerBricks); // while (iterator.MoveNext()) // { // VisualBrick visualBrick = iterator.CurrentBrick as VisualBrick; // if (visualBrick is TableBrick tableBrick) // { // var b = tableBrick.Bricks; // } // } //}; ReportDesignTool designTool = new ReportDesignTool(report); CustomControlToolBoxRegistrator.AddPatternControlToToolBox(designTool.DesignRibbonForm.DesignMdiController); designTool.ShowRibbonDesignerDialog(); } } }