Sending Values from SAM to excel

3 posts / 0 new
Last post
hys05
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
active_case('Fres');

//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');
outln(d);

T_out = get('T_htf_hot_ref');

xl_set(xl,T_out,'A1');

//close the Excel file and free the Excel object
xl_close(xl);
xl_free(xl);

//display results of script
msg="";
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);
outln();

hys05

I need some help with this please

Paul Gilman

Hello,

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');
outln(test);

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,
Paul.

Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer