本文整理汇总了C#中CsvWriter.NextRecord方法的典型用法代码示例。如果您正苦于以下问题:C# CsvWriter.NextRecord方法的具体用法?C# CsvWriter.NextRecord怎么用?C# CsvWriter.NextRecord使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CsvWriter
的用法示例。
在下文中一共展示了CsvWriter.NextRecord方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteComponentToTheFile
private void WriteComponentToTheFile(CsvWriter writer, DataTemplateComposite outputDataTemplateComposite)
{
foreach (var component in outputDataTemplateComposite.Cast<DataTemplateComponent>())
{
if (component.GetType() == typeof(DataTemplateComposite))
{
writer.WriteField(""); writer.WriteField("");
writer.WriteField("Name"); writer.WriteField(component.Name);
writer.WriteField(""); writer.WriteField("");
writer.WriteField(""); writer.WriteField("");
writer.NextRecord();
WriteComponentToTheFile(writer, component as DataTemplateComposite);
}
else
{
if (component.Component == null)
{
writer.WriteField("Position"); writer.WriteField("n/a");
writer.WriteField("Name"); writer.WriteField(component.Name);
writer.WriteField("Type"); writer.WriteField("n/a");
writer.WriteField("Value"); writer.WriteField("n/a");
writer.NextRecord();
break;
}
writer.WriteField("Position"); writer.WriteField(component.Component.Pos);
writer.WriteField("Name"); writer.WriteField(component.Component.Name);
writer.WriteField("Type"); writer.WriteField(component.Component.TypeOfVariable.ToString());
writer.WriteField("Value"); writer.WriteField(component.Component.StringValue().Trim());
writer.NextRecord();
}
}
}
示例2: Main
static void Main(string[] args)
{
if (args.Length < 1)
{
System.Console.WriteLine("Syntax: ExportWMPMetadataToCSV.exe <outfile> [<top>]");
return;
}
int? top = null;
if (args.Length >= 2)
{
top = int.Parse(args[1]);
}
string output_filename = args[0];
var normalized_names = new Dictionary<string, string>();
foreach (var attr in all_attributes)
{
string name = attr.Replace("/", "_");
normalized_names[attr] = name;
}
var wmp = new WMPLib.WindowsMediaPlayerClass();
var item_collection = wmp.getAll();
using (var writer = File.CreateText(output_filename))
using (var csv = new CsvWriter(writer))
{
// Write CSV Header
for (int i = 0; i < all_attributes.Length; i++)
{
string h = normalized_names[all_attributes[i]];
csv.WriteField(h);
}
csv.NextRecord();
for (int i = 0; i < item_collection.count; i++)
{
if (top.HasValue && i>= top.Value)
{
break;
}
System.Console.WriteLine("WMP Item #: {0}", i + 1);
// write a csv line for each item in the collection
var item = item_collection.get_Item(i);
for (int j = 0; j < all_attributes.Length; j++)
{
var attr_value = item.getItemInfo(all_attributes[j]) ?? "";
csv.WriteField(attr_value);
}
csv.NextRecord();
}
}
System.Console.WriteLine("DONE");
}
示例3: writeEmailListToCSV
private void writeEmailListToCSV(String[] emails, String CSVFileName)
{
try
{
using (var sr = new StreamWriter(@CSVFileName))
{
var writer = new CsvWriter(sr);
/*-------------------------
* HEADER
* -----------------------*/
writer.WriteField("Email Address");
writer.NextRecord();
/*-------------------------
* Email List
* -----------------------*/
for(int i=0; i< emails.Length;i++)
{
writer.WriteField(emails[i]);
writer.NextRecord();
}
}
}
catch(Exception e)
{Console.WriteLine("CSV write failed");}
}
示例4: Output
public void Output(TableInfo table, DataTable data)
{
var outputFilename = string.Format("{0}.csv", data.TableName);
_logger.Info("Writing data to {0}...", outputFilename);
using (var stringWriter = new StringWriter())
using (var csv = new CsvWriter(stringWriter))
{
foreach (DataColumn column in data.Columns)
{
csv.WriteField(column.ColumnName);
}
csv.NextRecord();
foreach (var row in data.AsEnumerable())
{
foreach (var item in row.ItemArray)
{
csv.WriteField(item.ToString());
}
csv.NextRecord();
}
File.WriteAllText(outputFilename, stringWriter.ToString());
}
_logger.Info("Done writing data to {0}.", outputFilename);
}
示例5: WriteDynamicExpandoObjectTest
public void WriteDynamicExpandoObjectTest()
{
using( var stream = new MemoryStream() )
using( var reader = new StreamReader( stream ) )
using( var writer = new StreamWriter( stream ) )
using( var csv = new CsvWriter( writer ) )
{
dynamic obj = new ExpandoObject();
obj.Id = 1;
obj.Name = "one";
csv.WriteRecord( obj );
csv.NextRecord();
obj = new ExpandoObject();
obj.Id = 2;
obj.Name = "two";
csv.WriteRecord( obj );
csv.NextRecord();
writer.Flush();
stream.Position = 0;
var expected = "Id,Name\r\n";
expected += "1,one\r\n";
expected += "2,two\r\n";
Assert.AreEqual( expected, reader.ReadToEnd() );
}
}
示例6: Run
public void Run(IEnumerable<Company> organisations, string filePath)
{
var conf = new CsvHelper.Configuration.CsvConfiguration();
conf.UseInvariantCulture = true;
var sb = new StringBuilder();
using (var streamWriter = new StringWriter(sb))
using (var writer = new CsvWriter(streamWriter, conf))
{
writer.WriteField("Name");
writer.WriteField("Email");
writer.WriteField("Location");
writer.WriteField("Size");
writer.WriteField("Industry");
writer.WriteField("Url");
writer.WriteField("Bilanz2011");
writer.WriteField("Bilanz2012");
writer.NextRecord();
foreach (var orga in organisations)
{
writer.WriteField(orga.Name);
writer.WriteField(orga.Email);
writer.WriteField(orga.Location);
writer.WriteField(orga.Size);
writer.WriteField(orga.Industry);
writer.WriteField(orga.Url);
writer.WriteField(orga.WelfareBalanceFor2011);
writer.WriteField(orga.WelfareBalanceFor2012);
writer.NextRecord();
}
File.WriteAllText(filePath, sb.ToString(), Encoding.Default);
}
}
示例7: GetCSV
public async Task<string> GetCSV(IList<DynamicTableEntity> results, string[] headings, bool addHeaderRow)
{
using (var memoryStream = new MemoryStream())
{
using (var streamWriter = new StreamWriter(memoryStream))
{
using (var streamReader = new StreamReader(memoryStream))
{
using (var writer = new CsvWriter(streamWriter))
{
for (int i = 0; i < results.Count; i++)
{
var item = results[i];
if (i == 0)
{
if (addHeaderRow)
{
writer.WriteField("PartitionKey");
writer.WriteField("RowKey");
writer.WriteField("TimeStamp");
foreach (var key in headings)
{
writer.WriteField(key);
}
writer.NextRecord();
}
}
writer.WriteField(item.PartitionKey);
writer.WriteField(item.RowKey);
writer.WriteField(item.Timestamp);
foreach (var key in headings)
{
var prop = item.Properties.ContainsKey(key)
? GetValue(item.Properties[key]).ToString()
: string.Empty;
writer.WriteField(prop);
}
writer.NextRecord();
}
streamWriter.Flush();
memoryStream.Position = 0;
return await streamReader.ReadToEndAsync();
}
}
}
}
}
示例8: MergerToOneCsv
public void MergerToOneCsv()
{
bool b = true;
foreach (string item in CsvFilesPath)
{
using (var reader = new CsvReader(new StreamReader(item)))
{
if (FirstLine.Count <= 0)
{
reader.Read();
FirstLine = new List<string>(reader.FieldHeaders);
}
if (b)
{
using (var writer = new CsvWriter(new StreamWriter(_strBatchResult, true)))
{
foreach (string s in FirstLine)
{
writer.WriteField(s);
}
writer.NextRecord();
foreach (string s in FirstLine)
{
writer.WriteField(reader.GetField(s));
}
writer.NextRecord();
}
b = false;
}
while (reader.Read())
{
using (var writer = new CsvWriter(new StreamWriter(_strBatchResult, true)))
{
foreach (string strHeader in reader.FieldHeaders)
{
Console.WriteLine(reader.GetField(strHeader));
}
foreach (string s in FirstLine)
{
writer.WriteField(reader.GetField(s));
}
writer.NextRecord();
}
}
}
}
}
示例9: WriteFieldTest
public void WriteFieldTest()
{
var stream = new MemoryStream();
var writer = new StreamWriter( stream );
var csv = new CsvWriter( writer );
var date = DateTime.Now.ToString();
var guid = Guid.NewGuid().ToString();
csv.WriteField( "one" );
csv.WriteField( "one, two" );
csv.WriteField( "one \"two\" three" );
csv.WriteField( " one " );
csv.WriteField( date );
csv.WriteField( (short)1 );
csv.WriteField( 1 );
csv.WriteField( (long)1 );
csv.WriteField( (float)1 );
csv.WriteField( (double)1 );
csv.WriteField( guid );
csv.NextRecord();
var reader = new StreamReader( stream );
stream.Position = 0;
var data = reader.ReadToEnd();
Assert.AreEqual( "one,\"one, two\",\"one \"\"two\"\" three\",\" one \"," + date + ",1,1,1,1,1," + guid + "\r\n", data );
}
示例10: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
string methodName = Request["MethodName"];
string afterDate = Request["AfterDate"];
Response.ContentType = "text/plain";
using (SqlConnection conn = new SqlConnection(profilesdb))
{
conn.Open();
SqlCommand dbcommand = new SqlCommand("[UCSF.].[ReadActivityLog]", conn);
dbcommand.CommandType = CommandType.StoredProcedure;
dbcommand.Parameters.Add(methodName != null ? new SqlParameter("@methodName", methodName) : new SqlParameter("@methodName", DBNull.Value));
dbcommand.Parameters.Add(afterDate != null ? new SqlParameter("@afterDT", afterDate) : new SqlParameter("@afterDT", DBNull.Value));
using (SqlDataReader dbreader = dbcommand.ExecuteReader(CommandBehavior.CloseConnection))
{
CsvWriter writer = new CsvWriter(Response.Output);
while (dbreader.Read())
{
writer.WriteField(dbreader.GetInt32(0));
writer.WriteField(dbreader[1].ToString());
writer.WriteField(dbreader[2].ToString());
writer.WriteField(dbreader[3].ToString());
writer.WriteField(dbreader.GetDateTime(4));
writer.WriteField(dbreader[5].ToString());
writer.WriteField(dbreader[6].ToString());
writer.WriteField(dbreader[7].ToString());
writer.NextRecord();
}
Response.Output.Flush();
}
}
}
示例11: InitCsvFile
public void InitCsvFile()
{
const string subPath = "Analyzer";
var isExists = Directory.Exists(subPath);
if (!isExists) Directory.CreateDirectory(subPath);
File.Create(_filePath).Close();
using (var streamWriter = File.AppendText(_filePath))
{
var writer = new CsvWriter(streamWriter);
writer.Configuration.Delimiter = ";";
writer.WriteField("GENERAL:AXIS:X");
for (var i = 1; i <= Analyzer.AnalyzerChannels.HighestId; i++)
{
var fieldString = "";
var id = i;
foreach (var analyzerChannel in Analyzer.AnalyzerChannels.Children.Where(analyzerChannel => analyzerChannel.AnalyzerObservableVariable != null && analyzerChannel.Id == id))
{
fieldString = "VARIABLE:" + analyzerChannel.AnalyzerObservableVariable.Name + ":[" +
analyzerChannel.AnalyzerObservableVariable.Unit + "]:AXIS:Y";
}
writer.WriteField(fieldString != "" ? fieldString : "VARIABLE:EMPTY:AXIS:Y");
}
writer.NextRecord();
streamWriter.Close();
}
}
示例12: GenerateCsvStub
public void GenerateCsvStub(string targetPath)
{
Program.Write("Generating CSV stub ...");
using (var stream = new StreamWriter(targetPath, false, Encoding.UTF8))
{
var writer = new CsvWriter(stream, CsvService.GetDefaultCsvConfiguration());
var dummyLine = new Dictionary<string, string>();
foreach (var column in _configuration.Columns)
{
dummyLine[column.Header] = "";
}
foreach (var field in dummyLine.Keys)
{
writer.WriteField(field);
}
writer.NextRecord();
foreach (var field in dummyLine.Keys)
{
writer.WriteField(dummyLine[field]);
}
}
Program.Write("CSV stub saved at '" + targetPath + "'.");
}
示例13: GetFile
private static byte[] GetFile()
{
var items = new List<Order>()
{
new Order()
{
Id = 1,
ShippingMethodName= "Test",
}
};
using (var ms = new MemoryStream())
using (var sw = new StreamWriter(ms))
using (var w = new CsvWriter(sw))
{
w.WriteField("Order Id");
w.WriteField("Shipping Method");
w.WriteField("Tracking Number");
w.NextRecord();
foreach (var item in items)
{
w.WriteField(item.Id);
w.WriteField(item.ShippingMethodName);
w.WriteField("Courier");
w.NextRecord();
}
sw.Flush();
var file = ms.ToArray();
sw.Close();
return file;
}
}
示例14: Main
private static void Main()
{
using (var csv = new CsvWriter(new StreamWriter("results.csv", false, Encoding.UTF8)))
{
WriteHeader(csv);
var languagesToTest = new[] {Languages.EnglishUK, Languages.GermanGermany};
foreach (var language in languagesToTest)
{
var results = new AutoCorrectTester(language).Run();
foreach (var result in results)
{
foreach (var testResult in result.Results)
{
csv.WriteField(language);
csv.WriteField(result.AutoCompleteMethod);
csv.WriteField(result.MemorySize);
csv.WriteField(testResult.Misspelling);
csv.WriteField(testResult.TargetWord);
csv.WriteField(testResult.CharactersTyped);
csv.WriteField(testResult.TargetWord.Length);
csv.WriteField(testResult.TimeTaken.Milliseconds);
csv.WriteField(testResult.CharactersTyped != -1
? (double) testResult.CharactersTyped/testResult.TargetWord.Length
: 2d);
csv.NextRecord();
}
}
}
}
}
示例15: DownloadCSVTemplate
/// <summary>
/// Downloads the CSV template for assignments.
/// </summary>
/// <author> Cristian Araya Fuentes </author>
/// <returns> Csv file </returns>
public FileResult DownloadCSVTemplate()
{
String vTemplateFileName = "plantillaAsignacion.csv";
byte[] vFileSize;
int vIDEntity = getEntityID(Request.Cookies["Entidad"].Value);
int vIDPeriod = Int32.Parse(Request.Cookies["Periodo"].Value);
IEnumerable<DataCSV> vGroups = getGroupesPeriod(vIDPeriod, vIDEntity);
using (Stream memoryStream = new MemoryStream())
{
StreamWriter streamWriter = new StreamWriter(memoryStream, Encoding.UTF8);
var vWriter = new CsvWriter(streamWriter);
vWriter.Configuration.Encoding = Encoding.UTF8;
//Write the CSV's file header
vWriter.WriteHeader(typeof(DataCSV));
//Write each group
foreach (DataCSV group in vGroups)
{
vWriter.WriteRecord(group);
}
vWriter.NextRecord();
streamWriter.Flush();
memoryStream.Flush();
memoryStream.Position = 0;
vFileSize = new byte[memoryStream.Length];
memoryStream.Read(vFileSize, 0, vFileSize.Length);
streamWriter.Close();
streamWriter.Dispose();
}
return File(vFileSize, System.Net.Mime.MediaTypeNames.Application.Octet, vTemplateFileName);
}