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
 Origin Forum
 sort columns alphabetically?

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
cjfraz Posted - 05/05/2006 : 10:28:45 AM
Origin Version (Select Help-->About Origin): 7.5 sr5
Operating System:xp pro sp2

I have a bunch of worksheets with colmns XYYYY...

I'd like to sort all the Y columns left to right alphabetically by the column label (without sorting the numeric data in the columns at all).

Is there a strightforward or built in way to do this?

Thanks,

J...
2   L A T E S T    R E P L I E S    (Newest First)
cjfraz Posted - 05/05/2006 : 9:07:19 PM
Thank you very much Mike. This works great.

J...
Mike Buess Posted - 05/05/2006 : 5:50:31 PM
I don't know any built in way to change the column order but this brute force method works...
void SortColumnsByLabel()
{
Worksheet wks1 = Project.ActiveLayer(); // active wks
string wksName = wks1.GetPage().GetName(); // its name
Worksheet wks;
wks.Create();
for(int i=1;i<wks1.GetNumCols();i++)
{
wks.SetCell(i - 1,0,wks1.Columns(i).GetName()); // column name
wks.SetCell(i - 1,1,wks1.Columns(i).GetLabel()); // column label
}
wks.Sort(1); // sort by label column
Worksheet wks2;
wks2.CreateCopy(wks1); // duplicate starting wks
for(i=1;i<wks1.GetNumCols();i++) // delete all columns but X
wks2.DeleteCol(1);
Dataset ds1,ds2;
string colName,colLabel;
for(i=1;i<wks1.GetNumCols();i++)
{
wks.GetCell(i - 1,0,colName); // get name
wks.GetCell(i - 1,1,colLabel); // get label
wks2.AddCol(colName); // add column
wks2.Columns(i).SetLabel(colLabel); // set label
ds1.Attach(wksName + "_" + colName);
ds2.Attach(wks2,i);
ds2 = ds1; // copy data
}
wks.Destroy();
wks1.Destroy();
wks2.GetPage().Rename(wksName);
}


Mike Buess
Origin WebRing Member

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