DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Add kanal in Excel

I have a file with many groups. in each group there is a time channel. I only want to import a time channel from Groupe, in which there is a channel named Eng_Spd, into Excel. Can someone help me, how should I write the code. Below is my code

 

Dim oExcel,oWBook,oSheet,K,L,oGroup,lCol,oChn,DisplayType,Sfile
Set oExcel = CreateObject("Excel.Application") ' Excel öffnen
oExcel.Visible = True
Call oExcel.Workbooks.Open("N:\01_IMO-Light\Test\DIAdem-Test.xlsx")
Set oWBook = oExcel.Activeworkbook

If ( 1 < oWBook.Sheets.Count ) Then ' wir wollen nur eine Sheet !
For K = 1 To oWBook.Sheets.Count-1
Call oWBook.Sheets(1).Delete
Next
End If
Set oSheet = oWBook.Sheets(1)
oSheet.Name = "DIAdem_Export"
lCol = 1
For K = 1 To Data.Root.ChannelGroups.Count 'KanalGruppen werden gezählt.
Set oGroup = Data.Root.ChannelGroups(K) 'oGroup ist die KanalGruppe
For L = 1 To oGroup.Channels.Count
Set oChn = oGroup.Channels(L) 'oChn ist die Nummer von Kanälen

if oChn.Name = "time" or oChn.Name = "Eng_Spd" or oChn.Name = "Eng_Trq" or oChn.Name = "Eng_Trq_indicated" or oChn.Name = "InjCrv_qSetUnBal" or oChn.Name ="Veh_Spd" then
oSheet.Cells(1,lCol) = oChn.Name 'Die bestimmten Messdaten in Excel übernehmen
oSheet.Cells(2,lCol) = oGroup.Name
oSheet.Cells(3,lCol) = oChn.Properties("unit_string").Value
Call ChannelToExcelColumnBlk(oChn,oExcel,oSheet,lCol,4) '
lCol = lCol + 1
Else
End if
Next
Next

 

 

'-------------------------------------------------------------------------------
' ChannelToExcelColumnBlk
'-------------------------------------------------------------------------------
Function ChannelToExcelColumnBlk(oChn,oExcel,oSheet,ColNo,StartRow)
Dim lExcelLength,oRange,vChnData,K
Dim fFlag : fFlag = NULL
' Switch off screen updating if necessary
If ( oExcel.ScreenUpdating ) Then
oExcel.ScreenUpdating = False
fFlag = True
End If
'-------------------------------------------------
' Limit number of values per column to Excel's
' limit
'-------------------------------------------------
lExcelLength = MinV(oChn.Size,oSheet.Rows.Count-StartRow+1)
' On Error Resume Next
Set oRange = oSheet.range(oSheet.Cells(StartRow,ColNo),oSheet.Cells(StartRow+lExcelLength-1,ColNo))
oRange.Value = ChnToValue(oChn,"TransposedMatrix")
On Error Resume Next
Call oExcel.ActiveWorkbook.Names.Add(Replace(oChn.Name," ","_"),oRange)
On Error Goto 0
'-------------------------------------------------
' NoValue Handling for Excel
' NoValues are replaced with empty cells.
'-------------------------------------------------
If ( "Yes" = oChn.Properties("novaluekey").Value ) Then
For K = 1 to oChn.Size
If ( IsNull(oChn(K)) ) Then
oSheet.Cells(StartRow+K-1,ColNo) = NULL
End If
Next
End If

If ( "time" = LCase(oChn.Properties("displaytype").Value) ) Then oRange.NumberFormat = "DD.MM.YYYY hh:mms"
If ( "text" = LCase(oChn.Properties("displaytype").Value) ) Then oRange.EntireColumn.AutoFit
On Error Goto 0
' If screen updating was switched off, switch it back
If ( Not IsNull(fFlag) ) Then oExcel.ScreenUpdating = True
End Function

0 Kudos
Message 1 of 3
(148 Views)

Hi FazelSCH,

 

I don't really understand your question, do you have any error when you run your script?

 

Have a nice day!

 

Clement

0 Kudos
Message 2 of 3
(97 Views)

Thank you ,I did solve das Problem

0 Kudos
Message 3 of 3
(95 Views)