WINCC6.0怎么实现历史报警归档,就是建立定期归档并转换成EXCLE文档保存。,谁能否给个具体的说明啊?谢谢
最佳答案
转一个帖子
取之于“民”用之于“民”,几段代码,希望对后来者有帮助,不要见笑。
1、记录脚本:同一卡片号的每一根钢的数据记录,有多少根,记多少行
#include "apdefap.h"
int gscAction( void )
{
#pragma code ()
char FileName[20] = " ";
double genshu,row,col;
__object* pExcel = NULL;
genshu=GetTagDouble("记数根数");
SetTagDouble("根数记录",genshu);
row=genshu+4;
if((GetTagBit("钢温记录信号")==1))
{
pExcel = __object_create("Excel.Application.9"); //9表示用的是office
2000
pExcel->Visible =0;
pExcel->Workbooks ->Open ("e:\\LZEQ_HMI\\JILU.xls");//Cells(row,col)
pExcel->Worksheets("sheet1")->Cells(row,1)->Value=GetTagWord("记数根数
");
pExcel->Worksheets("sheet1")->Cells(row,2)->Value=GetTagChar("开始时间
");
pExcel->Worksheets("sheet1")->Cells(row,3)->Value=GetTagWord("1#高温计
温度记录");
pExcel->Worksheets("sheet1")->Cells(row,4)->Value=GetTagFloat("1#水箱流
量记录");
pExcel->Worksheets("sheet1")->Cells(row,5)->Value=GetTagWord("2#高温计
温度记录");
pExcel->Worksheets("sheet1")->Cells(row,6)->Value=GetTagFloat("2#水箱流
量记录");
pExcel->Worksheets("sheet1")->Cells(row,7)->Value=GetTagWord("3#高温计
温度记录");
pExcel->Worksheets("sheet1")->Cells(row,8)->Value=GetTagFloat("3#水箱流
量记录");
pExcel->Worksheets("sheet1")->Cells(row,9)->Value=GetTagWord("4#高温计
温度记录");
pExcel->Worksheets("sheet1")->Cells(row,10)->Value=GetTagWord("5#高温计
温度记录");
pExcel->Worksheets("sheet1")->Cells(row,11)->Value=GetTagFloat("4#水箱
流量记录");
pExcel->Worksheets("sheet1")->Cells(row,12)->Value=GetTagWord("6#高温计
温度记录");
pExcel->Worksheets("sheet1")->Cells(row,13)->Value=GetTagWord("7#高温计
温度记录");
pExcel->Worksheets("sheet1")->Cells(row,14)->Value=GetTagFloat("5#水箱
流量记录");
pExcel->Worksheets("sheet1")->Cells(row,15)->Value=GetTagWord("8#高温计
温度记录");
pExcel->Worksheets("sheet1")->Cells(row,16)->Value=GetTagChar("系统时间
");
SetTagBit("钢温记录信号",0);
}
pExcel->ActiveWorkbook->Save;
pExcel->Workbooks->Close();
pExcel->Quit();
__object_delete(pExcel);
return 0;
}
2、存储脚本。每一卡片号的钢记录为一张以卡片号为名的Excel表
#include "apdefap.h"
int gscAction( void )
{
#pragma code ("kernel32.dll")
VOID GetLocalTime(LPSYSTEMTIME lpSystemTime);
#pragma code ()
char FileName[20] = " ";
char* Name;
float guige,hao;
#pragma code("kernel32.dll")
BOOL DeleteFileA(LPCTSTR lpFileName);//声明API函数。
#pragma code()
SYSTEMTIME sysTime;
__object* pExcel = NULL;
GetLocalTime(&sysTime);
hao=GetTagFloat("卡片号_22");
//Name=GetTagChar("卡片号_22");
if (hao==0)
{
Name=GetTagChar("系统时间");
}
else
{
Name=GetTagChar("卡片号_22");
}
guige=GetTagFloat("轧制规格_22");
if (guige>1000)
{
guige=guige/100;
SetTagFloat("成品规格记录",guige);
}
else
{
SetTagFloat("成品规格记录",guige);
}
if ((guige>100)&(guige<1000))
{
guige=guige/10;
SetTagFloat("成品规格记录",guige);
}
else
{
SetTagFloat("成品规格记录",guige);
}
if((GetTagBit("转存")==1))
{
sprintf(FileName,"e:\\LZEQ_HMI\\记录\\%s.xls" ,Name);
pExcel = __object_create("Excel.Application.9"); //9表示用的是office
2000
pExcel->Visible = 0;
pExcel->Workbooks ->Open ("e:\\LZEQ_HMI\\JILU.xls");
pExcel->Worksheets("sheet1")->Range("A2")->Value=GetTagChar("形状");
pExcel->Worksheets("sheet1")->Range("A1")->Value=GetTagChar("控冷");
pExcel->Worksheets("sheet1")->Range("C2")->Value=GetTagFloat("成品规格
记录");
pExcel->Worksheets("sheet1")->Range("F2")->Value=GetTagChar("开始日期
1");
pExcel->Worksheets("sheet1")->Range("J2")->Value=GetTagChar("系统日期
");
pExcel->Worksheets("sheet1")->Range("C3")->Value=GetTagDouble("卡片号
_22");
pExcel->Worksheets("sheet1")->Range("F3")->Value=GetTagChar("钢种_22");
pExcel->Worksheets("sheet1")->Range("I3")->Value=GetTagChar("炉号_22");
pExcel->Worksheets("sheet1")->Range("L3")->Value=GetTagChar("来料规格
_22");
pExcel->Worksheets("sheet1")->Range("O3")->Value=GetTagChar("本卡片号根
数_22");
pExcel->ActiveWorkbook->SaveAs(FileName);
pExcel->Workbooks->Close();
pExcel->Quit();
__object_delete(pExcel);
DeleteFileA("e:\\LZEQ_HMI\\JILU.xls");//调用API函数。
pExcel = __object_create("Excel.Application.9"); //9表示用的是office
2000
pExcel->Visible =0;
pExcel->Workbooks ->Open ("e:\\LZEQ_HMI\\运行数据库初始\\JILU.xls");
pExcel->ActiveWorkbook->SaveAs("e:\\LZEQ_HMI\\JILU.xls");
pExcel->Workbooks->Close();
pExcel->Quit();
__object_delete(pExcel);
SetTagBit("转存",0);
}
return 0;
}
3、记录卡片号查询代码
char FileName[256];
sprintf(FileName,"C:\\Program Files\\Microsoft
Office\\Office\\Excel.exe e:\\LZEQ_HMI\\记录\\%s.xls",GetTagChar("查询
卡片号"));
ProgramExecute(FileName);
只用第二条就可以满足你的要求了
提问者对于答案的评价:
蛮全面的!谢谢
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc277690.html