组态王日报表实例
一、控件祝贺已超 1 万工控人加入 PLC 工业自动化精 英群
1.1 时间控件:Calendar Control

1.2 按钮:

1.3 报表控件

二、控件设置
2.1 时间控件

2.2 确定按钮

String Year ; //查询开始年
String Month;
String Day;
/*-----取两位数年分(即取2004的04)----*/
Year = StrRight( StrFromReal(Ctrl0018.Year, 0, "f" ), 4 );
Month = StrFromReal(Ctrl0018.Month,0, "f" );
Day = StrFromReal(Ctrl0018.Day,0, "f" );
//保证年月日都是用两位数表示,得到##/##/##字符串格式的日期
if( Strlen(Month ) == 1) //如果月份小于10,在前加上0,即8又08表示
Month = "0" + StrFromReal(Ctrl0018.Month, 0, "f" );
if( Strlen(Day ) == 1 )
Day = "0" + StrFromReal(Ctrl0018.Day,0, "f" );
报表日期 = Year + "年" + Month + "月" + Day + "日";
//定义一个内存字符串变量"报表日期",用于在报表里显示当前查询到的报表的日期
Long StartTime16; //查询时间
Long Y16;
Y16=Ctrl0018.Year;
Long M16;
M16=Ctrl0018.Month;
Long D16;
D16=Ctrl0018.Day;
StartTime16=NewHTConverttime(Y16, M16, D16, 0, 0, 0);
ReportSetHistData("Report0", "\\local\一号压力", StartTime16, 3600, "B5:B28");
ReportSetHistData("Report0", "\\local\二号压力", StartTime16, 3600, "C5:C28");
ReportSetHistData("Report0", "\\local\三号压力",StartTime16, 3600, "D5:D28");
ReportSetHistData("Report0", "\\local\四号压力",StartTime16, 3600, "E5:E28");
ReportSetHistData("Report0", "\\local\五号压力", StartTime16, 3600, "F5:F28");
ReportSetHistData("Report0", "\\local\六号压力", StartTime16, 3600, "G5:G28");
ReportSetHistData("Report0", "\\local\余氯",StartTime16, 3600, "H5:H28");
ReportSetHistData("Report0", "\\local\浊度",StartTime16, 3600, "I5:I28");
ReportSetHistData("Report0", "\\local\一号瞬时流量", StartTime16, 3600, "J5:J28");
ReportSetHistData("Report0", "\\local\二号瞬时流量", StartTime16, 3600, "K5:K28");
ReportSetHistData("Report0", "\\local\一号累计流量",StartTime16, 3600, "L5:L28");
ReportSetHistData("Report0", "\\local\二号累计流量",StartTime16, 3600, "M5:M28");
ReportSetHistData("Report0", "\\local\信号强度",StartTime16, 3600, "N5:N28");
2.3 打印按钮

2.4 保存按钮

string filename;
filename="D:\数据文件夹\"+
StrFromReal(Ctrl0018.Year, 0, "f" )+ "年"+
StrFromReal( Ctrl0018.Month, 0, "f" )+ "月"+
StrFromReal( Ctrl0018.Day, 0, "f" )+"日报表"+".xls";
ReportSaveAs("Report0",filename);
2.5 报表控件

三、运行效果

