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
 Origin Forum
 sort columns alphabetically?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

cjfraz

USA
22 Posts

Posted - 05/05/2006 :  10:28:45 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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...

Mike Buess

USA
3037 Posts

Posted - 05/05/2006 :  5:50:31 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

cjfraz

USA
22 Posts

Posted - 05/05/2006 :  9:07:19 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you very much Mike. This works great.

J...
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