doulu1020 2015-04-25 12:43
浏览 468
已采纳

PHPExcel:根据图像设置行高(以像素为单位)

is there a way to set the row height according to the height of an image?

Example: I put an image (320x480 pixel) on D12 and now i want the row #12 height to fit the image (480 pixel).

Thanks!

  • 写回答

1条回答 默认 最新

  • dongwai4434 2015-04-25 13:10
    关注

    This is actually a lot more complex than it might seem - have a read of Microsoft's own article on setting height/width

    MS Excel measures row height in points when you specify a height value in Excel itself, where a point is approximately 1/72 inch or 0.035 cm. PHPExcel does provide helper methods for converting between points and pixels.

    $pixels = 480;
    $points = PHPExcel_Shared_Drawing::pixelsToPoints($pixels);
    

    and there is a corresponding PHPExcel_Shared_Drawing::pointsToPixels() method

    Use the helper to calculate the number of points from the pixel resolution of your image, and set that as your row height


    Internally though, Excel OfficeOpenXML format uses English Metric Units (or EMUs), where 1 EMU is defined as 1/360,000 of a centimeter and thus there are 914,400 EMUs per inch, and 12,700 EMUs per point.

    This allows for relatively straightforward conversions between the different units, and again, PHPExcel provides helper methods to convert between pixels and EMUs.

    $pixels = 480;
    $emu = PHPExcel_Shared_Drawing::pixelsToEMU($pixels);
    

    and there is a corresponding PHPExcel_Shared_Drawing::EMUToPixels() method

    If you save the file using the Excel2007 Writer (which saves as OfficeOpenXML format) then the image dimensions will be converted to EMUs, and when the file is subsequently reloaded there may be some slight discrepancy in the conversion, so allow a slight margin in the height that you set for the row to allow for this

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 MATLAB代码补全插值
  • ¥15 Typegoose 中如何使用 arrayFilters 筛选并更新深度嵌套的子文档数组信息
  • ¥15 前后端分离的学习疑问?
  • ¥15 stata实证代码答疑
  • ¥50 husky+jaco2实现在gazebo与rviz中联合仿真
  • ¥15 dpabi预处理报错:Error using y_ExtractROISignal (line 251)
  • ¥15 在虚拟机中配置flume,无法将slave1节点的文件采集到master节点中
  • ¥15 husky+kinova jaco2 仿真
  • ¥15 zigbee终端设备入网失败
  • ¥15 金融监管系统怎么对7+4机构进行监管的