01-22-2019 08:07 AM
Is it possible to use the ChannelsToArray function and export that matrix to Excel?
Solved! Go to Solution.
01-22-2019 10:17 AM - edited 01-22-2019 10:18 AM
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
01-23-2019 03:28 AM
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.
01-23-2019 12:05 PM
Is there way to keep all the groups in the same excel file, just in different tabs?
02-19-2019 03:56 PM
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