Scada Excel İletişimi
Bir çok uygulamada Scada’dan excel’e veri okumak veya yazmak isteririz. WinTr scada script fonksiyonu ile bunu yapabiliriz. Excel versiyonuna bağlı olarak yazacağımız script farklı olabilir. Aşağıda paylaştığım script tüm Excel versiyonları ile çalışır.
Imports System
Imports System.IO
Imports System.Windows.Forms
Imports Microsoft.VisualBasic
Imports System.Globalization
Namespace WinTr
Public ClassMainClass
PublicTag_1 as string
PublicTag_2 as string
PublicSubLoad
DimoldCulture AsSystem.Globalization.CultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture
Try
Dimcultur_str As String= CultureInfo.CurrentCulture.IetfLanguageTag
DimExx As NewMicrosoft.Office.Interop.Excel.Application
DimnewCulture As NewSystem.Globalization.CultureInfo(Exx.Application.LanguageSettings.LanguageID(Microsoft.Office.Core.MsoAppLanguageID.msoLanguageIDUI))
System.Threading.Thread.CurrentThread.CurrentCulture = newCulture
DimExl AsMicrosoft.Office.Interop.Excel.Application
Exl = NewMicrosoft.Office.Interop.Excel.Application
Exl.Visible = True
Exl.Workbooks.Open("C:\Book1.xlsx")
Tag_1 = Exl.Worksheets(1).cells(1, 1).value
Tag_2 = Exl.Worksheets(1).cells(2, 1).value
Exl.Quit()
Catchex AsException
MessageBox.Show(Ex.ToString,Ex.Message)
EndTry
System.Threading.Thread.CurrentThread.CurrentCulture = oldCulture
End Sub
End Class
End Namespace
Veri yazmak için aşağıdaki kodu kullanabilirsiniz.
Exl.Worksheets(1).cells(1, 1).value = Tag_1
