qax-os / excelize

Go language library for reading and writing Microsoft Excel™ (XLAM / XLSM / XLSX / XLTM / XLTX) spreadsheets
https://xuri.me/excelize
BSD 3-Clause "New" or "Revised" License
18.32k stars 1.71k forks source link

SetColWidth doesn't correct #569

Closed EP-Toushirou closed 4 years ago

EP-Toushirou commented 4 years ago

Description Hello, SetColWidth's point is not same as the excel's point.

func SetColWidth() {
    f, _ := excelize.OpenFile("SetColWidth.xlsx")
    f.SetColWidth("Sheet1", "A", "A", 10.75)
    f.Save()
}

Describe the results you received: image

Describe the results you expected: 10.75

Output of go version:

go version go1.13.7 windows/amd64

Excelize version or commit ID:

Commits on Jan 23, 2020 (new master)

Environment details (OS, Microsoft Excel™ version, physical, etc.):

win10, office2019(1912)
xuri commented 4 years ago

This issue similar width #279, the column width in the Excel relate width DPI (Ref: Description of how column widths are determined in Excel, DPI and Device-Independent Pixels and ECMA 376 Part1 18.3.1.13). The SetColWidth function in this library won't check DPI, the value of the column width will be set as is. So the same document will be shown differently on different OS and display devices. You need to calculate the width to fit the platform, for example, using the Calibri font as an example, the maximum digit width of 11 point font size is 7 pixels (at 96 dpi)

SetColWidth("Sheet1", "A", "A", math.Trunc((10.75*7+5)/7*256)/256)
EP-Toushirou commented 4 years ago

Thank you for your explain.I will check it again.🤝