The Origin Forum
File Exchange
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Setting text in a cell...

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
jdf726 Posted - 11/10/2017 : 12:07:36 PM
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


8   L A T E S T    R E P L I E S    (Newest First)
ajgor74 Posted - 08/30/2021 : 06:46:03 AM
quote:
Originally posted by YimingChen

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


James


I knew I had to put "$" somewhere, now it works!
thank you
YimingChen Posted - 08/26/2021 : 2:26:39 PM
Try this:
B == 1 ? A$ : " na"


James
ajgor74 Posted - 08/26/2021 : 09:22:49 AM
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

YimingChen Posted - 08/26/2021 : 09:06:35 AM
What version of Origin do you have? It works for me in 2021b.

James
ajgor74 Posted - 08/26/2021 : 04:51:32 AM
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
Hideo Fujii Posted - 12/13/2017 : 09:52:24 AM
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
jdf726 Posted - 11/10/2017 : 2:55:45 PM
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


Chris D Posted - 11/10/2017 : 12:56:31 PM
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

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