将数据从Intouch导出到Excel

时间:2018-01-18 10:43:43

标签: sql-server excel vb.net excel-vba wonderware vba

我正在使用Intouch R2 SP1编写SCADA。在这个SCADA中,我必须在excel中做一些报告。该报告只是将10个值写入特定单元格。问题是我正在使用的代码正在使用Office 2010,这是我在计算机中的版本,但是当我在新计算机中安装SCADA时,我们购买了Office 2016的许可证。当我尝试生成用这台计算机报告,除了写入单元格外,它使一切正常。

所以我的问题是这样的:有没有人知道如何使用Intouch Archestra Graphics的vb.net将这些数据导出到excel电子表格?如果没有,是否可以使用SQL查询将数据从SQL Server导出到Excel?

我正在使用的代码如下,在这里您可以看到我正在将excel文件复制到新位置,更改其名称并打开新的Excel文件。之后,我使用函数WWPoke()将所需的值插入Excel。

dim sourceDir as string;
dim destDir as string;
dim fileName as string;
dim destName as string;
dim sourceFile as string;
dim destFile as string;
dim modo as System.IO.FileMode;
dim fechaini as string;

sourceDir = "C:\MIGRA\SCADA\Acesur_Cogeneracion";
destDir = "C:\InformesAcesur";
fileName = "Informe.xls";
destName = InTouch:$Day + "" + InTouch:$Month + "" + InTouch:$Year + "_" +                     
InTouch:$Hour+ "" + InTouch:$Minute + ".xls";
sourceFile = System.IO.Path.Combine(sourceDir,fileName);
destFile = destDir + "\" + destName;

'I copy the original file to the new location
System.IO.File.Copy(sourceFile,destFile,true);

'I open the copied file
System.Diagnostics.Process.Start("excel.exe",destFile);


'I send the data to excel - THIS IS THE PART THAT'S NOT WORKING
WWPoke( "excel.exe", "Hoja1", "F10C4", FechaInicio);
WWPoke( "excel.exe", "Hoja1", "F11C4", FechaFin);
WWPoke( "excel.exe", "Hoja1", "F20C4", StringFromReal(E,2,"f"));
WWPoke( "excel.exe", "Hoja1", "F21C4", StringFromReal(Q,2,"f"));
WWPoke( "excel.exe", "Hoja1", "F22C4", StringFromReal(V,2,"f"));
WWPoke( "excel.exe", "Hoja1", "F28C4", StringFromReal(REE,2,"f"));
WWPoke( "excel.exe", "Hoja1", "F34C4", StringFromReal(FT001,2,"f"));
WWPoke( "excel.exe", "Hoja1", "F35C4", StringFromReal(FT002,2,"f"));
WWPoke( "excel.exe", "Hoja1", "F36C4", StringFromReal(FT003,2,"f"));
WWPoke( "excel.exe", "Hoja1", "F37C4", StringFromReal(FT004,2,"f"));

谢谢!

1 个答案:

答案 0 :(得分:0)

问题是函数WWPoke()与64位操作系统不兼容,它与Office的版本无关。所以我所做的就是创建.csv文件并使用excel宏将数据导入报告。