如何解决无法生成模板:未找到 TrueType 字体文件
我的 excel 中有中文字符,列上的 setAutoSize
不起作用。我参考这篇文章 PHPExcel auto size column width 来修复它。
但它抛出
无法生成模板:未找到 TrueType 字体文件。
这是我的代码
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->fromArray($data);
\PhpOffice\PhpSpreadsheet\Shared\Font::setTrueTypeFontPath("/usr/share/fonts/msttcore/");
\PhpOffice\PhpSpreadsheet\Shared\Font::setAutoSizeMethod(\PhpOffice\PhpSpreadsheet\Shared\Font::AUTOSIZE_METHOD_EXACT);
$cellIterator = $sheet->getRowIterator(1,1)->current()->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(true);
foreach($cellIterator as $cell){
$column = $cell->getColumn();
$sheet->getColumnDimension($column)->setAutoSize(true);
}
我记录了它使用的字体
echo $this->getParent()->getCellXfByIndex($cell->getXfIndex())->getFont()->getName();
// Calibri
我在这篇文章中安装了 truetype 字体How to install Microsoft True Type fonts for Centos 7?
$ ll /usr/share/fonts/msttcore/calibri*
-r--r--r-- 1 root root 351544 Sep 11 2006 /usr/share/fonts/msttcore/calibrib.ttf
-r--r--r-- 1 root root 362524 Sep 11 2006 /usr/share/fonts/msttcore/calibrii.ttf
-r--r--r-- 1 root root 352736 Sep 11 2006 /usr/share/fonts/msttcore/calibri.ttf
-r--r--r-- 1 root root 367620 Sep 11 2006 /usr/share/fonts/msttcore/calibriz.ttf
检查是否安装了
$ fc-list | grep -i cali
/usr/share/fonts/msttcore/calibri.ttf: Calibri:style=Regular
/usr/share/fonts/msttcore/calibrii.ttf: Calibri:style=Italic
/usr/share/fonts/msttcore/calibriz.ttf: Calibri:style=Bold Italic
/usr/share/fonts/msttcore/calibrib.ttf: Calibri:style=Bold
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。