Sending Values from SAM to excel

  • hys05
  • Topic Author
More
31 Oct 2016 00:58 #4876 by hys05
Sending Values from SAM to excel was created by hys05
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();

Please Log in or Create an account to join the conversation.

  • hys05
  • Topic Author
More
31 Oct 2016 01:01 #4877 by hys05
Replied by hys05 on topic Sending Values from SAM to excel
I need some help with this please

Please Log in or Create an account to join the conversation.

  • pgilman
More
31 Oct 2016 15:25 #4878 by pgilman
Replied by pgilman on topic Sending Values from SAM to excel
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.

Please Log in or Create an account to join the conversation.

Moderators: pgilman
Powered by Kunena Forum