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!
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!
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