【发布时间】:2015-12-01 02:26:58
【问题描述】:
基本上尝试读取文件并将其从 7 列更改为 5 列,并更改日期格式。应该补充一点,我使用的是 linqpad,语言是 C# 语句。
代码:
string txtFolderPath = @"D:\Testing\BM\";
string[] files = Directory.GetFiles(txtFolderPath, "cplt.csv", SearchOption.AllDirectories);
//files.Dump();
foreach (string file in files)
{
// reading in csv file
var csvData = from row in new CpltData(@file, 1000000, 1000000, "")
//@"C:\Miu\Blue Fin III - A\Blue Fin III - A\cplt.csv"
select new
{
Period = row.Period,
IndexEltId = row.IndexEltId,
EventId = row.EventId,
Date = row.Date.ToString("dd-MMM-yyyy HH.mm.ss"),
Payout = row.Payout
};
//csvData.Dump();
Util.WriteCsv(csvData, @file);
}
错误消息:InvalidCastException 无法转换值 '8/22/2015 1:19:01 AM' 到第 2 行中的 DateTime
以下行发生错误:
var csvData = from row in new CpltData(@file, 1000000, 1000000, "")
CpltData(string csvFilePath, int noOfPeriods, double principal, string currency)
它是从某个 dll 导入的,不知道如何访问它:/
【问题讨论】:
-
你能显示
CpltData类的代码吗? -
你在哪一行得到这个异常?
-
@juharr - 见上文,也请见上文
-
无论
CplData是什么,这就是问题所在。如果不了解更多信息,我们无法真正帮助您。