生成报表时,有时记录较少,甚至没有,最终生成的报表会显得非常空,fastreport本身没有提供使用空行补满页的功能。搜索到的实现方案比较复杂。
这里研究了另一个方案,对数据源的selectcommand进行处理,直接获得指定行数的数据源:使用 union all select NULL,...补足的补空行
private void _StartReport(object sender, EventArgs e)
{
DataConnectionBase con=Report.FindObject("Connection") as DataConnectionBase; //获得 DataConnectionBase
SetSelectCommand(con.Tables[0],19); //调用函数
}
{
table.ForceLoadData=true; //数据源初始化之后,重新获取数据,必须设置
table.Init();
if(table.RowCount%n!=0||table.RowCount==0)
{
string sql=" union all select "; //构造union all select NULL,...,根据table的列数,添加NULL
for(int i=0;i<table.Columns.Count;i++)
sql+="NULL,";
sql=sql.Trim(',');
for(int j=0;j<n-table.RowCount%n;j++) //补充空行
table.SelectCommand+=sql;
}
}