0

I have a web application that generates a UTF-8 .csv and returns it to the user with the following code.

const createCSV = () => {

  ...

  return new Blob(["\ufeff" + csvContent], {
            type: "text/csv;charset=utf-8",
        })
}

I had to add the \ufeff BOM in order to get the character to render correctly in Excel

I am using Filesaver.js to trigger the save to the user's computer

onClick={() => saveAs(createCSV(attributes), "template.csv", {autoBom: true})}

This seems to work fine for Mac users, but when a user on Windows clicks the download button, the download prompt is showing the file type as Unicode Text.

Any ideas why the file is showing up as Unicode Text instead of .csv for Windows users?

DLee
  • 7,856
  • 4
  • 19
  • 23
  • Does it helps: https://stackoverflow.com/questions/6588068/which-encoding-opens-csv-files-correctly-with-excel-on-both-mac-and-windows ? – ishaba Jul 30 '21 at 19:35
  • 1
    I tried it out using `new TextEncoder("windows-1252", {NONSTANDARD_allowLegacyEncoding: true,}).encode(csvContent)`, which saves the file correctly but now the `≤` is saved as an unknown character – DLee Jul 30 '21 at 20:22
  • Thats because there is no such character in windows-1252 not much to deal with that – ishaba Jul 30 '21 at 20:33
  • Hmm okay, I will need to look for an encoding that works for both windows and mac and supports that character. Thanks for the suggestion though – DLee Jul 30 '21 at 21:23

0 Answers0