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

关于 XSSFFont.FontHeight 的属性设置 BUG 以及一点建议 #141

Closed
hizlin opened this issue Nov 18, 2018 · 2 comments
Closed

关于 XSSFFont.FontHeight 的属性设置 BUG 以及一点建议 #141

hizlin opened this issue Nov 18, 2018 · 2 comments
Assignees
Labels
Milestone

Comments

@hizlin
Copy link

hizlin commented Nov 18, 2018

部分简化源码
XSSFFont : IFont {
double FontHeight {
get {
if (ct_FontSize != null)
return (double)(short)(ct_FontSize.val * 20.0);
return DEFAULT_FONT_SIZE * 20.0;
}
set {
ct_FontSize.val = value; // BUG: 赋值没有除于 20;
}
}
short FontHeightInPoints {
get {
return (short)(this.FontHeight / 20.0);
}
set {
ct_FontSize.val = value;
}
}
}
FontHeight 属性的 set 部分 没有将 value 除于 20 再保存..
此 BUG 在 NPOIv2.2.1.0 已存在至v2.4, 更早的版本没接触...
HSSFFont 没有问题...
微软关于 CT_FontSize 的定义, val 的单位是 Point.
https://msdn.microsoft.com/en-us/library/office/documentformat.openxml.spreadsheet.fontsize.aspx

一点建议:
FontHeight/FontHeightInPoints 的数据类型设计很不合理...类型设置相反了.
FontHeight 使用 short, 单位为 1/20 Point, 单位很小了, 没必要有小数部分.
FontHeightInPoints 使用 double 或者 float, 单位为 Point, 需要小数部分;
Excel 软件是支持小数字号的, 例如 10.5 磅...
目前 NPOI 只能设置整数字号, 即使设置小数, 也会在内部类型转换后损失小数部分...

@tonyqus
Copy link
Member

tonyqus commented Nov 19, 2018

这确实是个bug,感谢

@tonyqus tonyqus added the bug label Nov 19, 2018
@tonyqus tonyqus self-assigned this Nov 19, 2018
@tonyqus
Copy link
Member

tonyqus commented Nov 23, 2018

下个版本将把FontHeight和FontHeightInPoints 都改成double,以适应所有情况。

@tonyqus tonyqus added this to the NPOI 2.5.0 milestone Mar 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants