fastreport打印ftp图片_FastReport快速打印(.net)

本文介绍了如何使用FastReport插件通过RegisterData方法注册DataSet对象,以实现从FTP获取图片并进行打印的详细步骤。内容包括创建FastReport模板、编辑数据源、设置Table控件、编写后台代码以及测试打印效果。
摘要由CSDN通过智能技术生成

我第一次使用FastReport插件做的功能是打印一个十分复杂的excel表格,有几百个字段都需要绑定数据,至少需要4个数据源,而且用到横向、竖向合并单元格。

我不是直接连接数据库,而是使用RegisterData的方式自己注册DataSet对象,所有的表Table都是代码生成,填充到DataSet中,然后注册到控件中。

最开始尝试使用这个插件做一个简单的功能使用的就是下面的例子,不过花了一整天,还请假了4个人都没有搞出来,晚上拿着别人的模板直接修改,然后测试,就通过了。

之前测试,一直都提示未连接到数据源,原因是我直接使用记事本来向模板添加数据源导致的,平时别人使用的数据源都是自己写代码,调用Design的方式得到的,而且只能是winform程序,webform程序不行,因为要启动com组件。

下面是我总结的特别简单的一个方式,使用RegisterData的方式自己注册DataSet对象。

1,          选择【File】-》【New】 新建FastReport模板,选择下图的1。

a0d1d211a2fe4723bd1b8e4bf79fea70.png

2,          选择【View】-》【Data】,显示如下,导出Dictionary,保存。

c82f7fa9e066c357220eb3e47abd91db.png

3,          编辑导出的.frd文件,编辑完后保存,再导入。

如下:

(1)  TableDataSource 是数据源节点。

(2)  Name是DataSet对象的Table的表名。

(3)  Column是Table的列,模板绑定数据时,使用Column的Name属性。

4,          编辑模板,添加一个Table控件。

第一行直接双击输入文本;第二行直接将右边的数据源托到单元格中;

设置边框、字体。

72b85f0474480889f3930ea7a2e60ea7.png

5,          添加事件后台方法

如下图,选中Table1,在事件ManualBuild的后面双击,添加下面的代码:

28fb0d2d2b32a2a71269289de2e50dfe.png

// 控件Table1的构建事件

private void Table1_ManualBuild(object sender, EventArgs e)

{

DataSourceBase data1 = Report.GetDataSource("Table1"); // 获取DataSet中表名为Table1的数据源

data1.Init(); // 初始化

Table1.PrintRow(0); // 控件Table1打印第0行

Table1.PrintColumns(); // 每打印一行,都要调用 PrintColumn或PrintColumns

while(data1.HasMoreRows) // 打印重复循环的行

{

Table1.PrintRow(1);

Table1.PrintColumns();

data1.Next(); // 读取下一行

}

}

说明:

(1)   Table控件是从第0行开始的。

(2)   绑定数据的重复行,算作一行。

(3)   输出行之前,要先调用Init() 方法,当有两个数据源,比如data1和data2,data1又是data2的父数据源,需要把data1当做参数,如 data2.Init(data1);

(4)   每打印一行,都要调用 PrintColumn或PrintColumns

6,          添加c#代码

新建一个测试页面test.aspx,将一个FastReport控件拖放到页面上(只有按照过FastReport.net,且引用了FastReport.dll,FastReport.Bars.dll,FastReport.Web.dll之后才可以)

添加后页面如下:

后台方法:

protected void WebReport_StartReport(object sender, EventArgs e)

{

DataSet ds = new DataSet();

DataTable table1 = new DataTable();

table1.TableName = "Table1"; // 一定要设置表名称

ds.Tables.Add(table1);

// 添加表中的列

table1.Columns.Add("姓名", typeof(string));

table1.Columns.Add("密码", typeof(string));

// 任意添加一些数据

for (int i = 0, maxI = 10; i < maxI; i++)

{

DataRow row = table1.NewRow();

row["姓名"] = "我是" + i.ToString();

row["密码"] = i.ToString();

table1.Rows.Add(row);

}

Report FReport = (sender as WebReport).Report;

string sPath = GetReportsPath("test.frx") ;

FReport.Load(sPath);

// 将DataSet对象注册到FastReport控件中

FReport.RegisterData(ds);

}

///

/// 获取fastreport模板的路径

///

/// 模板名称

/// 返回模板路径

public string GetReportsPath(string sReportName)

{

return FastReport.Utils.Config.ApplicationFolder + "Reports\\" + sReportName;

}

7,          测试效果

1对应保存,可以是各种格式;

2对应打印;

3对应分页。

186ee6c2cd21531acbf6cb47fd20e272.png

version 4.9 --------------- + added export headers/footers in ODF export + added ability to print/export transparent pictures (properties TfrxPictureView.Transparent and TfrxPictureView.TransparentColor) (PDF export doesn't supported) + added new "split to sheet" modes for TfrxXMLExport + added support of /PAGE tag in TfrxRichView, engine automatically break report pages when find /PAGE tag + added ability to hide Null values in TfrxChartView (TfrxChartView.IgnoreNulls = True) + added ability to set any custom page order for printing (i.e. 3,2,1,5,4 ) + [enterprise] added variables "AUTHLOGIN" and "AUTHGROUP" inside the any report + [enterprise] now any report file can be matched with any (one and more) group, these reports are accessible only in matched groups + [enterprise] now you can set-up cache delays for each report file (reports.xml) + [enterprise] added new properties editor for reports in Configuration utility (see Reports tab) + [enterprise] added property "Xml" - "SplitType" in server configuration - allow to select split on pages type between none/pages/printonprev/rowscount + [enterprise] added property "Xml" - "SplitRowsCount" in server configuration - sets the count of rows for "rowscount" split type + [enterprise] added property "Xml" - "Extension" in server configuration - allow select between ".xml" and ".xls" extension for output file + [enterprise] added property "Html" - "URLTarget" in server configuration - allow select the target attribute for report URLs + [enterprise] added property "ReportsFile" - path to file with reports to groups associations and cache delays + [enterprise] added property "ReportsListRenewTimeout" in server configuration + [enterprise] added property "ConfigRenewTimeout" in server configuration + [enterprise] added property "MimeType" for each output format in server configuration + [enterprise] added property "BrowserPrint" in server configuration - allow printing by browser, added new template nav_print_browser
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值