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
 LabTalk Forum
 copy cells between workbooks
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

OndrejMM

Australia
81 Posts

Posted - 01/27/2009 :  06:32:43 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi Guys,

can you please help me with the following script,... I have a workbook “book1”with many worksheets, where every worksheet contains 10 columns and 20 rows and I would need to do the following:

1.find every 4th cell from every worksheet of the workbook “book1”,..
2.then, copy these values to workbook “book2”, in the way that the values coming from one worksheet of the workbook “book1” will be in a new column of book2

I did the following but it is a bit messy and doesn’t work,...


win -a book1; //activate bookwork “book1”

for (ii=1; ii<=page.nLayers; ii++) //loop over all layers (worksheets)
{
page.active = ii; //make the worksheet active

for (ii=1; ii<=wks.maxRows; ii+4) //run loop over all rows and pick every 4th cell
{
cc=1;
%w=cell(ii, 1);
// copy cell values to the first column of book2
book2!cell(cc, 1)$ = book1!cell(ii, 1)$;
cc++;
};
};

Many Thanks
Ondrej

snowli

USA
1426 Posts

Posted - 01/27/2009 :  2:30:22 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Ondrej,

We have range notation in 8.0 and we support more xfunctions to manipulate the data.

You can check Help: X-Functions and Programing: LabTalk for more information.
You can also choose Tools: X-Function Script Samples to learn from examples we provided.
There are more help on our wiki page http://wiki.originlab.com/~originla/wiki/index.php?title=Category:LabTalk


Here are the script I wrote. It extract every 4th row in each sheet and put them to coresponding column in book2.

win -a book1;
nsheet=page.nlayers;
for (ii=1; ii<=nsheet; ii++)
{
range rsheet=$(ii)!; //define a range variable which points to ii-th sheet of Book1
wxt iw:=rsheet test:="mod(i,4)==1" ow:=[output]; //this xfunction extracts every fourth row of ii-th sheet and put results into an ouput book
ncol=wks.ncols; nrow=wks.nrows; //get row and column numbers of the output book
wtranspose; //transpose the worksheet
wks.ncols=nrow; //set the number of columns correctly becuase after transpose, some extract colum/rows are created
wks.nrows=ncol; //same as above line
range r1=1; //define range variable r1 to be first column of the output book
range r2=[book2]1!$(ii); //defined r2 to be the ii-th column on sheet1 of Book2
copydata r1 r2; //copy r1 to r2
loop(jj,2,wks.ncols) // this loop will copy 2nd to end columns of output sheet to append to ii-th column in book2
{
range r1=$(jj);
copydata r1 [book2]1!$(ii)[$(10*(jj-1)+1)] ;
jj++;
}
win -c; //delete the output book
}

Thanks, Snow Li
OriginLab Corp.

Edited by - snowli on 01/27/2009 2:30:52 PM
Go to Top of Page

OndrejMM

Australia
81 Posts

Posted - 01/27/2009 :  6:13:21 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Snow Li,
thanks a lot, works great,...
Ondrej
Go to Top of Page

thiago.maf

22 Posts

Posted - 06/14/2009 :  6:35:34 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Following these suggestions I've this problem:

When I try this in a OGS section, it doesn't work. But if I insert then, line per line, in the prompt it work fine... anyone know why?

range r_aa = [Book1]1!1 ;
range r_bb = [Book2]1!1 ;
copy r_aa r_bb ;
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 06/14/2009 :  9:14:15 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
SnowLi was using copydata, while your code was copy.

the copy command should also work in the way to wrote, but the copyData XF allows the range notation to be used without definning the range variables as it is an X-F.

CP
Go to Top of Page

thiago.maf

22 Posts

Posted - 06/14/2009 :  10:40:42 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I don't know why but when I take out tree instances of "page" object that was above those lines it work fine. I just put these tres objects after my "range" and "copy" lines.
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