Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SetColWidth doesn't correct #569

Closed
EP-Toushirou opened this issue Feb 2, 2020 · 2 comments
Closed

SetColWidth doesn't correct #569

EP-Toushirou opened this issue Feb 2, 2020 · 2 comments

Comments

@EP-Toushirou
Copy link

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
Copy link
Member

xuri commented Feb 2, 2020

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)

@xuri xuri closed this as completed Feb 2, 2020
@EP-Toushirou
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants