Author |
Topic |
|
masterd
Australia
Posts |
Posted - 03/13/2006 : 9:23:25 PM
|
Origin Version (Select Help-->About Origin): pro 7.5 sr4 Operating System: 2000 pro
Is there an easy way (ie. script) for automatically adjusting column width by following or similar criteria.
-X column width defined by width of numeric data -Y column width defined by width of column label
I know i can set fixed column width for all columns but that is not what i want as i get whole heap of white unused space. my Y columns usually contain digits and column label (label wider than numeric data) while my x column contains digits and no label.
I hope that was clear?!
Darko
After posting above message i have found this code
loop (ii,1,wks.ncols) { %N=wks.col$(ii).name$; %L=wks.col$(ii).label$; nn=%[%N]; // width of column name if(nn<%[%L]) nn=%[%L]; // if label is wider use it instead wks.col$(ii).width=nn; };
the code works fine only if there are labels in all columns. however, in my case every second column has a label and code does the right thing with column that has a label. however, column with no label gets shrank down to couple of milimeters wide literally.
Any chance of modifying above case to suit my situation?
Thanks
Darko
Edited by - masterd on 03/14/2006 12:54:45 AM |
|
Mike Buess
USA
3037 Posts |
Posted - 03/14/2006 : 05:41:35 AM
|
Hi Darko,
You say only your Y columns have labels so this acts only on Y columns...
loop (ii,1,wks.ncols) { kk=wks.col$(ii).type; // col type: X=4, Y=1, etc. if(kk==1) { %N=wks.col$(ii).name$; %L=wks.col$(ii).label$; nn=%[%N]; // width of column name if(nn<%[%L]) nn=%[%L]; // if label is wider use it instead wks.col$(ii).width=nn; }; };
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 03/14/2006 05:43:28 AM |
|
|
easwar
USA
1964 Posts |
Posted - 03/16/2006 : 10:55:08 AM
|
Hi,
And the following is an OC solution. It is not sensitive to Y columns, but you can add that if desired by looking at colum type.
Easwar OriginLab
void set_col_width() { Worksheet wks = Project.ActiveLayer(); if( !wks ) return; foreach(Column col in wks.Columns) { // First set width to fit the numbers col.SetWidth(-1); int nWidth = col.GetWidth(); // Then check if label exits and get size string str; col.GetLabel(str); int nLabelSize = str.GetLength(); if( nLabelSize > nWidth ) col.SetWidth(nLabelSize); } }
|
|
|
turbvg
Germany
9 Posts |
Posted - 05/22/2015 : 04:20:09 AM
|
Hi,
Sorry for awakening this topic nearly ten years after it was created, but I have a question about the OC code presented here :
I have used the OC code presented here, and it works quite well. However, there is one little problem that I have encountered : in general, in the data files that I handle, the acquisition is started before the machine, so for the first couple of hundreds rows, the values are quite a lot smaller than in general. So the macro works great for the first rows, but when the values start to climb, the column is too narrow and ##### appears.
I suspect that the SetWidth(-1) function only looks at a certain number of rows to determine the column width. Is there a way to modify this ?
Thanks
-- Origin 2015 Windows 7 |
|
|
jasonzhao
China
262 Posts |
Posted - 05/27/2015 : 05:04:18 AM
|
Hello,
The system variable @RLR control the Resize threshold; you can run the LabTalk script below in Script Window:
@RLR=1500; //set the threshold to 1500 row
then, the column width can be resized properly by both Origin C function or double click the right border of the column.
Best regards! Jason OriginLab Technical Service
|
Edited by - jasonzhao on 05/27/2015 05:54:47 AM |
|
|
long123
China
9 Posts |
Posted - 06/15/2015 : 04:16:37 AM
|
the code works fine only if there are labels in all columns. however, in my case every second column has a label and code does the right thing with column that has a label
sbvdxfnbghm |
|
|
jasonzhao
China
262 Posts |
Posted - 06/15/2015 : 04:32:36 AM
|
Hello,
Would you please tell me your Origin version? For our current version, Origin 2015, there is no such problem.
Best regards! Jason OriginLab Technical Service
quote: Originally posted by long123
the code works fine only if there are labels in all columns. however, in my case every second column has a label and code does the right thing with column that has a label
sbvdxfnbghm
|
|
|
long123
China
9 Posts |
Posted - 06/17/2015 : 02:36:46 AM
|
I know i can set fixed column width for all columns but that is not what i want as i get whole heap of white unused space. my Y columns usually contain digits and column label (label wider than numeric data) while my x column contains digits and no label.
sbvdxfnbghm |
|
|
jasonzhao
China
262 Posts |
Posted - 06/18/2015 : 11:28:38 PM
|
Hello,
Would you please illustrate the width you wanted for columns with a screenshot, so we can understand the questions better?
Best regards! Jason OriginLab Technical Service
quote: Originally posted by long123
I know i can set fixed column width for all columns but that is not what i want as i get whole heap of white unused space. my Y columns usually contain digits and column label (label wider than numeric data) while my x column contains digits and no label.
sbvdxfnbghm
|
|
|
long123
China
9 Posts |
Posted - 06/26/2015 : 03:39:03 AM
|
then, the column width can be resized properly by both Origin C function or double click the right border of the column.
sbvdxfnbghm |
|
|
|
Topic |
|