I'm getting data from the database, some strings are English, some are Arabic, some are half Arabic half English.
I'm generating the spreadsheet .xlsx
like this
function writeToFile($spreadsheet, $filename)
{
header("Content-Encoding: UTF-8");
header('Content-Type: application/vnd.ms-excel; charset=UTF-8"');
header('Content-Disposition: attachment; filename=' . $filename);
$writer = new Xlsx($spreadsheet);
$writer->save("php://output");
}
But I'm not downloading it directly, this generates a blob which gets downloaded using javascript.
fetch(url)
.then(resp => resp.blob())
.then(file => {
if (file.size > 0) {
const url = window.URL.createObjectURL(file);
const a = document.createElement('a');
a.style.display = 'none';
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
} else {
console.log('error');
}
})
.catch(() => console.log('error'));
The problem is with PHPspreadsheet, I don't know if I fix that, I'll get another problem related to JS, but I do know that if I generate the file without using JS, I'll still have the Arabic issue.