Search code examples
phpphpexcelxlsxphpspreadsheet

Problems with apostrophos using Phpspreadsheet to write xlsx


I fill out a spreadsheet with the information of a person, however, names like D'anna generate a problem in xlsx. D'anna has a square box in place of the apostrophe '. The form of writing that I use is this:

$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($this->excel, 'Xlsx');
$writer->save('php://output');

and at the time of setting the value in the cell, I use:

$planilha->setCellValue(utf8_encode($value['name']);

For the other values, it works correctly, only for the apostrophe that generates problem. Can someone help me? thankful!


Solution

  • I did this:

    $worksheet->setCellValue('C25',utf8_encode("D'anna"));
    

    And from the picture, you see it works as expected:

    D'anna picture