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