Beispiel #1
0
 public void SimpleCommaWrite()
 {
     MemoryStream stream = new MemoryStream();
     CsvFileWriter writer = new CsvFileWriter(stream);
     writer.WriteRow(new [] {"one", "two", "three"});
     StreamReader reader = new StreamReader(stream);
     stream.Position = 0;
     Assert.AreEqual("one,two,three", reader.ReadLine());
 }
Beispiel #2
0
 public void SpecialCharInValue()
 {
     MemoryStream stream = new MemoryStream();
     CsvFileWriter writer = new CsvFileWriter(stream);
     writer.WriteRow(new[] { "one,two", "t\"h\"\"ree" });
     StreamReader reader = new StreamReader(stream);
     stream.Position = 0;
     Assert.AreEqual("\"one,two\",\"t\"\"h\"\"\"\"ree\"", reader.ReadLine());
 }
Beispiel #3
0
        public void Export(string filePath, DataSet dataSet)
        {
            if(string.IsNullOrEmpty(filePath)) throw new ArgumentException("Empty filename for export");

            using(FileStream stream = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write))
            {
                CsvFileWriter writer = new CsvFileWriter(stream);
                DataTable table = dataSet.Tables[0];
                foreach (DataRow row in table.Rows)
                {
                    object[] rowItems = row.ItemArray;
                    string[] items = rowItems.Select(i => i.ToString())
                        .ToArray();
                    writer.WriteRow(items);
                }
            }
        }