-
Notifications
You must be signed in to change notification settings - Fork 606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Some CSVs aren't being parsed. #279
Comments
As a quick workaround, I ended up just using the passing the |
thank you! I will have a look once Invoice is done 🙌 |
Hi @barbinbrad , can you show us the changes you made? I think the problem may be related to the export const readLines = async (file: File, count = 2): Promise<string> => {
// ...
if (lines.length >= count) {
reader.cancel();
return lines.slice(0, count).join("\n");
}
// ...
} |
@anteriovieira just something like this: const processFile = async (file: File) => {
if (!file) {
setFileColumns(null);
return;
}
flushSync(() => {
setLoading(true);
});
Papa.parse(file, {
header: true,
skipEmptyLines: true,
error: (error) => {
setError(error.message);
setFileColumns(null);
setFirstRows(null);
setLoading(false);
},
complete: (results) => {
const { data, meta } = results;
if (!data || data.length < 2) {
setError("CSV file must have at least 2 rows.");
setFileColumns(null);
setFirstRows(null);
setLoading(false);
return;
}
if (!meta || !meta.fields || meta.fields.length <= 1) {
setError("Failed to retrieve CSV column data.");
setFileColumns(null);
setFirstRows(null);
setLoading(false);
return;
}
setFileColumns(meta.fields);
setFirstRows(data as Record<string, string>[]);
setLoading(false);
},
});
}; |
Thank you very much @barbinbrad |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I used your code as the basis of a CSV import tool and ran into a tricky bug.
Here's an example of a file that was not parsed by
readLines
:random_contacts.csv
Will post a solution when I have one.
The text was updated successfully, but these errors were encountered: