RE: XLSX cell width - in twips?
- From: David Thielen <thielen@xxxxxxxxxxxxx>
- Date: Tue, 18 Dec 2007 06:08:01 -0800
I am following from "Office Open XML - Part 4" The <col width="9.140625"/>
element:
Column width measured as the number of characters of the maximum digit width
of the numbers 0, 1, 2, ..., 9 as rendered in the normal style's font. There
are 4 pixels of margin padding (two on each side), plus 1 pixel padding for
the gridlines.
width = Truncate([{Number of Characters} * {Maximum Digit Width} + {5 pixel
padding}]/{Maximum Digit Width}*256)/256
Using the Calibri font as an example, the maximum digit width of 11 point
font size is 7 pixels (at 96 dpi). In fact, each digit is the same width for
this font. Therefore if the cell width is 8 characters wide, the value of
this attribute shall be Truncate([8*7+5]/7*256)/256 = 8.7109375.
To translate the value of width in the file into the column width value at
runtime (expressed in terms of pixels), use this calculation:
=Truncate(((256 * {width} + Truncate(128/{Maximum Digit
Width}))/256)*{Maximum Digit Width})
Using the same example as above, the calculation would be
Truncate(((256*8.7109375+Truncate(128/7))/256)*7) = 61 pixels
To translate from pixels to character width, use this calculation:
=Truncate(({pixels}-5)/{Maximum Digit Width} * 100+0.5)/100
Using the example above, the calculation would be
Truncate((61-5)/7*100+0.5)/100 = 8 characters.
Note: when wide borders are applied, part of the left/right border shall
overlap with the 2 pixel padding on each side. Wide borders do not affect the
width calculation of the column.
Note: When the sheet is in the mode to view formulas instead of values, the
pixel width of the column is doubled.
The possible values for this attribute are defined by the XML Schema double
datatype.
--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com
Cubicle Wars - http://www.windwardreports.com/film.htm
"Jialiang Ge [MSFT]" wrote:
Hello Dave,.
Would you let me know the unit of your 'width'? Why did you add "/ 7f) *
256f) - (int) (128f/7f)) / 256f"?
If the dpi is 96, I am sure that: 1 twip = 1/1440 inch = 96/1440 pixel
We may also dynamically determine the TwipsPerPixelX and TwipsPerPixelY
according to the current resolution with the sample codes in
http://support.microsoft.com/kb/94927/en-us.
Regards,
Jialiang Ge (jialge@xxxxxxxxxxxxxxxxxxxx, remove 'online.')
Microsoft Online Community Support
==================================================
For MSDN subscribers whose posts are left unanswered, please check this
document: http://blogs.msdn.com/msdnts/pages/postingAlias.aspx
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express/Windows Mail, please make sure
you clear the check box "Tools/Options/Read: Get 300 headers at a time" to
see your reply promptly.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
- Follow-Ups:
- RE: XLSX cell width - in twips?
- From: Jialiang Ge [MSFT]
- RE: XLSX cell width - in twips?
- References:
- XLSX cell width - in twips?
- From: David Thielen
- RE: XLSX cell width - in twips?
- From: Jialiang Ge [MSFT]
- XLSX cell width - in twips?
- Prev by Date: RE: XLSX cell width - in twips?
- Next by Date: RE: XLSX cell width - in twips?
- Previous by thread: RE: XLSX cell width - in twips?
- Next by thread: RE: XLSX cell width - in twips?
- Index(es):
Relevant Pages
|