Simple CSV Writer


/ Published in: C#
Save to your folder(s)



Copy this code and paste it in your HTML
  1. using System;
  2. using System.IO;
  3. using System.Text;
  4.  
  5. namespace RedHook.Utils
  6. {
  7. public class CsvWriter
  8. {
  9. public static void Write(string[][] data, string outputPath)
  10. {
  11. if (data == null) throw new ArgumentException("Parameter \"data\" cannot be null");
  12. if (outputPath == null) throw new ArgumentException("Parameter \"outputPath\" cannot be null");
  13.  
  14. StringBuilder sb = new StringBuilder();
  15. for (int i = 0; i < data.GetLength(0); i++)
  16. {
  17. if (data[i] == null) continue;
  18. sb.AppendLine(string.Join(",", data[i]));
  19. }
  20. File.WriteAllText(outputPath, sb.ToString());
  21. }
  22. }
  23. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.