Why is my CSV Importer reading my CSV deformatted?
I am importing a CSV and my CSV importer is reading the headings deformatted. Some headings that I need are: Issuer_nr, Authority_nr and Kaart serie nummer. Those are being read as:
ÿþI�s�s�u�e�r� �N�r�
�A�u�t�h�o�r�i�t�y� �N�r�
�K�a�a�r�t� �s�e�r�i�e� �n�u�m�m�e�r�
When I open the CSV in a code editor it just normally shows the headings as they should be:
Issuer Nr;Authority Nr;Kaart serie nummer;
When I export the CSV to CSV with numbers it does read the headings normally in the importer.
Any ideas?
7 Replies
The CSV isn't saved as UTF8
Is there anyway to still use CSV's not saved as UTF8? It's an export from a system I can't change anything in.
Look up ‘csv BOM’ I’m sure there’s php packages out there that you can use to normalize the csv file contents before running it through the importer.
Even with utf-8 I’ve seen issues like this between files saved out of windows vs Mac.
In what function can I write code on the imported file?
Any ideas?
Because rn its not matching the values right.
I can't find any function to put the normalizing code in before it hits the columns here.
You might need to extend the ImportAction to tap into the forms FileUpload and modify the afterStateUpdated(). Might be possible with one of the Importer lifecycle hooks too. Not 100% sure of the best place to do it. https://filamentphp.com/docs/3.x/actions/prebuilt-actions/import#lifecycle-hooks
Ideally though, a validation on the file might be better. If it’s not a supported encoding, then don’t allow them to continue.
Again not sure where or how to check that. Haven’t don’t anything with the imports personally.