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

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 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器