锐浪报表使用
By
admin
at 2018-08-28 • 0人收藏 • 3850人看过
感谢daheian提供的示例和代码。
1,打印和打印预览
示例代码里面用的是mdb数据库,这里我利用官方提供的示例数据。
import win.ui; import reportRl; import reportRl.path; import reportRl.displayView; /*DSG{{*/ mainForm = win.form(text="aardio form";right=759;bottom=469) mainForm.add( btnPrint={cls="button";text="打印";left=9;top=5;right=80;bottom=30;dl=1;dt=1;z=1}; btnPrintPreview={cls="button";text="打印预览";left=88;top=5;right=159;bottom=30;dl=1;dt=1;z=2}; static={cls="static";text="static";left=10;top=39;right=751;bottom=458;border=1;db=1;dl=1;dr=1;dt=1;transparent=1;z=3} ) /*}}*/ var report,err = reportRl(); if(!report){ mainForm.msgbox(err) } var fileName = reportRl.path.templatePath() + "1a.简单表格.grf"; report.LoadFromFile(fileName); report.DetailGrid.Recordset.LoadData("http://www.gridreport.cn/demos/data/DataCenter.ashx?data=Customer") //report.DetailGrid.Recordset.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=" + reportRl.path.dataPath() + "NorthWind.mdb;"; var displayObj,err = reportRl.displayView(mainForm.static); if(!displayObj){ mainForm.msgbox(err) } displayObj.Report = report; displayObj.Start(); mainForm.btnPrint.oncommand = function(id,event){ report.Print(true); } mainForm.btnPrintPreview.oncommand = function(id,event){ report.PrintPreview(true); } mainForm.enableDpiScaling() mainForm.show(); return win.loopMessage();
5 个回复 | 最后更新于 2018-11-07
最简单的报表就是按照设计器的向导一步一步来:
import win.ui; import reportRl; import reportRl.path; import reportRl.displayView; /*DSG{{*/ mainForm = win.form(text="推式提供报表数据-Grid++Report例子 for aardio";right=1085;bottom=632;border="dialog frame";max=false) mainForm.add( button={cls="button";text="打印预览";left=0;top=40;right=109;bottom=74;z=1}; button2={cls="button";text="退出";left=0;top=114;right=109;bottom=148;z=2}; button3={cls="button";text="打印预览";left=0;top=206;right=109;bottom=240;z=4}; static={cls="static";text="Static";left=140;top=34;right=1069;bottom=484;transparent=1;z=3} ) /*}}*/ var report = reportRl(); assert(report,"报表组件创建失败!"); var fileName = "C:\Users\popdes\Desktop\reportRl\reports\aarT.grf"; report.LoadFromFile(fileName); report.FetchRecord = function(){ /*在报表生成时且以推模式向报表提供数据,报表主对象请求数据时触发。*/ var name = report.FieldByName("name"); var nianling = report.FieldByName("nianling"); var tizhong = report.FieldByName("tizhong"); var zhuzhi = report.FieldByName("zhuzhi"); for(i=1;50;1){ report.DetailGrid.Recordset.Append(); name.AsString = "aaaa"++i; nianling.AsInteger = i; tizhong.AsFloat = 30+i; zhuzhi.AsString = "shanghaishi , jinganqu . xisihutong"++i report.DetailGrid.Recordset.Post(); } } mainForm.button2.oncommand = function(id,event){ //退出 mainForm.close(); } mainForm.button.oncommand = function(id,event){ //打印预览 report.PrintPreview(true); } mainForm.button3.oncommand = function(id,event){ var displayObj,err = reportRl.displayView(mainForm.static); if(!displayObj){ mainForm.msgbox(err) } displayObj.Report = report; displayObj.Start(); } mainForm.enableDpiScaling(); mainForm.show(); return win.loopMessage();
动态添加一条数据的方法:
var ii = 1; mainForm.button4.oncommand = function(id,event){ var c1 = report.FieldByName("c1"); var i1 = report.FieldByName("i1"); var f1 = report.FieldByName("f1"); report.DetailGrid.Recordset.Append(); c1.AsString = "A"++ii; i1.AsInteger = ii; f1.AsFloat = math.random(); report.DetailGrid.Recordset.Post(); displayObj.QuickRefresh() ii++; }
关键点在上面的:
displayObj.QuickRefresh()
回复#4 @aiwen :
没上传, 代码都在上面了,
先下载 reportx的库, https://pan.baidu.com/s/1OvgukJoq3SPJboZBGGLThA
之后代码按照上面的改改就好了.
登录后方可回帖
直接获取程序中的数据来显示和打印: