The Origin Forum
File Exchange
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
 LabTalk Forum
 Setting text in a cell...
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

jdf726

78 Posts

Posted - 11/10/2017 :  12:07:36 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): Origin 2016
Operating System: 64 bit Win 7

I am sorry that this is an old question, but I always seem to forget how to do this...

How do you programmatically write text data to a cell?

I always seem to find ways that don't work...

If you define a range
range op = [Summary]Sheet1!2[1];
Then set it equal to a number
op = 2;
Then it works, but if you write
op = "Test"
you just get "--" in the cell.

Using 'cell' notation seems to work
[Summary]Sheet1!cell(1,2) = "test"
but this always looks a bit odd to me... is 'Cell' a function here, stuck to a snippet of range notation?
In fact, why isn't the part that says "[Summary]Sheet1!" handled as a 'string literal' with quotes? ("Summary" is an arbitrary 'name' right?)

To give some context, I am normally grabbing data from many different workbooks in a "doc ef LB{}" loop and want to copy the name of the workbook into each line of the output summary/analysis because the order in which the workbooks is processes is not something I can rely upon. Logging the workbook name in a column means I can always match up the operating conditions of each of the datasets.

I found that this works (j is some loop variable that counts where I am in the loop through workbooks)

Summary!cell(j,1) = %(page.name$);

But I am confused that if I type page.name$= at the command window it tells me the (string) name of the book, but if I ask the script window to report the value "%(page.name$)=" it gives an empty string.
If I leave out the %() part then in the context of a script it doesn't work...


jdf


Chris D

428 Posts

Posted - 11/10/2017 :  12:56:31 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

The way to write text to cells in a worksheet is to define a range to a column. Then assign the string using the row number "index" for the range. E.g.:

range op = [Summary]Sheet1!2;
op[1]$="Test";


Notice the addition of $. That is required when assigning text.

Cell() is a function but is a bit deprecated. See: https://www.originlab.com/doc/LabTalk/ref/Cell-func

For me,

page.name$=;

outputs the active window (book, graph, etc) short name in both the Command and Script Window.


Thanks,
Chris Drozdowski
Originlab Technical Support
Go to Top of Page

jdf726

78 Posts

Posted - 11/10/2017 :  2:55:45 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Ahhhh...Many thanks!

Other attempts failed because I was declaring my range to be a cell using
range op = [Summary]Sheet1!1[1:1]
Then op = 1 (a number) works, but text does not.
Even if you use the trailing dollar (op$ = "test") it doesn't work.

Even had I declared the range at the column level, I would not have thought to include the dollar on the left hand side ('transforming'/'casting'/'converting'/'substituting' on the right hand side I can get, but not on the left hand side...).

The way I got it to work with 'Cell' is weird, because if you set
Summary!cell(j,1) = %(page.name$);

works, but

Summary!cell(j,1) = page.name$;

puts the string literal "page.name$" into the cell! (i.e. without evaluating the variable).

I seem to have explored all the ways of it NOT working! (but in several ways that work with numbers)


jdf




quote:
Originally posted by Chris D

Hi,

The way to write text to cells in a worksheet is to define a range to a column. Then assign the string using the row number "index" for the range. E.g.:

range op = [Summary]Sheet1!2;
op[1]$="Test";


Notice the addition of $. That is required when assigning text.

Cell() is a function but is a bit deprecated. See: https://www.originlab.com/doc/LabTalk/ref/Cell-func

For me,

page.name$=;

outputs the active window (book, graph, etc) short name in both the Command and Script Window.


Thanks,
Chris Drozdowski
Originlab Technical Support


Go to Top of Page

Hideo Fujii

USA
1582 Posts

Posted - 12/13/2017 :  09:52:24 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi jdf,

> Summary!cell(j,1) = page.name$; puts the string literal "page.name$" into the cell

Have you tried: Summary!cell(j,1)$ = page.name$; ?
This way should match the data types at both left and right-hand sides.

--Hideo Fujii
OriginLab

Edited by - Hideo Fujii on 12/13/2017 09:56:00 AM
Go to Top of Page

ajgor74

Italy
3 Posts

Posted - 08/26/2021 :  04:51:32 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi
I've read many threads but I didn't find any working solution to my problem, similar to this one.
I have a column (A) with observation/sample names (so text) and column (B) with results of an experiment associated to each sample (so numbers); now I want to copy the labels from the observation names (A) to another columns (C) ONLY for certain results with a simple formula:
on column (C) I set B == 1 ? A : " na"
but it doesn't work with text, while if column (A) contains numbers insterad of text, it works.
What's wrong? and how could I solve it?
tk
Go to Top of Page

YimingChen

820 Posts

Posted - 08/26/2021 :  09:06:35 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
What version of Origin do you have? It works for me in 2021b.

James
Go to Top of Page

ajgor74

Italy
3 Posts

Posted - 08/26/2021 :  09:22:49 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I'm using b9.5.1 (2018)
quote:
Originally posted by YimingChen

What version of Origin do you have? It works for me in 2021b.

James

Go to Top of Page

YimingChen

820 Posts

Posted - 08/26/2021 :  2:26:39 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Try this:
B == 1 ? A$ : " na"


James
Go to Top of Page

ajgor74

Italy
3 Posts

Posted - 08/30/2021 :  06:46:03 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by YimingChen

Try this:
B == 1 ? A$ : " na"


James


I knew I had to put "$" somewhere, now it works!
thank you
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