我正在迭代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";
}
?>
答案 0 :(得分:2)
字体是单元格样式的一个方面;所以你需要获取单元格的样式细节,并从中读取字体信息:
$cell->getStyle()
->getFont()
->getName();
请注意,您也可以以类似的方式获取字体大小,斜体,粗体,下划线,super /下标,strikethru和字体颜色....字体对象包含的信息不仅仅是字体名称。