phpencodephpspreadsheet

How to set the encode in PhpSpreadsheet\Reader\Xlsx?


I want to use PhpSpreadsheet convert xlsx to pdf, it's succeed. But the Chinese word in xlsx is error. And the setInputEncoding method is not found. What can I do? please give me guide

$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
$spreadsheet = $reader->load($public['root'].'/' . $fileName);
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Mpdf');
$pdfName = str_replace($extension, 'pdf', $fileName);
$writer->save($public['root'].'/' . $pdfName);

Solution

  • You can set Font Family in file xlsx.

    $reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
    $spreadsheet = $reader->load($public['root'].'/' . $fileName);
    
    $styleArray = array(
        'font'  => array(
            'name'  => 'Verdana' // change your font
        ));
    
    $spreadsheet->getDefaultStyle()->applyFromArray($styleArray);