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 matlab求解平差
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?