Php 未能生成模板:找不到TrueType字体文件

Php 未能生成模板:找不到TrueType字体文件,php,excel,fonts,truetype,phpspreadsheet,Php,Excel,Fonts,Truetype,Phpspreadsheet,我的excel中有中文字符,setAutoSize列不起作用。我参考这篇文章来修复它。 但是它扔 未能生成模板:找不到TrueType字体文件 这是我的代码 $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $sheet->fromArray($data); \PhpOffice\PhpSpreadsheet\Shared\Font::setTrueTypeFontPath("

我的excel中有中文字符,
setAutoSize
列不起作用。我参考这篇文章来修复它。 但是它扔

未能生成模板:找不到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字体作为本文的参考

检查是否安装了

$ 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
$ 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