Hi David,
Here are some OriginC solutions...
1. This will sort each column in ascending order w.r.t to itself. (To sort in descending order use SORT_DESCENDING instead of SORT_ASCENDING.) The pg.SetShow() commands merely refresh the worksheet to show the changes. void SortColumn()
{
Worksheet wks = Project.ActiveLayer();
Dataset dd;
foreach (Column cc in wks.Columns)
{
dd.Attach(cc);
dd.Sort(SORT_ASCENDING);
}
Page pg = Project.Pages();
pg.SetShow(PAGE_HIDDEN);
pg.SetShow(PAGE_ACTIVATE);
}
2. This will remove all NaN cells and shift remaining cells upwards.void RemoveNaN()
{
Worksheet wks = Project.ActiveLayer();
Dataset dd;
foreach (Column cc in wks.Columns)
{
dd.Attach(cc);
dd.Trim();
}
}
3. Delete every Nth column...void RemoveNthCol(int N)
{
Worksheet wks = Project.ActiveLayer();
int nCols = LabTalk.wks.ncols;
for(int i=nCols-1; i>=0; i--)
{
if( mod(i+1,N)==0 )
wks.DeleteCol(i);
}
}
Since you're new to OriginC and asked for details...
1. Open CodeBuilder from Origin's View menu.
2. Select New on CodeBuilder's File menu. In the resulting dialog,
2a. Enter a file name such as Test.c.
2b. Check both the Add to Workspace and the Fill with Default Contents options.
2c. Click OK.
3. Copy the three functions from this post and paste them into the new file.
4. Select Build on CodeBuilders Tools menu. You should see the following messages
compiling...
Test.c
Linking...
Done!
5. Return to Origin, make sure your worksheet is active and open the script window (View->Script Window). To execute one of your functions just type its name with arguments (if any) and hit Enter...
SortColumn<Enter>
RemoveNaN<Enter>
The third function needs the column increment as an argument, i.e., to remove every 4th column...
RemoveNthCol 4<Enter>
Mike Buess
Origin WebRing Member
Edited by - Mike Buess on 12/29/2004 2:15:30 PM