Bootstrap

WINCC CSV文件参数导出/导入

CSV文件参数导出

#include "apdefap.h"

void OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName)

{

FILE*  pFile = NULL;

char szFile[_MAX_PATH+10];

char* CC=NULL;

char * F[3]={"F1","F2","F3"};

char * T[3]={"T1","T2","T3"};

char * C[3]={"C1","C2","C3"};

int FF,i;

float TT;

strcat(szFile,"d:\\data.csv");

pFile=fopen(szFile,"w+");//注意如果用“a”代替“w+”则表示,不覆盖原来CSV文件内容

if(pFile==NULL)

{

printf("\r\nError in fopen()\r\n");

return;

}

for(i=0;i<=2;i++)

{

FF=GetTagDWord(F[i]);

TT=GetTagFloat(T[i]);

CC=GetTagChar(C[i]);

fprintf(pFile,"%d,%f,%s\n",FF,TT,CC);//注意这里%d和%f中间 有“,”可以使CSV到处和EXCEL格式相同 !!!重要

}

fclose(pFile);

}

CSV文件参数导入

#include "apdefap.h"

void OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName)

{

FILE*  pFile = NULL;

char szFile[_MAX_PATH+10];

char * F[3]={"F1","F2","F3"};

char * T[3]={"T1","T2","T3"};

char * C[3]={"C1","C2","C3"};

int FF,i;

float TT;

char  CC[20];

strcat(szFile,"d:\\data.csv");

pFile=fopen(szFile,"r+");

if(pFile==NULL)

{

printf("\r\nError in fopen()\r\n");

return;

}

for(i=0;i<=2;i++)

{

fscanf(pFile,"%d,%f,%s\n",&FF,&TT,CC);

SetTagDWord(F[i],FF);

SetTagFloat(T[i],TT);

SetTagChar(C[i],CC);

}

fclose(pFile);

}


如有交流的地方,请致信QQ: 1625785563

;