【问题标题】:C# Excel Interop: How to set cells height and width in pixels?C# Excel 互操作:如何以像素为单位设置单元格的高度和宽度?
【发布时间】:2017-07-25 09:41:51
【问题描述】:

我不会故意在这个问题中发布任何代码,因为不需要回答这个问题,由于某些原因,我需要通过像素值而不是标准 activeWorksheet.Rows.RowHeight 设置工作表中单元格的高度和宽度接受标准值。 如何通过像素成功设置单元格的高度和宽度?谢谢。

【问题讨论】:

  • pixels = points * DPI / 72 可以反转为points = pixels / DPI * 72
  • @JeremyThompson 感谢您的回复,我在哪里以及如何获得 DPi?
  • 伙伴,只需谷歌“c# get DPI”
  • @JeremyThompson 是的,你是对的,哈哈 :)

标签: c# office-interop com-interop excel-interop


【解决方案1】:

公式:

pixels = points * DPI / 72

可以反转为:

points = pixels / DPI * 72

这样您可以使用像素设置行高。

get the DPI in C# see this

【讨论】:

  • 但问题是如何在 Excel 互操作中设置它:excWorksheet.Columns[1].ColumnWidth = pixel / DPI * 72;当您将鼠标放在 excel 中的列上时,像素会增加很多。
  • @JohnKurtz 你在谈论列宽,问题是关于 RowHeight。
  • 对不起,我只是假设它们会以相同的方式测量!关于如何处理列宽的任何见解?标题询问高度和宽度。
  • 对于 Arial 10,我发现了一个很好的近似值:excWorksheet.Columns[1].ColumnWidth = 0.14286f * (pixels - 5);
猜你喜欢
  • 2019-08-06
  • 2011-12-05
  • 2014-12-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-18
  • 1970-01-01
相关资源
最近更新 更多