Ionic React: Export Data To CSV File

Is there a way to export my data into CSV and download it to a phone device?

This is what I do to export using the | as delimator (not comma)

exportedText is a string containing the CSV data as a string.

   exportedText =
      '|No|Category|Subcategory|Question|Guide|DocxTAG|QuestionType|Aggregate|payload\n';
    exportedLines.forEach(line => {
      line.forEach(col => {
        exportedText = exportedText + '|' + col;
      });
      exportedText = exportedText + '\n';
    });

    // console.log('ExportedText: ', exportedText);

    const blob = new Blob([exportedText], { type: 'text/plain' });
    const url = window.URL.createObjectURL(blob);
    const link = document.createElement('a');
    if (link.download !== undefined) { // feature detection
      link.setAttribute('href', url);
      link.setAttribute('download', template.templateName + '' + Date.now() + '.csv');
      link.style.visibility = 'hidden';
      document.body.appendChild(link);
      link.click();
      document.body.removeChild(link);
    }
1 Like

Hi @Tommertom,

This works fantastic on the web, but it does not work on mobile. how to download it into the download folder on mobile?

U run capacitor or cordova - use filewriter plugins
On web, I am not sure you can control the output folder

1 Like