You are here

public static function PHPExcel_Shared_Drawing::pixelsToCellDimension in Loft Data Grids 6.2

Same name and namespace in other branches
  1. 7.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/Drawing.php \PHPExcel_Shared_Drawing::pixelsToCellDimension()

* Convert pixels to column width. Exact algorithm not known. * By inspection of a real Excel file using Calibri 11, one finds 1000px ~ 142.85546875 * This gives a conversion factor of 7. Also, we assume that pixels and font size are proportional. * *

Parameters

int $pValue Value in pixels: * @param PHPExcel_Style_Font $pDefaultFont Default font of the workbook * @return int Value in cell dimension

1 call to PHPExcel_Shared_Drawing::pixelsToCellDimension()
PHPExcel_Shared_Font::calculateColumnWidth in vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/Font.php
* Calculate an (approximate) OpenXML column width, based on font size and text contained * *

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/Drawing.php, line 71

Class

PHPExcel_Shared_Drawing
PHPExcel_Shared_Drawing

Code

public static function pixelsToCellDimension($pValue = 0, PHPExcel_Style_Font $pDefaultFont) {

  // Font name and size
  $name = $pDefaultFont
    ->getName();
  $size = $pDefaultFont
    ->getSize();
  if (isset(PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size])) {

    // Exact width can be determined
    $colWidth = $pValue * PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size]['width'] / PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size]['px'];
  }
  else {

    // We don't have data for this particular font and size, use approximation by
    // extrapolating from Calibri 11
    $colWidth = $pValue * 11 * PHPExcel_Shared_Font::$defaultColumnWidths['Calibri'][11]['width'] / PHPExcel_Shared_Font::$defaultColumnWidths['Calibri'][11]['px'] / $size;
  }
  return $colWidth;
}