Skip to content
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

Safari issue in exported csv #48

Open
aiyubaarav opened this issue Jan 12, 2022 · 4 comments
Open

Safari issue in exported csv #48

aiyubaarav opened this issue Jan 12, 2022 · 4 comments

Comments

@aiyubaarav
Copy link

I am using this library to generate the csv from array list in flutter web

When there is chrome works fine.
But in safari it gives me the csv data but not in different raw but in all the records in single row

If anyone has solution please provide

Thanks in advance

@close2
Copy link
Owner

close2 commented Jan 18, 2022

Is the output itself incorrect, or does Safari "render" the csv incorrectly.
End of line characters are unfortunately not standardized.
Are there multiple lines, if you save the generated file and open it in an editor?

What happens, if you change the eol character?

@paritosh1edison
Copy link

paritosh1edison commented Feb 10, 2022

I am facing same issue for Firefox browser.

Steps to reproduce:
flutter run -d web-server

Then open the provided localhost link in Firefox browser. (Here we can also open the same link in Chrome to test the difference in output)

then onButton click convert the list to csv using plugin and download the file. code for this:

//This code is for converting
final csv1 = const ListToCsvConverter(eol: "\n", delimitAllFields: true).convert([
      ["ab", DateFormat("MM/dd/yyyy").format(Timestamp.now().toDate()).toString()],
      ["ab", DateFormat("MM/dd/yyyy").format(Timestamp.now().toDate()).toString()],
    ], eol: "\n", delimitAllFields: true);

//This code is for downloading the file
AnchorElement(href: "data:text/plain;charset=utf-8,$csv1")
      ..setAttribute("download", "TickerData${DateTime.now()}.csv")
      ..click();

I downloaded files from both Firefox and Chrome and open it on Microsoft excel. Both files seems to be slightly different size. Also, I have tried using eol: "\n" and eol: "\t" It seems to work on chrome while Firefox is a no go.

I opened both files in notepad and chrome file is showing the second entry in next line while Firefox file showing everything in one line.

Let me know if any workaround for this one.

Thanks

@jamiecollinson
Copy link

I'm seeing the same issue on Safari (fine on Chrome) - has anyone figured out a workaround?

@yellowgraysu
Copy link

yellowgraysu commented Feb 13, 2023

I recently met this issue and here is a working example using blob:

import 'dart:convert';
import 'dart:html' as html;
import 'package:csv/csv.dart';

void downloadCSV(String fileName, List<List<String>> csvRows) {
  final csvData = const ListToCsvConverter().convert(csvRows);
  final bytes = utf8.encode(csvData);
  final blob = html.Blob([bytes]);
  final url = html.Url.createObjectUrlFromBlob(blob);
  html.AnchorElement(href: url)
    ..download = fileName
    ..click();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants