T O P I C R E V I E W |
newuser_ca |
Posted - 06/26/2012 : 11:13:10 AM OriginPro 8.6 in win7.
How to Access WorksheetPage, Worksheet or Column by name instead of index in C#?
by index: WorksheetPage wbk = m_originApp.WorksheetPages[0] as WorksheetPage; Worksheet wks = wbk.Layers[0] as Worksheet; Column colTlm = wks.Columns[0] as Column;
The help file says to use "FindWorksheet" function to get worksheet by name: Worksheet wks = m_originApp.FindWorksheet(selectedWords); WorksheetPage wbk = (WorksheetPage)wks.Parent;
How about WorksheetPage and Column? thanks. |
7 L A T E S T R E P L I E S (Newest First) |
Penn |
Posted - 07/03/2012 : 9:37:48 PM Hi,
There is no direct way to pass an array into Origin C either. You can do the same way as getting array from Origin C. Firstly, define an array variable, and then set string to the array one by one. For example:
m_originApp.Execute("StringArray sa;"); // define a LabTalk string array
for(int i=0; i<size; i++)
{
string str = "sa.Add(" + strarr[i] + ");"; // add string to array command
m_originApp.Execute(str); // add one string to string array
}
Penn |
newuser_ca |
Posted - 07/03/2012 : 11:14:00 AM It worked now.
Thanks a lot!
Here is a related question. Is it able to pass a C# array into Origin? I know how to pass a string into Origin C in C#. If there is a way to pass an array, that will be nice. |
Penn |
Posted - 07/02/2012 : 05:31:06 AM Hi,
If you want to use get_LTStr, please make sure that the return value ltID is a LabTalk string value.
For the StringArray issue, there is no way to get it directly currently. You can try the following way:
string strCMD1 = "StringArray sa = getTimeArray(); size = sa.GetSize();"; // LT command to return the stringarray to a LT stringarray variable, and get this array size
m_originApp.Execute(strCMD1); // execute the LT command
int size = Int32.Parse(m_originApp.get_LTVar("size").ToString()); // get size to C#
// put the string to C# string array
string[] strarr = new string[size];
for(int i = 1; i <= size; i++)
{
string strCMD2 = "string str$ = sa.GetAt(" + i.ToString() + ")$;"; // LT command to get the ith string
m_originApp.Execute(strCMD2);
strarr[i-1] = app.get_LTStr("str$"); // here use the get_LTStr() method
}
Penn |
newuser_ca |
Posted - 06/29/2012 : 11:11:12 AM Hi Penn,
That is very helpful.
I tried function get_LTStr, but it is not working. What is missing? m_originApp.Execute("ltID = getID();"); string str = m_originApp.get_LTStr("ltID");
How about StringArray? I have an OriginC function getTimeArray() which returns a StringArray. How can I get it in C#?
Thanks. |
Penn |
Posted - 06/28/2012 : 10:09:14 PM Hi,
Do you mean that you want to get the return value from Origin C function and then use this return value in C# program? If so, please try something like:
m_originApp.Execute("ltVar = getSum(3, 4);");
string str = m_originApp.get_LTVar("ltVar").ToString();
Penn |
newuser_ca |
Posted - 06/28/2012 : 1:41:02 PM Hi Penn,
It worked very well. thanks!
By the way, how can I get the return value from Origin C function? For example, I have Origin C function called getSum(int a, int b). Here is how I did: 1. In C#, call getSum() function, get the value and write to a worksheet 2. In C#, access to this worksheet and get the value from the cell. Is there a direct way to get it?
Thanks! |
Penn |
Posted - 06/27/2012 : 11:35:04 PM Hi,
You can try:
WorksheetPage wbk = m_originApp.WorksheetPages["Book1"];
Worksheet wks = m_originApp.FindWorksheet("[Book1]Sheet1!");
Column col = wks.Columns["B"];
Penn |