so want write values csv file in 3 columns follows:
number of series firstval secondval 10 23 33 50 55 66 100 98 102
i stores myvalues in dictionary
var timeresults = new dictionary<string, dictionary<string, double>>();
and mycode this:
foreach (var resultset in timeresults) { var csv = new stringbuilder(); csv.appendline(string.format("number of timeseries;{0}", n)); foreach (var result in resultset.value) { csv.appendline(string.format("{0}.{1} (ms);{2}", resultset.key, result.key, result.value)); } file.appendalltext(@"d:/csv/results_" + resultset.key + ".csv", csv.tostring()); }
but this:
number of timeseries 10 add.firstval(ms) 74 add.secondval (ms) 12 number of timeseries 50 add.firstval (ms) 4 add.secondval(ms) 3 number of timeseries 100 add.firstval (ms) 6 add.secondval (ms) 6
all want tell go first line next column , write again. values in 1 column. how possible?
writing , reading cvs files not simple task itself. better use libraris csvhelper , a fast csv reader
also, dictionary not guarantee order in records. might problem you. consider using list instead or sort records criteria.
so, code this
stream = new memorystream(); writer = new streamwriter(stream); csvwriter = new csvwriter(writer); csvwriter.configuration.quoteallfields = false; csvwriter.configuration.hasheaderrecord = true; csvwriter.writefield("number of timeseries"); csvwriter.writefield("add.firstval(ms)"); csvwriter.writefield("add.secondval (ms)"); csvwriter.nextrecord(); foreach (var resultset in timeresults) { csvwriter.writefield(resultset.key); foreach (var result in resultset.value) { csvwriter.writefield(result.key); csvwriter.writefield(result.value)); } csvwriter.nextrecord(); } writer.flush(); // need data in stream. // dispose objects.
Comments
Post a Comment