Program.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using System.Data;
  3. using System.Data.OleDb;
  4. using CustomControls.Design;
  5. using DevExpress.XtraReports.UI;
  6. namespace PatternDemo
  7. {
  8. static class Program
  9. {
  10. /// <summary>
  11. /// 应用程序的主入口点。
  12. /// </summary>
  13. [STAThread]
  14. static void Main()
  15. {
  16. DataTable rs = new DataTable();
  17. 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;';"))
  18. {
  19. odConnection.Open();
  20. using (OleDbCommand cmd = new OleDbCommand())
  21. {
  22. cmd.Connection = odConnection;
  23. cmd.CommandType = CommandType.Text;
  24. cmd.CommandText = "SELECT * FROM [Sheet1$]";
  25. using (OleDbDataAdapter oleda = new OleDbDataAdapter(cmd))
  26. {
  27. oleda.Fill(rs);
  28. }
  29. }
  30. odConnection.Close();
  31. }
  32. var report = new XtraReport();
  33. report.DataSource = rs;
  34. /* 测试循环获取控件 */
  35. //report.AfterPrint += (sender, args) =>
  36. //{
  37. // XtraReport xtraReport = (XtraReport)sender;
  38. // var a = xtraReport.Pages[0];
  39. // NestedBrickIterator iterator = new NestedBrickIterator(a.InnerBricks);
  40. // while (iterator.MoveNext())
  41. // {
  42. // VisualBrick visualBrick = iterator.CurrentBrick as VisualBrick;
  43. // if (visualBrick is TableBrick tableBrick)
  44. // {
  45. // var b = tableBrick.Bricks;
  46. // }
  47. // }
  48. //};
  49. ReportDesignTool designTool = new ReportDesignTool(report);
  50. CustomControlToolBoxRegistrator.AddPatternControlToToolBox(designTool.DesignRibbonForm.DesignMdiController);
  51. designTool.ShowRibbonDesignerDialog();
  52. }
  53. }
  54. }