Home > Blockchain >  Capacitor / Ionic Filesystem writeFile to csv
Capacitor / Ionic Filesystem writeFile to csv

Time:04-10

I am using Capacitor 3, Filesystem and I'm saving data into a file.

Here is the code:

  writeToCSVFile = async () => {
    await Filesystem.writeFile({
      path: 'text.csv',
      data: `0123445544,4556677`,
      directory: Directory.Documents
    });
  };

The file is saving but there is some data in cell 1 of the csv with some strange characters.

In my can there should be 2 cells each with one of the numbers in the data.

How can I fix this?

CodePudding user response:

You have to set the encoding parameter to Encoding.UTF8:

import { Filesystem, Directory, Encoding } from '@capacitor/filesystem';

writeToCSVFile = async () => {
  await Filesystem.writeFile({
    path: 'text.csv',
    data: `0123445544,4556677`,
    directory: Directory.Documents,
    encoding: Encoding.UTF8
  });
};
  • Related