当前位置: 首页>>代码示例>>PHP>>正文


PHP PHPExcel_Shared_Drawing::pixelsToCellDimension方法代码示例

本文整理汇总了PHP中PHPExcel_Shared_Drawing::pixelsToCellDimension方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPExcel_Shared_Drawing::pixelsToCellDimension方法的具体用法?PHP PHPExcel_Shared_Drawing::pixelsToCellDimension怎么用?PHP PHPExcel_Shared_Drawing::pixelsToCellDimension使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PHPExcel_Shared_Drawing的用法示例。


在下文中一共展示了PHPExcel_Shared_Drawing::pixelsToCellDimension方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: calculateColumnWidth

 /**
  * Calculate an (approximate) OpenXML column width, based on font size and text contained
  *
  * @param     int        $fontSize            Font size (in pixels or points)
  * @param     bool    $fontSizeInPixels    Is the font size specified in pixels (true) or in points (false) ?
  * @param     string    $cellText            Text to calculate width
  * @param     int        $rotation            Rotation angle
  * @return     int        Column width
  */
 public static function calculateColumnWidth(PHPExcel_Style_Font $font, $cellText = '', $rotation = 0, PHPExcel_Style_Font $defaultFont = null)
 {
     // If it is rich text, use plain text
     if ($cellText instanceof PHPExcel_RichText) {
         $cellText = $cellText->getPlainText();
     }
     // Special case if there are one or more newline characters ("\n")
     if (strpos($cellText, "\n") !== false) {
         $lineTexts = explode("\n", $cellText);
         $lineWitdhs = array();
         foreach ($lineTexts as $lineText) {
             $lineWidths[] = self::calculateColumnWidth($font, $lineText, $rotation = 0, $defaultFont);
         }
         return max($lineWidths);
         // width of longest line in cell
     }
     // Try to get the exact text width in pixels
     try {
         // If autosize method is set to 'approx', use approximation
         if (self::$autoSizeMethod == self::AUTOSIZE_METHOD_APPROX) {
             throw new Exception('AutoSize method is set to approx');
         }
         // Width of text in pixels excl. padding
         $columnWidth = self::getTextWidthPixelsExact($cellText, $font, $rotation);
         // Excel adds some padding, use 1.07 of the width of an 'n' glyph
         $columnWidth += ceil(self::getTextWidthPixelsExact('0', $font, 0) * 1.07);
         // pixels incl. padding
     } catch (Exception $e) {
         // Width of text in pixels excl. padding, approximation
         $columnWidth = self::getTextWidthPixelsApprox($cellText, $font, $rotation);
         // Excel adds some padding, just use approx width of 'n' glyph
         $columnWidth += self::getTextWidthPixelsApprox('n', $font, 0);
     }
     // Convert from pixel width to column width
     $columnWidth = PHPExcel_Shared_Drawing::pixelsToCellDimension($columnWidth, $defaultFont);
     // Return
     return round($columnWidth, 6);
 }
开发者ID:phpsmith,项目名称:IS4C,代码行数:47,代码来源:Font.php

示例2: calculateColumnWidth

 /**
  * Calculate an (approximate) OpenXML column width, based on font size and text contained
  *
  * @param 	int		$fontSize			Font size (in pixels or points)
  * @param 	bool	$fontSizeInPixels	Is the font size specified in pixels (true) or in points (false) ?
  * @param 	string	$columnText			Text to calculate width
  * @param 	int		$rotation			Rotation angle
  * @return 	int		Column width
  */
 public static function calculateColumnWidth(PHPExcel_Style_Font $font, $columnText = '', $rotation = 0, PHPExcel_Style_Font $defaultFont = null)
 {
     // If it is rich text, use plain text
     if ($columnText instanceof PHPExcel_RichText) {
         $columnText = $columnText->getPlainText();
     }
     // Only measure the part before the first newline character (is always "\n")
     if (strpos($columnText, "\n") !== false) {
         $columnText = substr($columnText, 0, strpos($columnText, "\n"));
     }
     // Try to get the exact text width in pixels
     try {
         // If autosize method is set to 'approx', use approximation
         if (self::$autoSizeMethod == self::AUTOSIZE_METHOD_APPROX) {
             throw new Exception('AutoSize method is set to approx');
         }
         // Width of text in pixels excl. padding
         $columnWidth = self::getTextWidthPixelsExact($columnText, $font, $rotation);
         // Excel adds some padding, use 1.07 of the width of an 'n' glyph
         $columnWidth += ceil(self::getTextWidthPixelsExact('0', $font, 0) * 1.07);
         // pixels incl. padding
     } catch (Exception $e) {
         // Width of text in pixels excl. padding, approximation
         $columnWidth = self::getTextWidthPixelsApprox($columnText, $font, $rotation);
         // Excel adds some padding, just use approx width of 'n' glyph
         $columnWidth += self::getTextWidthPixelsApprox('n', $font, 0);
     }
     // Convert from pixel width to column width
     $columnWidth = PHPExcel_Shared_Drawing::pixelsToCellDimension($columnWidth, $defaultFont);
     // Return
     return round($columnWidth, 6);
 }
开发者ID:honj51,项目名称:taobaocrm,代码行数:41,代码来源:Font.php


注:本文中的PHPExcel_Shared_Drawing::pixelsToCellDimension方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。