#include "apdefap.h"
int gscAction( void )
{
// WINCC:TAGNAME_SECTION_START
// syntax: #define TagNameInAction "DMTagName"
// next TagID : 1
// WINCC:TAGNAME_SECTION_END
// WINCC:PICNAME_SECTION_START
// syntax: #define PicNameInAction "PictureName"
// next PicID : 1
// WINCC:PICNAME_SECTION_END
#pragma code ("kernel32.dll")//调用动态链接库
VOID GetLocalTime(LPSYSTEMTIME lpSystemTime);
#pragma code ()
#pragma code("Shell32.dll")//调用动态链接库
VOID ShellExecuteA(HWND, LPCTSTR , LPCTSTR , LPCTSTR , LPCTSTR , INT);
#pragma code()
char FileName[30] = "";
char DateTime[30] = "";
int i;
int j;
SYSTEMTIME sysTime;
__object* pExcel = NULL; //建立 pExcel 指针 用来对 EXCEL 进行操作
HWND handle=NULL;
handle=FindWindow(NULL,"WinCC-运行系统 - ");
GetLocalTime(&sysTime);
//sprintf(FileName,"d:\\Day_Report_%02d-%02d-%02d.xls",sysTime.wHour,sysTime.wMinute,sysTime.wSecond);
//sprintf(FileName,"d:\\%02d-%02d-%02d.xls",sysTime.wHour,sysTime.wMinute,sysTime.wSecond);
sprintf(FileName,"e:\\ribao\\%04d-%02d-%02d.xlsx",sysTime.wYear,sysTime.wMonth,sysTime.wDay);
sprintf(DateTime,"%04d-%02d-%02d",sysTime.wYear,sysTime.wMonth,sysTime.wDay);
pExcel = __object_create("Excel.Application");
pExcel->Visible = 0;//控制生成的excel 文件是否可见,当1 时,生成excel文件时可见.
pExcel->Workbooks ->Open ("e:\\ribao\\ribao.xlsx");
pExcel->DisplayAlerts = 0;
//SetTagFloat("TAG2",10);
//i=GetTagWord("Minute")+3;
//if (i>26) { GetTagWord("Minute") ;}
//else if (i<=26)
//{
//sprintf(FileName,"d:\\Day_Report_%02d-%02d-%02d.xls",sysTime.wHour,sysTime.wMinute,sysTime.wSecond);
//pExcel = __object_create("Excel.Application");
pExcel->Visible = 0;//控制生成的excel 文件是否可见,当1 时,生成excel文件时可见.
//pExcel->Workbooks ->Open (FileName);
//pExcel->Workbooks ->Open ("d:\\Day_Report.xls");
//pExcel->Worksheets("sheet1")->Range("X1")->Value=GetTagChar("@ServerName");//Return-Type: char* 读取当前计算机名
//pExcel->Worksheets("sheet1")->Range("X2")->Value=GetTagChar("@CurrentUser");//Return-Type: char* 读取当前操作员
//SetTagFloat("TAG2",80);
SetTagChar("ac",DateTime);
pExcel->Worksheets("sheet1")->Cells(2,2)->Value=GetTagChar("ac");
pExcel->Worksheets("sheet1")->Cells(4,2)->Value=GetTagFloat("新城管路压力1");
pExcel->Worksheets("sheet1")->Cells(4,3)->Value=GetTagFloat("新城管路压力2");
pExcel->Worksheets("sheet1")->Cells(5,2)->Value=GetTagFloat("热电管路压力1");
pExcel->Worksheets("sheet1")->Cells(5,3)->Value=GetTagFloat("热电管路压力2");
pExcel->Worksheets("sheet1")->Cells(6,2)->Value=GetTagFloat("煤矸石管路压力1");
pExcel->Worksheets("sheet1")->Cells(6,3)->Value=GetTagFloat("煤矸石管路压力2");
pExcel->ActiveWorkbook->SaveAs(FileName);//存盘
//pExcel->ActiveWorkbook->PrintPreview();//可以预览
//pExcel->ActiveWorkbook->PrintOut();//直接打印
pExcel->Workbooks->Close();//关闭文件
pExcel->Quit();//退出Excel
__object_delete(pExcel);
return 0;
}
最佳答案
首先,FileName工作簿是自动新建的,还是已经存在的?
如果是已经存在的,只要打开就行了:pExcel->Workbooks ->Open(FileName);
如果是新建的,需要:pExcel->Workbooks ->Add;保存时:pExcel->ActiveWorkbook->SaveAs(FileName);
提问者对于答案的评价:
问题已经解决了 不过还是要谢谢大家
原创文章,作者:ximenziask,如若转载,请注明出处:https://www.zhaoplc.com/plc358781.html