Bunlong / react-papaparse

react-papaparse is the fastest in-browser CSV (or delimited text) parser for React. It is full of useful features such as CSVReader, CSVDownloader, readString, jsonToCSV, readRemoteFile, ... etc.
https://react-papaparse.js.org
MIT License
364 stars 61 forks source link

encoding issue with CSReader when the csv come from excel #78

Closed dimitri-hoareau-WEL closed 3 years ago

dimitri-hoareau-WEL commented 3 years ago

Hello,

I am having an encoding problem with the CSVReader feature. I am working with a client who use an old version of microsoft excel. When he save a csv from excel, the generated csv file is apparently not encoded in utf-8 but in Latin1 (iso-8859-1) Thus, when he uploads his file, the French special characters like "é", "î" ... are replaced by �

I saw that there was a way to change the encoding with "encoding (The encoding to use when opening local files. If specified, it must be a value supported by the FileReader API.) on this page : https://react-papaparse.js.org/docs I have just to add encoding = iso-8859-1 ? But I did not understand in which part of the code should I add it

Here is the code if my app :

onFileLoad={handleOnFileLoad}
onError={handleOnError}
ref={buttonRef}
noClick
noDrag

>
{({ file }) => (
  <aside
    style={{
      display: 'flex',
      flexDirection: 'row',
      marginBottom: 10,
      alignItems: "baseline"
    }}
  >
    <Button
    className={classes.button}
    onClick={handleOpenDialog}
    variant="contained"
    color="primary"
    component="span">
      {trad.browse_file}
    </Button>
    <Typography>{file && file.name}</Typography>

  </aside>
)}
</CSVReader>

And thanks you very much for this package !

Bunlong commented 3 years ago

@dimitri-hoareau-WEL Please try to add config props to CSVReader. Here is the docs.

<CSVReader
  config={
    encoding: "ISO-8859-1",
  }
>
 ...
</CSVReader>
dimitri-hoareau-WEL commented 3 years ago

It's working ! thank you

Bunlong commented 3 years ago

@dimitri-hoareau-WEL You are welcome. Thank you!