-1

我正在迭代 excel 工作表的所有单元格并打印出值。同时我还想打印他们正在使用的字体名称。是否有任何函数可以在 phpexcel 中获取特定的单元格字体名称?谢谢。下面是代码片段

 include('lib/phpexcel/Classes/PHPExcel/IOFactory.php');

  //Use whatever path to an Excel file you need.
  $inputFileName = 'text.xlsx';

  try {
    $inputFileType = PHPExcel_IOFactory::identify($inputFileName);
    $objReader = PHPExcel_IOFactory::createReader($inputFileType);
    $objPHPExcel = $objReader->load($inputFileName);
  } catch (Exception $e) {
    die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . 
        $e->getMessage());
  }

  $sheet = $objPHPExcel->getSheet(0);
  $highestRow = $sheet->getHighestRow();
  $highestColumn = $sheet->getHighestColumn();

  foreach ($sheet->getRowIterator() as $row) {
  echo '<tr>' . "\n";
  $cellIterator = $row->getCellIterator();
  $cellIterator->setIterateOnlyExistingCells(false); 
  foreach ($cellIterator as $cell) {
// Is there any similar $cell->getFont() function ?? which will echo"time new roman" 
    echo '<td>' .$cell->getValue(). '</td>' . "\n";
  }

  echo '</tr>' . "\n";
}
  ?>
4

1 回答 1

2

字体是单元格样式的一个方面;所以您需要获取单元格的样式详细信息,并从中读取字体信息:

$cell->getStyle()
    ->getFont()
    ->getName();

请注意,您还可以以类似的方式获取字体大小、斜体、粗体、下划线、上标/下标、删除线和字体颜色……字体对象包含的信息不仅仅是字体名称。

于 2017-05-13T16:12:44.000 回答