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
 columns order
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Stefan B

Germany
10 Posts

Posted - 11/21/2016 :  5:33:57 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi,

I want to sort the columns in my worsheet.

For example, i have colums A B C D. I want column D to become column A , column C to become B etc. In the other worlds, i want to revert the current order of coulumns. I tried to find some function is User Guide but i didnt ;/

Regards,

Stefan Batory

Stefan B.

yuki_wu

896 Posts

Posted - 11/21/2016 :  9:54:53 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Stefan,

Perhaps you should try to swap the position of columns with a loop:
For example, there are a few of columns in [Book1]Sheet1:

range wks = [Book1]Sheet1;
int swaptimes = wks.ncols / 2;
loop(ii,1,swaptimes)
{
	int endcol = wks.ncols + 1 - ii;
	colswap rng:= [Book1]Sheet1!($(endcol),$(ii));
}

You can get a new order after you execute these scripts.

Hope it can be some help!

Regards,
Yuki
OriginLab

Edited by - yuki_wu on 11/21/2016 9:55:28 PM
Go to Top of Page

aplotnikov

Germany
162 Posts

Posted - 11/24/2016 :  02:12:25 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Stefan,

The reordering procedure suitable even for earlier Origin versions (8.6SR3) can be implemented as follows:

dataset dtTr={...};
// A loose dataset containing new column order - each value
// represents column number in the actual worksheet,
// for instance {3,5,1,4,2}, that is the third column
// should be moved to the first position, etc.
loop(ii,1,dtTr.GetSize()){
  colmove r:=col($(dtTr[ii])) o:=last;
//Worksheet to reorder is assumed active, if not you should modify
// the "rng" parameter (r:=...)
  loop(jj,ii+1,dtTr.GetSize()) {
    if (dtTr[jj]>dtTr[ii]) dtTr[jj]-=1;
// modifying the "new order" dataset
// taking into account the changes after column moving
  }
}


I just tried to simplify the code disregarding the performance. However this solution is not optimal - the number of X-function calls can be significantly reduced if the "colmove" X-function supports "pos" operation (requires more recent Origin versions). If the performance matters (that is very unlikely in this particular case) a bit more sophisticated solution can be suggested.

Regards,

Alexei

Edited by - aplotnikov on 11/24/2016 02:55:01 AM
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