The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Automation Server/COM and LabVIEW
 Access WorksheetPage, Worksheet or Column by name
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

newuser_ca

70 Posts

Posted - 06/26/2012 :  11:13:10 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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.

Penn

China
644 Posts

Posted - 06/27/2012 :  11:35:04 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

You can try:

WorksheetPage wbk = m_originApp.WorksheetPages["Book1"];
Worksheet wks = m_originApp.FindWorksheet("[Book1]Sheet1!");
Column col = wks.Columns["B"];


Penn
Go to Top of Page

newuser_ca

70 Posts

Posted - 06/28/2012 :  1:41:02 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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!
Go to Top of Page

Penn

China
644 Posts

Posted - 06/28/2012 :  10:09:14 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

newuser_ca

70 Posts

Posted - 06/29/2012 :  11:11:12 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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.

Edited by - newuser_ca on 06/29/2012 11:43:55 AM
Go to Top of Page

Penn

China
644 Posts

Posted - 07/02/2012 :  05:31:06 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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

Edited by - Penn on 07/02/2012 05:32:17 AM
Go to Top of Page

newuser_ca

70 Posts

Posted - 07/03/2012 :  11:14:00 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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.

Edited by - newuser_ca on 07/03/2012 1:49:48 PM
Go to Top of Page

Penn

China
644 Posts

Posted - 07/03/2012 :  9:37:48 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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

Edited by - Penn on 07/03/2012 11:39:40 PM
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000