NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

How to save .xls file using TestStand at a predefined location

Solved!
Go to solution

Hello,

 

I wanted to write a test case using TestStand without using LabVIEW VIs. My requirements are -

1. Through TestStand, read "RLOC" and "Voltage" column/information from some Input.xls template file and create respective local array variables accordingly within the Teststand sequence file.

2. Launch a new worksheet which will gather the test results by using the local array variables (created in step 1) as input. Pass/Fail criteria will be implemented based on the values read from the engine ECM.

3. Lets call the new worksheet as "Results.xls" and it should get saved at a pre-defined location.

 

Out of above mentioned points, I am able to implement point # 2, but I am still not able to figure out "how can I Read the value from Input.xls template file", and "how can I save the Results.xls file at a predefined path".

 

Please have a look at the attached sequence. I have currently hard coded Locals.RLOC[] and Locals.[x][0], but eventually I want this info to get populated from Input.xls file.

Also, at step 12/14, I am trying to use the step "Save Excel", but I don't think its the correct step. It is asking for Filename (Optional) as input, and even though I have mentioned "Results.xls", while saving the file its getting saved by name as Book1.xla, Book2.xls.

Can you please suggest any step wherein I can mention the path where the file will get saved with the name Results.xls?

 

I am using TestStand 2010.

 

Thanks and Regards,

Niraj.

 

0 Kudos
Message 1 of 10
(5,213 Views)

Hi,

 

Try doing this instead. Locals.Local is just a path variable that has the path to where I want to save the file.

 

save excel.PNG

Rohama K.
0 Kudos
Message 2 of 10
(5,191 Views)

Thanks for replying back.

 

Method I:

I am using Locals.Results_Filename and and getting the path of file where I want to save the report. I am using this Local variable as an input to "SaveAs" step, to send the Filename (optional) value.

In this case, the value stored in the Locals.Results_Filename is "D:\\Niraj\\temp_123\\Loopback_Test_123_6-11-2012_1_42_.xlsx", but I am getting following run time error.

 

Error, An error occurred calling 'SaveAs' in '_Workbook' of 'Microsoft Excel 12.0 Object Library' The file could not be accessed. Try one of the following: • Make sure the specified folder exists. • Make sure the folder that contains the file is not read-only. • Make sure the file name does not contain any of the following characters: < > ? [ ] : | or * • Make sure the file/path name doesn't contain more than 218 characters. Source: Microsoft Office Excel [Error Code: -2146827284, User-defined error code.]

 

Error.JPG

 

 

Method II:

But, if I replace the Locals.Results_Filename and instead directly use "D:\\Niraj\\temp_123\\Loopback_Test_123_6-11-2012_1_42_.xlsx", then the same SaveAs step works fine without giving Run Time Error, and my test report is getting saved properly.

 

Error.JPG

 

But, since I can not keep the Filename as fixed, instead I want some way where I can use the Locals.Results_Filename to define the file location.

Logically both Method I and Method II are the same, but I am not able to understand why it is giving run time error for MEthod I.

 

Thanks and Regards,

Niraj.

0 Kudos
Message 3 of 10
(5,185 Views)
Solution
Accepted by topic author Niraj2810

What happens when you replace the \\ with a \ in the variable (Locals.Results_Filename)?  Does it still error?

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
0 Kudos
Message 4 of 10
(5,176 Views)

It works and now I am more concerned about when to use "\" and when to use "\\". I remember I used to have issues when using "\" in the variable while using it to store the file path. Anyways, I will remove the step where I was converting each "\" and replacing it with "\\".

 

That solves my one of the issues. Thanks for that.

 

One issue which still is open is, can you tell me how can I read the value from xls file using ActiveX commands? Please refer my first post in this thread.

I have currently hard coded Locals.RLOC[] and Locals.[x][0], but eventually I want this info to get populated from Input.xls file.

Please suggest some way to fetch the info from .xlsx file and use it in TestStand using ActiveX command.

 

Thanks and Regards,

Niraj.

0 Kudos
Message 5 of 10
(5,171 Views)

Did you see this? http://sine.ni.com/devzone/cda/epd/p/id/765

 

I haven't looked in it so I don't know what it's doing.

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
0 Kudos
Message 6 of 10
(5,166 Views)

I have already checked that example, and it is using copying excel columns to TestStand using Labview VIs.

My intension here is, to perform excel operations using TestStand only. For this task, I am not suppose to use the LabVIEW VIs.

 

Thanks and Regards,

Niraj.

0 Kudos
Message 7 of 10
(5,162 Views)

So no VIs huh?  OK.

 

Do you have to use ActiveX?  Can you use the .NET interface with the .NET adapter?

 

Either way it looks like there isn't a direct example available in TestStand for this.  So usually here is how I would proceed in this situation:

 

Find the API for excel.  Just type Excel API in msdn.com for the search and it should come up.

Once I familiarize myself with the Excel object model and understand (containment and inheritance for it) then I usually search for an example in C#, LabVIEW or VB.NET.

After I find an example that is close I just translate it into TestStand using activeX steps or the .NET steps.

 

 

What version/s of TestStand are you using (sorry if you mentioned this previously I must have missed it)?

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
0 Kudos
Message 8 of 10
(5,157 Views)

I think I should be able to use either ActiveX or .NET steps, but since I have already done "Write into excel" operation using ActiveX commands I will prefer to continue with ActiveX commands.

And, I am using TestStand 2010.

 

 

Thanks and Regards,

Niraj.

0 Kudos
Message 9 of 10
(5,153 Views)

Not sure if you guys work together but he just posted an example: http://forums.ni.com/t5/NI-TestStand/excel-doesn-t-close/td-p/2025168

 

Good luck.

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
0 Kudos
Message 10 of 10
(5,140 Views)