找回密码
 立即注册

QQ登录

只需一步,快速开始

huchunyan

银牌会员

9

主题

18

帖子

3031

积分

银牌会员

积分
3031

活字格认证

huchunyan
银牌会员   /  发表于:2015-9-15 11:17  /   查看:4862  /  回复:2
GcSpreadSheet控件的FontSize和excel的不一致,比如,同样设置11号,控件中的字体大小明显要比excel里面的字体大小要小很多,怎么可以保持一致

2 个回复

倒序浏览
iceman
社区贡献组   /  发表于:2015-9-15 17:44:00
沙发
回复 1楼huchunyan的帖子

请通过以下代码转换:

  1.     private void Window_Loaded(object sender, RoutedEventArgs e)
  2.         {
  3.             this.gcSpreadSheet1.ActiveSheet.Cells[0, 0].FontSize = UnitHelper.PointToPixel(11);
  4.             this.gcSpreadSheet1.ActiveSheet.Cells[0, 0].Text = "测试";
  5.         }
  6.     }

  7.     internal static class UnitHelper
  8.     {
  9.         private static double? _dpi;
  10.         private static readonly double PointsPerInch = 72;

  11.         public static double PointToPixel(double point)
  12.         {
  13.             return point * GetDPI() / PointsPerInch;
  14.         }

  15.         public static double PixelToPoint(double pixel)
  16.         {
  17.             return pixel * PointsPerInch / GetDPI();
  18.         }

  19.         public static double GetDPI()
  20.         {
  21.             if (_dpi.HasValue)
  22.                 return _dpi.Value;
  23.             else
  24.             {
  25.                 _dpi = GetSystemDPI();
  26.                 return _dpi.Value;
  27.             }
  28.         }

  29.         private static double GetSystemDPI()
  30.         {
  31.             return 96; //Look like excel always use DPI=96.
  32.         }

  33.     }
复制代码

评分

参与人数 1满意度 +5 收起 理由
huchunyan + 5 谢谢

查看全部评分

回复 使用道具 举报
iceman
社区贡献组   /  发表于:2015-9-23 09:32:00
板凳
回复 1楼huchunyan的帖子

请问问题是否解决?为了给你提供更优质的服务,请对本次服务进行评分。我们会认真对待你提出的宝贵意见,谢谢
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部