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 Class MainClass
Public Tag_1 as string
Public Tag_2 as string
PublicSub Load
Dim oldCulture As System.Globalization.CultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture
Try
Dim cultur_str As String = CultureInfo.CurrentCulture.IetfLanguageTag
Dim Exx As New Microsoft.Office.Interop.Excel.Application
Dim newCulture As New System.Globalization.CultureInfo(Exx.Application.LanguageSettings.LanguageID(Microsoft.Office.Core.MsoAppLanguageID.msoLanguageIDUI))
System.Threading.Thread.CurrentThread.CurrentCulture = newCulture
Dim Exl As Microsoft.Office.Interop.Excel.Application
Exl = New Microsoft.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()
Catch ex As Exception
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