场景
FastReport安装包下载、安装、去除使用限制以及工具箱中添加控件:
https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/100893794
Winform中使用FastReport实现简单的自定义PDF导出:
https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/100920681
在上面的基础上,在设计模板时添加一个Table,然后在点击打印预览页面,对Table进行赋值。
实现
打开Design Report 界面,在左边菜单栏拖拽一个Table控件,然后改为一行两列,具体根据自己需求。
记住Name 属性这里为Table1。
然后在按钮的点击事件里
var table1 = report1.FindObject("Table1") as TableObject ; if (table1 != null) { //设置表格的边框颜色 table1.Border.Color = Color.Red; //设置表格的border全显示 table1.Border.Lines = BorderLines.All; //新建一行 TableRow row1 = new TableRow(); //新建Cell1 TableCell cell1 = new TableCell(); //Cell1赋值 cell1.Text = "公众号:"; //新建Cell2 TableCell cell2 = new TableCell(); //设置Cell的边框属性 cell2.Border.Color = Color.Black; cell2.Border.Lines = BorderLines.All; //Cell2赋值 cell2.Text = "霸道的程序猿"; //讲Cell添加到Row row1.AddChild(cell1); row1.AddChild(cell2); //将ROw添加到table table1.Rows.Add(row1); }