问题描述
我有一个字典列表,具有相同的键列表,但值不同。有没有办法使用CSVHelper将其写入CSV文件?我在下面有示例代码,但是显然没有用。
static void Main(string[] args)
{
List<Dictionary<String,String>> records = new List<Dictionary<string,string>>();
Dictionary<String,String> data1 = new Dictionary<String,String>();
data1.Add("Name1","Value1");
data1.Add("Name2","Value2");
records.Add(data1);
Dictionary<String,String> data2 = new Dictionary<String,String>();
data2.Add("Name1","Value1");
data2.Add("Name2","Value2");
records.Add(data2);
using (var writer = new StreamWriter("e:\\temp\\test.csv"))
using (var csv = new CsvWriter(writer))
{
csv.WriteRecords(records);
//GEtting exception here
//CsvHelper.Configuration.CsvConfigurationException: 'Types that inherit IEnumerable cannot be auto mapped. Did you accidentally call GetRecord or WriteRecord which acts on a single record instead of calling GetRecords or WriteRecords which acts on a list of records?'
}
}
有什么办法解决吗?
谢谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)