Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Excel column width
Message
De
25/12/2001 10:50:32
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
25/12/2001 08:22:25
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Divers
Thread ID:
00597816
Message ID:
00598040
Vues:
20
>>>Excel shows column width when we are resizing column. Excel uses units and pixels to show width. when I use Automation width property shows something else (I think). So a column 80 pixels width has width property equal 48. Is ther a way to find out pixels?
>>>
>>>Thanks Mark
>>
>>Mark,
>>For column width there are 2 units and methods. If you use ColumnWidth then width is expressed in characters (normal style - '0'), if you use Width then unit is points. Use columnwidth to set (at least I couldn't do it with width directly) :
>>
>>
oExcel= createobject('Excel.Application')
>>oExcel.Workbooks.Add
>>With oExcel
>>  .visible = .t.
>>  With .Activeworkbook.ActiveSheet.Columns(1)
>>    lcFont = .Font.Name
>>    lnSize = .Font.Size
>>    lnWidthInChars = .Columnwidth
>>    lnWidthInPoints = .Width
>>    lnWidthInPixels = lnWidthInPoints*fontmetric(19,lcFont,lnSize)/72 && 72 points = one inch
>>    ? 'On entry'
>>    ? 'Width in chars  :',lnWidthInChars
>>    ? 'Width in points :',lnWidthInPoints
>>    ? 'Width in pixels :',lnWidthInPixels
>>
>>* Set to 120 pixels
>>    .ColumnWidth = 120/(fontmetric(6,lcFont,lnSize)*txtwidth('0',lcFont,lnSize))
>>    lnWidthInChars = .Columnwidth
>>    lnWidthInPoints = .Width
>>    lnWidthInPixels = lnWidthInPoints*fontmetric(19,lcFont,lnSize)/72 && 72 points = one inch
>>    ? 'After setting to 120 pixels'
>>    ? 'Width in chars  :',lnWidthInChars
>>    ? 'Width in points :',lnWidthInPoints
>>    ? 'Width in pixels :',lnWidthInPixels, 'Should be higher than 120'
>>
>>* Set to 10 chars
>>    .ColumnWidth = 10
>>    lnWidthInChars = .Columnwidth
>>    lnWidthInPoints = .Width
>>    lnWidthInPixels = lnWidthInPoints*fontmetric(19,lcFont,lnSize)/72 && 72 points = one inch
>>    ? 'After setting to 10 chars'
>>    ? 'Width in chars  :',lnWidthInChars
>>    ? 'Width in points :',lnWidthInPoints
>>    ? 'Width in pixels :',lnWidthInPixels
>>
>>  Endwith
>>Endwith
>>
Cetin
>
>Hi Cetin,
>Thanks for help. Why when you set width to 120 it should be higher then 120?
>
>Thanks, Mark

Width seems to add apprx. 5-6 pixels (margin?). ie: 48 points are returned for default column width which is 64 pixels and 8.43 chars. 48 points in fact is more than 8.43 chars space (default Excel uses Arial,10 points). It should be 7.0 * 8.43 = 59.01 (fontmetric()*txtwidth() = 7)
Excel sounds to be buggy on calculation < g >

For example set columnwidth to 100 chars an recheck width in points and pixels :)
Also try setting a column to Courier new in Excel than change column width to 10, do columnwidth setting on a default column too. You'd see both column's have same width in pixels. I suspect if it ever takes care about font despite its docs.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform