public static void Sample_ReadExcel_WriteCsv() { string sampleDataPath = @"..\..\Samples\"; var watch = new Stopwatch(); using (var reader = new ExcelNativeAdapter()) { reader.FileName = sampleDataPath + @"cd-Daten.xls"; reader.SheetName = "Tabelle1"; reader.Connect(); using (var writer = new CsvAdapter()) { writer.FileName = Path.Combine(sampleDataPath, "cd-Daten_FromXls.csv"); watch.Start(); int lineCount = 0; reader.ReadData(30) .ForEach(x => { Console.WriteLine("Tablename=" + x.TableName + ", Count=" + x.Rows.Count); lineCount += x.Rows.Count; }) .Do(x => writer.WriteData(x, false)); watch.Stop(); Console.WriteLine("lineCount=" + lineCount + ", Time=" + watch.Elapsed); Console.ReadLine(); } reader.Disconnect(); } }
public static void Sample_ReadXml_WriteCsv_Address() { string sampleDataPath = @"..\..\Samples\"; var watch = new Stopwatch(); using (var reader = new XmlAdapter()) { reader.FileName = sampleDataPath + @"GetAddressResponse.xml"; reader.XPath = "/GetAddressResponse/GetAddressResult/result/address"; using (var writer = new CsvAdapter()) { writer.FileName = sampleDataPath + @"flatxml.csv"; watch.Start(); int lineCount = 0; reader.ReadData(30) .ForEach(x => { Console.WriteLine("Tablename=" + x.TableName + ", Count=" + x.Rows.Count); lineCount += x.Rows.Count; }) .Do(x => writer.WriteData(x)); watch.Stop(); Console.WriteLine("lineCount=" + lineCount + ", Time=" + watch.Elapsed); Console.ReadLine(); } } }
public static void Sample_ReadXml_WriteCsvs_Kunden() { string sampleDataPath = @"..\..\Samples\"; var watch = new Stopwatch(); using (var reader = new XmlAdapter()) { reader.FileName = sampleDataPath + @"kunden.xml"; reader.XPath = "/adre/kunde"; reader.ReadFormatter = new XmlToDataSetFormatter(); using (var writer = new CsvAdapter()) { writer.FileName = ""; watch.Start(); int lineCount = 0; reader.ReadData(30) .ForEach(x => { writer.FileName = sampleDataPath + x.TableName + ".csv"; Console.WriteLine("Tablename=" + x.TableName + ", Count=" + x.Rows.Count); lineCount += x.Rows.Count; }) .Do(x => writer.WriteData(x)); watch.Stop(); Console.WriteLine("lineCount=" + lineCount + ", Time=" + watch.Elapsed); Console.ReadLine(); } } }
public void Test_ReadXml_WriteCsv_Address() { using (var reader = new XmlAdapter()) { reader.FileName = Path.Combine(this.testDataPath, @"GetAddressResponse.xml"); reader.XPath = "/GetAddressResponse/GetAddressResult/result/address"; using (var writer = new CsvAdapter()) { writer.FileName = Path.Combine(this.resultPath, @"flatxml.csv"); int lineCount = 0; reader.ReadData(30) .ForEach(x => { Console.WriteLine("Tablename=" + x.TableName + ", Count=" + x.Rows.Count); lineCount += x.Rows.Count; }) .Do(x => writer.WriteData(x)); } } // check var targetlineCount = File.ReadLines(this.resultPath + @"flatxml.csv").Count(); Assert.AreEqual(3, targetlineCount); }
public static void Sample_ReadOracle_WriteCsv() { string sampleDataPath = @"..\..\Samples\"; var watch = new Stopwatch(); using (var reader = new DbAdapter()) { reader.ConnectionInfo = new OracleNativeDbConnectionInfo() { Database = "TESTDB01", UserName = "******", Password = "******", Host = "COMPUTER01" }; reader.TableName = "TB_DATA"; reader.Connect(); using (var writer = new CsvAdapter()) { writer.FileName = Path.Combine(sampleDataPath, "TB_DATA.csv"); watch.Start(); int lineCount = 0; reader.ReadData(30) .ForEach(x => { Console.WriteLine("Tablename=" + x.TableName + ", Count=" + x.Rows.Count); lineCount += x.Rows.Count; }) .Do(x => writer.WriteData(x, false)); watch.Stop(); Console.WriteLine("lineCount=" + lineCount + ", Time=" + watch.Elapsed); Console.ReadLine(); } reader.Disconnect(); } }
public static void Sample_String_To_CsvFile() { string data = @"Name;Address;Gpnr John;Main Road; 4711 Jeffrey;;4712 Mike;Hauptstr.1;4713"; string sampleDataPath = @"..\..\Samples\"; var watch = new Stopwatch(); using (Stream stream = StreamUtil.CreateStream(data)) { using (var reader = new CsvAdapter(stream)) { reader.Separator = ";"; using (var writer = new CsvAdapter()) { writer.FileName = sampleDataPath + "StringData.csv"; watch.Start(); int lineCount = 0; reader.ReadData(30) .ForEach(x => { Console.WriteLine("Tablename=" + x.TableName + ", Count=" + x.Rows.Count); lineCount += x.Rows.Count; }) .Do(x => writer.WriteData(x)); watch.Stop(); Console.WriteLine("lineCount=" + lineCount + ", Time=" + watch.Elapsed); Console.ReadLine(); } } } }
public static void Sample_DateFormats_Converted() { string sampleDataPath = @"..\..\Samples\"; var watch = new Stopwatch(); using (var reader = new CsvAdapter()) { reader.FileName = sampleDataPath + @"DataFormats.txt"; reader.Enclosure = "\""; reader.Separator = ";"; reader.ReadConverter.CountryColumnName = "CountryCode"; reader.ReadConverter.DefaultCulture = CultureInfo.CurrentCulture; reader.ReadConverter.ConverterDefinitions.Add(new ValueConverterDefinition("ReverseDate", typeof(DateTimeFormatConverter), "yyyyMMddHHmmss")); using (var writer = new CsvAdapter()) { writer.FileName = Path.Combine(Path.GetDirectoryName(reader.FileName), "DataFormats-Converted.txt"); writer.Enclosure = "\""; writer.Separator = ";"; watch.Start(); int lineCount = 0; reader.ReadData(30) .ForEach(x => { Console.WriteLine(x.ToString()); lineCount += x.Rows.Count; }) .Do(x => writer.WriteData(x, false)); watch.Stop(); Console.WriteLine("lineCount=" + lineCount + ", Time=" + watch.Elapsed); Console.ReadLine(); } } }