Hello friend's , i need a help from you.
I need to write a C code for open , write a value ,and save an EXCEL sheet
For example :
open a new Excel sheet
write into A1 cell a value
save and close
I know very well a VB but a C i havent a little experience.
In this case i need to write a code in C because i need to insert this into a function already existing.
If is impossible to create a XLS file , also CSV is good
Can you help me ?
thank you in advance
[?]: WinCC C script for work with an EXCEL sheet
-
- Posts: 265
- Joined: Sat May 27, 2006 6:46 am
- Location: Europe
-
- Posts: 34
- Joined: Sun Feb 18, 2007 10:01 am
- Location: Europe
try this one
it's in italian
ORA = now
GIORNO = day
MESE = month
ANNO = year
it's in italian
ORA = now
GIORNO = day
MESE = month
ANNO = year
Code: Select all
#include "apdefap.h"
int gscAction( void )
{
extern float somma29,somma30,somma31,somma56,somma57,somma58,sommaTe;
extern float media29,media30,media31,media56,media57,media58,mediaTe;
float Ts29,Ts30,Ts31,Ts56,Ts57,Ts58,Te;
extern int i;
char filename[40],xx[30];
FILE *stream;
// Report TS29
strcpy(filename,"C:\\Dati\\Trend_TS29_");
sprintf (xx, "%u", GetTagWord("GIORNO"));
strcat(filename,xx);strcat(filename,"_");
sprintf (xx, "%u", GetTagWord("MESE"));
strcat(filename,xx);strcat(filename,"_");
sprintf (xx, "%u", GetTagWord("ANNO"));
strcat(filename,xx);strcat(filename,".csv");
if ((stream = fopen(filename,"r")) ==NULL)
{
stream = fopen(filename,"w");
fprintf(stream,"ORA,");
fprintf(stream,"TS29,");
fprintf(stream,"VVS29\n");
fclose(stream);
}
if (i>=6)
{
i=0;
}
if (i<=5)
{
Ts29=GetTagFloat("DB18_DD80");
somma29=(somma29+Ts29);
if (i==5){
media29=somma29/6;
stream = fopen(filename,"a");
fprintf(stream,"%s,",GetTagChar("ORA"));
fprintf(stream,"%3.3f,",media29);
fprintf(stream,"%1f\n",GetTagFloat("DB18_DD700"));
fclose(stream);
somma29=0;
media29=0;
}
}
// Report TS30
strcpy(filename,"C:\\Dati\\Trend_TS30_");
sprintf (xx, "%u", GetTagWord("GIORNO"));
strcat(filename,xx);strcat(filename,"_");
sprintf (xx, "%u", GetTagWord("MESE"));
strcat(filename,xx);strcat(filename,"_");
sprintf (xx, "%u", GetTagWord("ANNO"));
strcat(filename,xx);strcat(filename,".csv");
if ((stream = fopen(filename,"r")) ==NULL)
{
stream = fopen(filename,"w");
fprintf(stream,"ORA,");
fprintf(stream,"TS30,");
fprintf(stream,"VVS30\n");
fclose(stream);
}
if (i>=6)
{
i=0;
}
if (i<=5)
{
Ts30=GetTagFloat("DB18_DD84");
somma30=(somma30+Ts30);
if (i==5){
media30=somma30/6;
stream = fopen(filename,"a");
fprintf(stream,"%s,",GetTagChar("ORA"));
fprintf(stream,"%3.3f,",media30);
fprintf(stream,"%1f\n",GetTagFloat("DB18_DD704"));
fclose(stream);
somma30=0;
media30=0;
}
}
// Report TS31
strcpy(filename,"C:\\Dati\\Trend_TS31_");
sprintf (xx, "%u", GetTagWord("GIORNO"));
strcat(filename,xx);strcat(filename,"_");
sprintf (xx, "%u", GetTagWord("MESE"));
strcat(filename,xx);strcat(filename,"_");
sprintf (xx, "%u", GetTagWord("ANNO"));
strcat(filename,xx);strcat(filename,".csv");
if ((stream = fopen(filename,"r")) ==NULL)
{
stream = fopen(filename,"w");
fprintf(stream,"ORA,");
fprintf(stream,"TS31,");
fprintf(stream,"VVS31\n");
fclose(stream);
}
if (i>=6)
{
i=0;
}
if (i<=5)
{
Ts31=GetTagFloat("DB18_DD88");
somma31=(somma31+Ts31);
if (i==5){
media31=somma31/6;
stream = fopen(filename,"a");
fprintf(stream,"%s,",GetTagChar("ORA"));
fprintf(stream,"%3.3f,",media31);
fprintf(stream,"%1f\n",GetTagFloat("DB18_DD708"));
fclose(stream);
somma31=0;
media31=0;
}
}
// Report TS56
strcpy(filename,"C:\\Dati\\Trend_TS56_");
sprintf (xx, "%u", GetTagWord("GIORNO"));
strcat(filename,xx);strcat(filename,"_");
sprintf (xx, "%u", GetTagWord("MESE"));
strcat(filename,xx);strcat(filename,"_");
sprintf (xx, "%u", GetTagWord("ANNO"));
strcat(filename,xx);strcat(filename,".csv");
if ((stream = fopen(filename,"r")) ==NULL)
{
stream = fopen(filename,"w");
fprintf(stream,"ORA,");
fprintf(stream,"TS56,");
fprintf(stream,"VVS56\n");
fclose(stream);
}
if (i>=6)
{
i=0;
}
if (i<=5)
{
Ts56=GetTagFloat("DB18_DD100");
somma56=(somma56+Ts56);
if (i==5){
media56=somma56/6;
stream = fopen(filename,"a");
fprintf(stream,"%s,",GetTagChar("ORA"));
fprintf(stream,"%3.3f,",media56);
fprintf(stream,"%1f\n",GetTagFloat("DB18_DD712"));
fclose(stream);
somma56=0;
media56=0;
}
}
// Report TS57
strcpy(filename,"C:\\Dati\\Trend_TS57_");
sprintf (xx, "%u", GetTagWord("GIORNO"));
strcat(filename,xx);strcat(filename,"_");
sprintf (xx, "%u", GetTagWord("MESE"));
strcat(filename,xx);strcat(filename,"_");
sprintf (xx, "%u", GetTagWord("ANNO"));
strcat(filename,xx);strcat(filename,".csv");
if ((stream = fopen(filename,"r")) ==NULL)
{
stream = fopen(filename,"w");
fprintf(stream,"ORA,");
fprintf(stream,"TS57,");
fprintf(stream,"VVS57\n");
fclose(stream);
}
if (i>=6)
{
i=0;
}
if (i<=5)
{
Ts57=GetTagFloat("DB18_DD104");
somma57=(somma57+Ts57);
if (i==5){
media57=somma57/6;
stream = fopen(filename,"a");
fprintf(stream,"%s,",GetTagChar("ORA"));
fprintf(stream,"%3.3f,",media57);
fprintf(stream,"%1f\n",GetTagFloat("DB18_DD716"));
fclose(stream);
somma57=0;
media57=0;
}
}
// Report TS58
strcpy(filename,"C:\\Dati\\Trend_TS58_");
sprintf (xx, "%u", GetTagWord("GIORNO"));
strcat(filename,xx);strcat(filename,"_");
sprintf (xx, "%u", GetTagWord("MESE"));
strcat(filename,xx);strcat(filename,"_");
sprintf (xx, "%u", GetTagWord("ANNO"));
strcat(filename,xx);strcat(filename,".csv");
if ((stream = fopen(filename,"r")) ==NULL)
{
stream = fopen(filename,"w");
fprintf(stream,"ORA,");
fprintf(stream,"TS58,");
fprintf(stream,"VVS58\n");
fclose(stream);
}
if (i>=6)
{
i=0;
}
if (i<=5)
{
Ts58=GetTagFloat("DB18_DD108");
somma58=(somma58+Ts58);
if (i==5){
media58=somma58/6;
stream = fopen(filename,"a");
fprintf(stream,"%s,",GetTagChar("ORA"));
fprintf(stream,"%3.3f,",media58);
fprintf(stream,"%1f\n",GetTagFloat("DB18_DD720"));
fclose(stream);
somma58=0;
media58=0;
}
}
// Report TE
strcpy(filename,"C:\\Dati\\Trend_TE_");
sprintf (xx, "%u", GetTagWord("GIORNO"));
strcat(filename,xx);strcat(filename,"_");
sprintf (xx, "%u", GetTagWord("MESE"));
strcat(filename,xx);strcat(filename,"_");
sprintf (xx, "%u", GetTagWord("ANNO"));
strcat(filename,xx);strcat(filename,".csv");
if ((stream = fopen(filename,"r")) ==NULL)
{
stream = fopen(filename,"w");
fprintf(stream,"ORA,");
fprintf(stream,"TE,");
fprintf(stream,"VGV\n");
fclose(stream);
}
if (i>=6)
{
i=0;
}
if (i<=5)
{
Te=GetTagFloat("DB18_DD112");
sommaTe=(sommaTe+Te);
if (i==5){
mediaTe=sommaTe/6;
stream = fopen(filename,"a");
fprintf(stream,"%s,",GetTagChar("ORA"));
fprintf(stream,"%3.3f,",mediaTe);
fprintf(stream,"%1f\n",GetTagFloat("DB18_DD724"));
fclose(stream);
sommaTe=0;
mediaTe=0;
}
}
i++;
return 0;
}