PHPExcel: set line height in pixels as per image

Is there a way to set the line height to match the image height?

Example: I am placing an image (320x480 pixels) on D12 and now I want the height of line # 12 to match the image (480 pixels).

Thank!

+3


source to share


1 answer


It's actually a lot more complicated than it sounds - read Microsoft's article on adjusting height and width

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

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

      

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

Use a helper to calculate the number of points from the pixel resolution of your image and set it as the line height




Internally, however, the Excel OfficeOpenXML format uses English Metric Units (or EMU) , where 1 EMU is defined as 1/360,000 centimeters and thus there are 914,400 EMU for every inch and 12,700 EMU for each point.

This allows relatively simple conversions between different units, and again PHPExcel provides helper methods for converting between pixels and ews.

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

      

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

If you save the file using Excel2007 Writer (which is saved in OfficeOpenXML format), the image dimensions will be converted to EMU, and when the file is reloaded, there may be a slight conversion mismatch, so let's allow a small margin in the height you set for the line so that allow it

+5


source







All Articles