一、EXCEL文档内两个重要的属性
属性 | 英文说明 |
baseColWidth (Base ColumnWidth) | Specifies the number of characters of the maximum digit width of the normal style's font. See defaultColWidth description in this section for details on calculating this value. See the col element description, particularly the width attribute description, for moreinformation on what is meant by "maximum digit width". The possible values for this attribute are defined by the W3C XML Schema unsignedInt datatype. |
defaultColWidth (Default ColumnWidth) | Default column width measured as the number of characters of the maximum digit widthof the normal style's font. If the user has not set this manually, then it can be calculated: If the user has set this manually, then there is no calculation, and simply a value isspecified. The possible values for this attribute are defined by the W3C XML Schema double datatype. |
defaultRowHeight (Default RowHeight) | Default row height measured in point size. Optimization so we don't have to write theheight on all rows. When the row height of all rows in a sheet is the default value, then that value is writtenhere, and customHeight is not set. If a few rows have a different height, that informationis written directly on each row. However, if most or all of the rows in the sheet have thesame height, but that height isn't the default height, then that height value should bewritten here (as an optimization), and the customHeight flag should also be set. In thiscase, all rows having this height do not need to express the height, only rows whoseheight differs from this value need to be explicitly expressed. The possible values for this attribute are defined by the W3C XML Schema doubledatatype. |
(2)、COl对象类
Defines column width and column formatting for one or more columns of the worksheet.
Attributes | Description |
width (Column Width) | 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 [Example: 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 must be Truncate([8*7+5]/7*256)/256 = 8.7109375. end example] (expressed in terms of pixels), use this calculation: =Truncate(((256 * {width} + Truncate(128/{Maximum Digit Width}))/256)*{Maximum Digit Width}) [Example: Using the same example as above, the calculation would be Truncate(((256*8.7109375+Truncate(128/7))/256)*7) = 61 pixels. end example] To translate from pixels to character width, use this calculation: =Truncate(({pixels}-5)/{Maximum Digit Width} * 100+0.5)/100 [Example: Using the example above, the calculation would be Truncate((61- 5)/7*100+0.5)/100 = 8 characters. end example] [Note: when wide borders are applied, part of the left/right border must overlap with the 2 pixel padding on each side. Wide borders do not affect the width calculation of the column. end note] [Note: When the sheet is in the mode to view formulas instead of values, the pixel width of the column is doubled. end note] The possible values for this attribute are defined by the W3C XML Schema double datatype. 列宽度,以数字 0、1、......、9 的最大数字宽度的字符数度量,以普通样式的字体呈现。边距填充有 4 个像素(每侧两个),加上网格线的 1 像素填充。 二 、要从像素转换为字符宽度,请使用此计算: |
二、高度计算
MAC WPS默认值:17.6磅 ( 默认字体:宋体 大小12磅), Windos WPS值:13.5磅 (默认字体:宋体 大小11磅)。
换算公式为:72磅=1英寸,1英寸=2.54厘米。
那么1磅=1/72英寸,而1英寸所含有PPI个像素,这里就不详细展开PPI的计算了,现在一般计算机默认为96,详细的计算可以自己百度。
因此磅到像素的转换为 : PX=(PT/72*PPI) (公式-1) 其中PX为像素 PT为磅
厘米到像素的转换为:PX= (mm/2.54*PPI) (公式-2) 其中PX为像素 mm为厘米
(1)MAC WPS计算 默认字体:宋体 大小12磅
高度为17.6磅的像素为 px=17.6/72*96 =23.46
高度为0.62厘米的像素为 px=0.62/2.54*96 =23.43 (此处的厘米数为wps上展示的,下同,和上述对比使用,有兴趣的同学可以根据宏获取磅值,再算像素)
(2)WINDOWS WPS计算 默认字体:宋体 大小11磅
高度为13.5磅的像素为 px=13.5/72*96 =18.00
高度为0.48厘米的像素为 px=0.48/2.54*96 =18.14
在WPS的若某行存在与默认不一样的高度时,在某行类的属性上ht就存在磅值,其计算方式与默认磅值相同。
三、宽度计算
(1)官方文档说明
官方文档对defaultColWidth (Default Column Width) 默认列宽度的解释如下:
(8X+5)/256X=256width
=》 width =(8X+5)/ X
=》 width = 8+5/X (公式-5)
在公式-5中 5/x为一个反函数,超过5以后随着X-Maximum Digit Width的变大,宽度几乎保持不变?我们从实际的应用中可以知道数字的宽度随着字体的变大,宽度也变大, 这个从EXCEL的文档中就可以轻易证实。
(2)宽度到像素计算