将OpenXML列宽转换为英寸

时间:2018-12-04 11:38:20

标签: excel openxml

我使用PhpSpreadsheet库生成XLSX。设置列宽时,我使用以下公式:

// Maximum Digit Width - default 7 (Calibri, 11)
// 4 (padding) + 1 (gridlines)
// FullDoc: https://docs.microsoft.com/en-us/previous-versions/office/developer/office-2010/cc802410(v=office.14)
width = Truncate([{Number of Characters} * {Maximum Digit Width} + {5 pixel padding}]/{Maximum Digit Width}*256)/256

例如:

Column A: 20 (character unit) = 20.7109375 (full width) = 145 px
Column B: 40 = 40.7109375 = 285 px

一切正常,但是,我还有另一个问题。

当我在LibreOffice Calc中打开生成的XLSX文件时,列宽显示为 inch

20.7109375 = 1.60"
40.7109375 = 3.14"

在.xlsx文件中: sheet1.xml

1个问题:LibraOffice如何将列宽值转换为英寸?

在MsExcel上打开时:

在正常模式下:

enter image description here

enter image description here

A和B的示例值相同。

但是在页面布局模式下:

enter image description here

enter image description here

A列:1.63英寸(156像素)

B列:3.19英寸(306像素)

2个问题:为什么每种模式的像素宽度都不同? (A列:145px <> 156px)

3个问题:为什么每个应用程序(Excel,LibreOffice)的英寸大小都不同? (B列:3.14英寸<> 3.19英寸)

通常,我想创建一张N列的工作表,因此,所有列的宽度之和等于纸张的大小(不带填充)。

对不起,我的英语!我使用Google!

0 个答案:

没有答案