DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Excel worksheet add after syntax

Hi,

 

I often save TDM files in Excel format and usually just include the channel name and unit. However, since I usually have multiple groups, I then have to manually insert the group name into the Excel file so that the customers can understand which groups the channels belong to.

I assume it might be possible to automate this using a script to save to Excel whilst inserting the group name into row 1, followed by the channel name in row 2 and the unit in row 3, as normal.

Can anyone guide me as to how I might go about this?

Thanks.

 

0 Kudos
Message 1 of 6
(3,050 Views)

Hi,

when opening a TDM file with the Excel Importer, channels are separated by group.

http://www.ni.com/example/27944/en/

Description: "Each group in the TDM/TDMS file is loaded onto a separate Excel Worksheet"

After importing it in Excel you can save it in Excel file format.

Regards

 

Christian
CLA, CTA, CLED
0 Kudos
Message 2 of 6
(2,981 Views)

Thanks, I will review this.

However, I was intending to have all the channels on the same sheet, with the group name in row 1. Is that possible?

Regards,

Simon.

0 Kudos
Message 3 of 6
(2,977 Views)

As far as I know there is no way to tell the Excel Importer to put all channels from different groups in one worksheet.

 

Here are some alternatives that I know:

- post process your data with a VBA macro

- if there is no Excel installed on the computer that must create the Excel file, you can use the FileSystemObject to write a text (csv) file with your structure and change the file extension to .xls. When opening it in Excel it should be interpreted automatically.

http://zone.ni.com/reference/de-XX/help/370858M-0113/scripting/objects/scripting_objects_ifilesystem...

- if there is Excel installed you can use the Excel COM interface in DIAdem to build an excel file with your structure. Here's an example that writes all channels from data portal to excel in one worksheet including group name:

 

dim i,j,oExcel,oWS,oChn
set oExcel = CreateObject("Excel.Application")
call oExcel.Workbooks.Add()
set oWS = oExcel.ActiveSheet
for i=1 to ChnNoMax
    set oChn = Data.GetChannel(i)
    oWS.Cells(1,i).Value = oChn.Name
    oWS.Cells(2,i).Value = oChn.UnitSymbol
    oWS.Cells(3,i).Value = oChn.Properties("groupname").Value
    'the following loop can take very long time depending on the channel size!!!
    for j=1 to oChn.Size
        oWS.Cells(j+3,i).Value = oChn(j)
    next
next
call oExcel.ActiveWorkbook.SaveAs(CurrentScriptPath & "Data in Excel")
call oExcel.Quit()
set oExcel = nothing

 

Be careful as this can take very long time for very long channels.

 

Regards

Christian
CLA, CTA, CLED
0 Kudos
Message 4 of 6
(2,974 Views)

This is much faster and should do the job 😉

 

dim i,j,oExcel,oWS,oChn
set oExcel = CreateObject("Excel.Application")
call oExcel.Workbooks.Add()
set oWS = oExcel.ActiveSheet
for i=1 to ChnNoMax
    set oChn = Data.GetChannel(i)
    oWS.Cells(1,i).Value = oChn.Name
    oWS.Cells(2,i).Value = oChn.UnitSymbol
    oWS.Cells(3,i).Value = oChn.Properties("groupname").Value
    oWS.Range(oWS.Cells(4,i), oWS.Cells(3+oChn.Size,i)) = oExcel.Transpose(oChn.GetValuesBlock(1,oChn.Size,eValueBlockSafeArray))
next
call oExcel.ActiveWorkbook.SaveAs(CurrentScriptPath & "Data in Excel")
call oExcel.Quit()
set oExcel = nothing

Christian
CLA, CTA, CLED
0 Kudos
Message 5 of 6
(2,955 Views)

Thanks Christian. I'll check it out.

Regards.

0 Kudos
Message 6 of 6
(2,953 Views)