场景

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);
            }

 

效果