• FastReport打印DataTable


    数据DataTable:

     1.创建2行1列Table:

    2.添加事件:

    3.添加代码:

    4. 效果

     

    附代码:

    private void Table1_ManualBuild(object sender, EventArgs e)
        {
          // get the "Customers" datasource
          DataSourceBase customers = Report.GetDataSource("Customers");
          // init it
          customers.Init();
          
          // number of columns in the datasource
          int colCount = customers.Columns.Count;
          
          // print the table header which contains column titles. It's a row with index = 0.
          Table1.PrintRow(0);
          for (int i = 0; i < colCount; i++)
          {
            // fill the cell with column title
            Cell1.Text = customers.Columns[i].Alias;
            // print it
            Table1.PrintColumn(0);
          }
          
          // now print a datasource content
          while (customers.HasMoreRows)
          {
            // print the table body. It's a row with index = 1.
            Table1.PrintRow(1);
            for (int i = 0; i < colCount; i++)
            {
              // fill the cell with datasource column's data
              Cell2.Text = customers[customers.Columns[i]].ToString();
              // print it
              Table1.PrintColumn(0);
            }
            
            // move to the next row
            customers.Next();
          }
        }
    View Code

     安装的FastReport官方事例:

    C:\Program Files (x86)\FastReports\FastReport.Net\Demos\Reports\Print DataTable

    所有列保持在一页:

     事件:

     Table2.ResultTable.AfterCalcBounds += new EventHandler(ResultTable_AfterCalcBounds);
        private void ResultTable_AfterCalcBounds(object sender, EventArgs e)
        {
          TableResult resultTable = sender as TableResult;
          float tableWidth = resultTable.Width;
          float pageWidth = Engine.PageWidth;
          
          if (tableWidth > pageWidth)
          {
            // table is wider than page, correct the columns width
            float ratio = pageWidth / tableWidth;
            foreach (TableColumn column in resultTable.Columns)
            {
              column.AutoSize = false;
              column.Width *= ratio;
            }
            
            // this will recalculate table rows height
            resultTable.CalcHeight();
          }
        }
  • 相关阅读:
    博客园第一篇随笔css3动画(奔跑的小杨)
    Python输出菱形
    Android开发经验总结
    Android中Activity共享变量的另一方法:Application context
    system()与execv()函数使用详解
    Sublime Text2 编译和运行C/C++程序(windows)
    Android View.post(Runnable )
    Android图像处理之Bitmap类
    android中dip、dp、px、sp和屏幕密度
    System.setProperty and System.getProperty
  • 原文地址:https://www.cnblogs.com/tiancaige/p/15942870.html
Copyright © 2020-2023  润新知