Sending Values from SAM to excel

3 posts / 0 new
Last post
Sending Values from SAM to excel

I want to send a calculated value from SAM to an excel-workbook using an lk script, I'm running the script with no errors but nothing is changing in the excel workbook Book100, I tried the same script also for different workbooks and also it's not working. Can someone please help me with that. Thank you

The Script:

/set the current SAM case

//create an Excel object and open the Excel file
xl = xl_create('C:/Users/Admin/Desktop/SAM work/Book100.xls.xlsm');
path = path_only( project_file() );

d = dir_list(path,'/Book100.xls.xlsm');

T_out = get('T_htf_hot_ref');


//close the Excel file and free the Excel object

//display results of script
ok = simulate(msg,1);
if (ok==true) outln("Simulation complete with values from Excel. See results in the " + active_case() + " case.");
else outln("Simulation failed with the following messages:\n",msg);


I need some help with this please

Paul Gilman


When you use LK to interact with Excel using Excel Automation, remember that SAM works with a copy of the Excel file in machine memory. It does not save the Excel file with your data, so it does not modify the Excel file. You can test this as follows. In your Book100.xlsm file, put the formula "=A1*2" in Cell A2, and then after you call the xl_set() function in your script, add the lines

test = xl_get(xl,'A2');

You should see that the value of test is two times the T_out value.

If you want to export data from SAM to Excel using LK, you can use the csvwrite() function to create a CSV file and then open the CSV file in Excel.

Best regards,

Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer