DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

ChannelsToArray send to Excel

Solved!
Go to solution

Is it possible to use the ChannelsToArray function and export that matrix to Excel?

0 Kudos
Message 1 of 5
(2,565 Views)

ChannelsToArray returns a "type-safe array".  Essentially that means that you can't do anything with it in code, just send it to other applications that accepts those.  I would just read all data into arrays that you create (or multidimensional array) and then write each value in the appropriate cell.  I tried using ChannelsToArray function myself and did not find much use for it so far.  Here is some example code to get you started if you don't have anything yet (it just writes a column into an existing Excel file):

Option Explicit  'Forces the explicit declaration of all the variables in a script.

' OPEN
DIM FSO, filePath, Excel
filePath = "C:\Users\myUser\Desktop\example.xlsx"
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Excel = CreateObject("Excel.Application")
Excel.Visible = TRUE
Call Excel.Workbooks.Open(filePath) 

' WRITE
Dim Arr, i, columnLetter
columnLetter = "A"
Arr = Array(1,2,3,4,5,6)
For i = 0 To UBound(Arr, 1) Step 1
  Excel.ActiveSheet.Range(columnLetter & (i + 1)).Value = Arr(i)
Next

' SAVE
Call Excel.ActiveSheet.Parent.Save()

' CLOSE
Excel.DisplayAlerts = False
Excel.Quit
Set Excel = Nothing
Message 2 of 5
(2,548 Views)
Solution
Accepted by topic author BrianCT

Since DIAdem 2018 there is also a simple Excel Export

Option Explicit
Call DataFileSaveSel("C:\temp\EXAMPLE.xlsx","ExcelTdmExport","'[1]/Time' - '[1]/Torque'")

It will also create a sheet including the property values and one per group.

Message 3 of 5
(2,531 Views)

Is there way to keep all the groups in the same excel file, just in different tabs?

0 Kudos
Message 4 of 5
(2,515 Views)

Hi Brian,

 

That is the default behavior when you save all groups in the Data Portal to an Excel file with that DataPlugin:

 

Call DataFileSave("C:\Users\bradt\Desktop\EXAMPLE.xlsx", "ExcelTdmExport")

 

If you want each group on a different tab, but you only want to export some of the groups, you can do that by providing the selected groups in that third parameter and keep using the DataFileSaveSel() command:

 

Set SelGroups = Data.CreateElementList()
Call SelGroups.Add(Data.Root.ChannelGroups(1))
Call SelGroups.Add(Data.Root.ChannelGroups(3))
Call DataFileSaveSel("C:\Users\bradt\Desktop\EXAMPLE.xlsx", "ExcelTdmExport", SelGroups)

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 5 of 5
(2,385 Views)