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
 LabTalk Forum
 columns order

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
Stefan B Posted - 11/21/2016 : 5:33:57 PM
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.
2   L A T E S T    R E P L I E S    (Newest First)
aplotnikov Posted - 11/24/2016 : 02:12:25 AM
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
yuki_wu Posted - 11/21/2016 : 9:54:53 PM
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

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