本文整理汇总了C#中CsvReader.GetFieldHeaders方法的典型用法代码示例。如果您正苦于以下问题:C# CsvReader.GetFieldHeaders方法的具体用法?C# CsvReader.GetFieldHeaders怎么用?C# CsvReader.GetFieldHeaders使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CsvReader
的用法示例。
在下文中一共展示了CsvReader.GetFieldHeaders方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseToRows
public virtual ParsedCSVFile ParseToRows(WebResponse response)
{
using (var reader = new CsvReader(new StreamReader(response.GetResponseStream()), true))
{
return new ParsedCSVFile(GetRows(reader).ToArray(), reader.GetFieldHeaders().Select(StringExtensions.RemoveWhitespace).ToArray());
}
}
示例2: CsvReader
//Create List to store your CSV data
List<Models.Holidayhome> IDataParser.parseHolidayhomes()
{
CsvReader csv = new CsvReader(reader, true);
int fieldCount = csv.FieldCount;
List<Holidayhome> holidayhomes = new List<Holidayhome>();
String[] headers = csv.GetFieldHeaders();
Holidayhome exObj = new Holidayhome();
while (csv.ReadNextRecord())
{
for (int i = 0; i < fieldCount; i++)
{
if (headers[i].Equals("location")) {exObj.location = csv[i];}
else if (headers[i].Equals("address1")) { exObj.address1 = csv[i]; }
else if (headers[i].Equals("address2")) { exObj.address2 = csv[i]; }
else if (headers[i].Equals("country")) { exObj.country = csv[i]; }
else if (headers[i].Equals("email")) { exObj.email = csv[i]; }
else if (headers[i].Equals("contactno")){ exObj.contactno = csv[i];}
else if (headers[i].Equals("amenities")){ exObj.amenities = csv[i];}
}
holidayhomes.Add(exObj);
}
return holidayhomes;
}
示例3: parseBookings
//Create List to store your CSV data
public List<Models.Booking> parseBookings()
{
CsvReader csv = new CsvReader(reader, true);
int fieldCount = csv.FieldCount;
List<Booking> bookinglist = new List<Booking>();
String[] headers = csv.GetFieldHeaders();
while (csv.ReadNextRecord())
{
Booking exObj = new Booking();
for (int i = 0; i < fieldCount; i++)
{
if (headers[i].Equals("holidayhomeno")) { exObj.holidayhomeno = csv[i]; }
else if (headers[i].Equals("customername")) { exObj.customername = csv[i]; }
else if (headers[i].Equals("address")) { exObj.address = csv[i]; }
else if (headers[i].Equals("price")) { exObj.price = csv[i]; }
else if (headers[i].Equals("startdate")) { exObj.startdate = csv[i]; }
else if (headers[i].Equals("enddate")) { exObj.enddate = csv[i]; }
else if (headers[i].Equals("creditcardtype")) { exObj.creditcardtype = csv[i]; }
else if (headers[i].Equals("expirydate")) { exObj.expirydate = csv[i]; }
}
bookinglist.Add(exObj);
}
return bookinglist;
}
示例4: ReadCvsContent
private static void ReadCvsContent(string csvFilePath, out List<string[]> data)
{
TextReader textReader = null;
string[] headers;
try
{
textReader = new StreamReader(csvFilePath, Encoding.Default);
using (CsvReader csv = new CsvReader(textReader, true, CSV_DELIMITER))
{
headers = csv.GetFieldHeaders();
data = new List<string[]>();
while (csv.ReadNextRecord())
{
string[] items = new string[headers.Length];
for (int i = 0; i < headers.Length; i++)
{
items[i] = csv[i];
}
data.Add(items);
}
}
}
finally
{
if (textReader != null)
{
textReader.Close();
}
}
}
示例5: BatchProcessVanco2
private static int? BatchProcessVanco2(CsvReader csv, DateTime date, int? fundid)
{
var fundList = (from f in DbUtil.Db.ContributionFunds
orderby f.FundId
select f.FundId).ToList();
var cols = csv.GetFieldHeaders();
BundleHeader bh = null;
var firstfund = BatchImportContributions.FirstFundId();
var fund = fundid != null && fundList.Contains(fundid ?? 0) ? fundid ?? 0 : firstfund;
while (csv.ReadNextRecord())
{
var routing = "0";
var checkno = "0";
var account = csv[0];
var amount = csv[7];
var fundText = csv[11];
if (bh == null)
bh = BatchImportContributions.GetBundleHeader(date, DateTime.Now);
var f = DbUtil.Db.FetchOrCreateFund(fundText);
var bd = BatchImportContributions.AddContributionDetail(date, f.FundId, amount, checkno, routing, account);
bh.BundleDetails.Add(bd);
}
BatchImportContributions.FinishBundle(bh);
return bh.BundleHeaderId;
}
示例6: BatchProcessEnon
private static int? BatchProcessEnon(CsvReader csv, DateTime date, int? fundid)
{
var cols = csv.GetFieldHeaders();
BundleHeader bh = null;
var fid = fundid ?? BatchImportContributions.FirstFundId();
while (csv.ReadNextRecord())
{
var dt = csv[2].ToDate();
var amount = csv[7];
if (!amount.HasValue() || !dt.HasValue)
continue;
var account = csv[5];
var checkno = csv[6];
if (bh == null)
bh = BatchImportContributions.GetBundleHeader(dt.Value, DateTime.Now);
var bd = BatchImportContributions.AddContributionDetail(date, fid, amount, checkno, "", account);
bh.BundleDetails.Add(bd);
}
BatchImportContributions.FinishBundle(bh);
return bh.BundleHeaderId;
}
示例7: parseHolidayhomes
//Create List to store your CSV data
public List<Models.Holidayhome> parseHolidayhomes()
{
CsvReader csv = new CsvReader(reader, true);
int fieldCount = csv.FieldCount;
List<Holidayhome> holidaylist = new List<Holidayhome>();
String[] headers = csv.GetFieldHeaders();
while (csv.ReadNextRecord())
{
Holidayhome exObj = new Holidayhome();
for (int i = 0; i < fieldCount; i++)
{
if (headers[i].Equals("holidayhomeno")) {exObj.holidayhomeno = csv[i];}
else if (headers[i].Equals("address1")) { exObj.address1 = csv[i]; }
else if (headers[i].Equals("address2")) { exObj.address2 = csv[i]; }
else if (headers[i].Equals("country")) { exObj.country = csv[i]; }
else if (headers[i].Equals("email")) { exObj.email = csv[i]; }
else if (headers[i].Equals("contactno")){ exObj.contactno = csv[i];}
else if (headers[i].Equals("amenities")){ exObj.amenities = csv[i];}
else if (headers[i].Equals("price")) { exObj.price = csv[i]; }
}
holidaylist.Add(exObj);
}
return holidaylist;
}
示例8: BatchProcessOakbrookChurch
private static int? BatchProcessOakbrookChurch(CsvReader csv, DateTime date, int? fundid)
{
var cols = csv.GetFieldHeaders();
BundleHeader bh = null;
var qf = from f in DbUtil.Db.ContributionFunds
where f.FundStatusId == 1
orderby f.FundId
select f.FundId;
while (csv.ReadNextRecord())
{
if (csv[16] == "Credit")
{
if (bh != null)
BatchImportContributions.FinishBundle(bh);
bh = BatchImportContributions.GetBundleHeader(date, DateTime.Now);
continue;
}
if (bh == null)
bh = BatchImportContributions.GetBundleHeader(date, DateTime.Now);
var bd = new BundleDetail
{
CreatedBy = Util.UserId,
CreatedDate = DateTime.Now,
};
bd.Contribution = new Contribution
{
CreatedBy = Util.UserId,
CreatedDate = DateTime.Now,
ContributionDate = date,
FundId = fundid ?? qf.First(),
ContributionStatusId = 0,
ContributionTypeId = ContributionTypeCode.CheckCash,
};
string ck, rt, ac;
rt = csv[11];
ac = csv[13];
ck = csv[14];
bd.Contribution.ContributionAmount = csv[15].GetAmount();
bd.Contribution.CheckNo = ck;
var eac = Util.Encrypt(rt + "|" + ac);
var q = from kc in DbUtil.Db.CardIdentifiers
where kc.Id == eac
select kc.PeopleId;
var pid = q.SingleOrDefault();
if (pid != null)
bd.Contribution.PeopleId = pid;
bd.Contribution.BankAccount = eac;
bh.BundleDetails.Add(bd);
}
BatchImportContributions.FinishBundle(bh);
return bh.BundleHeaderId;
}
示例9: parseExchangeRates
public List<Models.ExchangeRate> parseExchangeRates()
{
CsvReader csv = new CsvReader(reader, true);
int fieldCount = csv.FieldCount;
List<ExchangeRate> exList = new List<ExchangeRate>();
ExchangeRate exObj = null;
String[] headers = csv.GetFieldHeaders();
while (csv.ReadNextRecord())
{
exObj = new ExchangeRate();
for (int i = 0; i < fieldCount; i++)
{
// this is where you actually create your dB object
if (headers[i].Equals("fromCurrency"))
{
exObj.fromCurrency = csv[i];
}
else if (headers[i].Equals("toCurrency"))
{
exObj.toCurrency = csv[i];
}
else if (headers[i].Equals("rate"))
{
exObj.rate = Convert.ToDouble(csv[i]);
}
}
exList.Add(exObj);
}
return exList;
//throw new NotImplementedException();
}
示例10: Parse
public virtual ParsedCSVFile Parse(TextReader source)
{
using (var reader = new CsvReader(source, true))
{
return new ParsedCSVFile(GetRows(reader).ToArray(), reader.GetFieldHeaders().Select(StringExtensions.RemoveWhitespace).ToArray());
}
}
示例11: getDataTableOfLogFile
public DataTable getDataTableOfLogFile(string txtFilePath, string fileName)
{
try
{
Logger.logdata(logforimportmtalog, string.Format("getDataTableOfLogFile(..) has been started at {0}", DateTime.Now.ToString()));
CsvReader csv = new CsvReader(new StreamReader(txtFilePath + "\\" + fileName), true);
DataTable csvDataTable = new DataTable();
string[] headers = csv.GetFieldHeaders();
for (int i = 0; i < headers.Length; i++)
{
csvDataTable.Columns.Add(headers[i], typeof(string));
}
int fieldCount = csv.FieldCount;
while (csv.ReadNextRecord())
{
DataRow row = csvDataTable.NewRow();
for (int i = 0; i < fieldCount; i++)
{
row[i] = csv[i];
}
csvDataTable.Rows.Add(row);
}
Logger.logdata(logforimportmtalog, string.Format("getDataTableOfLogFile(..) method has been ended at {0}", DateTime.Now.ToString()));
csv.Dispose();
return csvDataTable;
}
catch (Exception ex)
{
Logger.logError(logforimportmtalog, ex);
throw ex;
}
}
示例12: BatchProcessFbcFayetteville
private static int? BatchProcessFbcFayetteville(CsvReader csv, DateTime date, int? fundid)
{
var cols = csv.GetFieldHeaders();
BundleHeader bh = null;
var firstfund = FirstFundId();
var fund = fundid ?? firstfund;
while (csv.ReadNextRecord())
{
if (csv[6].StartsWith("Total Checks"))
continue;
var routing = csv[4];
var account = csv[5];
var checkno = csv[6];
var amount = csv[7];
if (bh == null)
bh = GetBundleHeader(date, DateTime.Now);
var bd = AddContributionDetail(date, fund, amount, checkno, routing, account);
bh.BundleDetails.Add(bd);
}
if (bh == null)
return null;
FinishBundle(bh);
return bh.BundleHeaderId;
}
示例13: CsvReader
List<Models.Parking> IDataParser.parseParking(String parkingtype)
{
CsvReader csv = new CsvReader(reader, true);
int fieldCount = csv.FieldCount;
List<Parking> facility = new List<Parking>();
String[] headers = csv.GetFieldHeaders();
while (csv.ReadNextRecord())
{
Parking exObj = new Parking();
for (int i = 0; i < fieldCount; i++)
{ // need to make this more robust for non expected values
if (headers[i].Equals("AREA_DESC")) {
exObj.AreaDesc = csv[i];
} else if (headers[i].Equals("ROADNAME")) {
exObj.RoadName = csv[i];
} else if (headers[i].Equals("TOTAL_SPACES")) {
exObj.TotalSpaces = csv[i];
} else if (headers[i].Equals("LAT")) {
exObj.Latitude = Convert.ToDouble(csv[i]);
} else if (headers[i].Equals("LONG")) {
exObj.Longtitude = Convert.ToDouble(csv[i]);
}
}
exObj.Description = parkingtype;
facility.Add(exObj);
}
return facility;
}
示例14: BatchProcessSilverdale
public static int? BatchProcessSilverdale(CsvReader csv, DateTime date, int? fundid)
{
var cols = csv.GetFieldHeaders();
BundleHeader bh = null;
var firstfund = FirstFundId();
var fund = fundid ?? firstfund;
while (csv.ReadNextRecord())
{
var excludecol = csv[12] == "Virtual Credit Item";
var routing = csv[18];
var account = csv[19];
var amount = csv[20];
var checkno = csv[24];
if (excludecol)
{
if (bh != null) FinishBundle(bh);
bh = GetBundleHeader(date, DateTime.Now);
continue;
}
if (bh == null)
bh = GetBundleHeader(date, DateTime.Now);
var bd = AddContributionDetail(date, fund, amount, checkno, routing, account);
bh.BundleDetails.Add(bd);
}
FinishBundle(bh);
return bh.BundleHeaderId;
}
示例15: CreateOrgDB
static void CreateOrgDB(string filePath)
{
// open the file "data.csv" which is a CSV file with headers
using (CsvReader csv =
new CsvReader(new StreamReader(filePath, Encoding.GetEncoding("gb2312")), true))
{
int fieldCount = csv.FieldCount;
FileStream fs = new FileStream("log.csv", FileMode.Append);
StreamWriter streamWriter = new StreamWriter(fs);
streamWriter.BaseStream.Seek(0, SeekOrigin.End);
int lineNumber = 0;
//int igore = 3; // igore the first 4 line ( 0 , 1, 2, 3)
while (csv.ReadNextRecord())
{
Console.Write("{0}: ", lineNumber);
lineNumber++;
//if (igore > 0) // igore the format
//{
// igore--;
// continue;
//}
if( csv.HasHeaders)
{
foreach (string header in csv.GetFieldHeaders())
Console.Write(header);
}
string record = "";
Boolean done = false;
for (int i = 0 ; i < 5; i++)
{
if (!String.IsNullOrEmpty(csv[0]))
{
Console.Write(" {0} ", csv[i]);
record = record + csv[i] + ",";
}
else
done = true;
}
if (!done)
{
streamWriter.WriteLine(record);
Console.WriteLine();
}
else
{
break;
}
}
streamWriter.Close();
}
}