如何获取excel单元格的字体名称
How to get the font name of the excel cell
我正在迭代 excel sheet 的所有单元格并打印出值。同时我还想打印他们正在使用的字体名称。 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";
}
?>
字体是单元格样式的一个方面;所以你需要获取单元格的样式细节,并从中读取字体信息:
$cell->getStyle()
->getFont()
->getName();
请注意,您还可以以类似的方式获取字体大小、斜体、粗体、下划线、super/subscript、删除线和字体颜色....字体对象比简单的字体包含更多信息名字.
我正在迭代 excel sheet 的所有单元格并打印出值。同时我还想打印他们正在使用的字体名称。 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";
}
?>
字体是单元格样式的一个方面;所以你需要获取单元格的样式细节,并从中读取字体信息:
$cell->getStyle()
->getFont()
->getName();
请注意,您还可以以类似的方式获取字体大小、斜体、粗体、下划线、super/subscript、删除线和字体颜色....字体对象比简单的字体包含更多信息名字.