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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?