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
 All Forums
 Origin Forum for Programming
 Forum for Automation Server/COM and LabVIEW
 Access WorksheetPage, Worksheet or Column by name

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

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

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000