当前位置: 首页>>代码示例>>C#>>正文


C# CsvParser.ReadOneRow方法代码示例

本文整理汇总了C#中CsvParser.ReadOneRow方法的典型用法代码示例。如果您正苦于以下问题:C# CsvParser.ReadOneRow方法的具体用法?C# CsvParser.ReadOneRow怎么用?C# CsvParser.ReadOneRow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CsvParser的用法示例。


在下文中一共展示了CsvParser.ReadOneRow方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateFieldHeaderinfo

        public static FieldHeadersInfo CreateFieldHeaderinfo(string newCSVFilePath, string LatFieldName = "", string LongFieldName = "", string DisplayFieldName="")
        {
            Row row = new Row();
              Row headerFields = new Row();
              using (CsvParser reader = new CsvParser(newCSVFilePath))
              {
            //Read the header line
            if (!reader.ReadOneRow(row))
              return null;
            headerFields = row;

            //Set up the field info
            List<FieldInfo> FieldInfos = new List<FieldInfo>();

            FieldInfo SelectedLatField = null;
            FieldInfo SelectedLongField = null;
            foreach (string fieldName in headerFields)
            {
              FieldInfo field;

              //If lat/long field has been set previously, use it
              if (fieldName == LatFieldName)
              {
            field = new FieldInfo(LatFieldName, true, false);
            SelectedLatField = field;
              }
              else if (fieldName == LongFieldName)
              {
            field = new FieldInfo(LongFieldName, false, true);
            SelectedLongField = field;
              }

              //Otherwise, try to find the fields that potentially contain location information
              else if (string.Compare(fieldName.ToLower(), "y") == 0)
              {
            field = new FieldInfo(fieldName, true, false);
            if (SelectedLatField == null)
              SelectedLatField = field;
              }
              else if (fieldName.ToLower().Contains("lat"))
              {
            field = new FieldInfo(fieldName, true, false);
            if (SelectedLatField == null)
              SelectedLatField = field;
              }
              else if (string.Compare(fieldName.ToLower(), "x") == 0)
              {
            field = new FieldInfo(fieldName, false, true);
            if (SelectedLongField == null)
              SelectedLongField = field;
              }
              else if (fieldName.ToLower().Contains("lon"))
              {
            field = new FieldInfo(fieldName, false, true);
            if (SelectedLongField == null)
              SelectedLongField = field;
              }
              else
            field = new FieldInfo(fieldName, false, false);

              FieldInfos.Add(field);
            }

            //Update properties to trigger UI change
            FieldHeadersInfo fieldHeadersInfo = new FieldHeadersInfo();
            fieldHeadersInfo.Fields = FieldInfos;
            fieldHeadersInfo.SelectedLatField = SelectedLatField == null ? fieldHeadersInfo.Fields.First() : SelectedLatField;
            fieldHeadersInfo.SelectedLongField = SelectedLongField == null ? fieldHeadersInfo.Fields.First() : SelectedLongField;
            fieldHeadersInfo.SelectedDisplayField = string.IsNullOrEmpty(DisplayFieldName) ? fieldHeadersInfo.Fields.First() : fieldHeadersInfo.Fields.First(f => f.FieldName == DisplayFieldName);

            fieldHeadersInfo.FieldsVisibility = Visibility.Visible;

            return fieldHeadersInfo;
              }
        }
开发者ID:Esri,项目名称:spatialsearch-opencsv-censusreport,代码行数:75,代码来源:Feature.cs

示例2: ParseCsvData

        /// <summary>
        /// Create features from the csv file
        /// </summary>
        private void ParseCsvData()
        {
            Features = new List<Feature>();

              Row row = new Row();
              try
              {
            using (CsvParser reader = new CsvParser(CsvFilePath))
            {
              //Read off the first line
              if (!reader.ReadOneRow(row))
            return;

              //Read a row
              while (reader.ReadOneRow(row))
              {
            //Read the fields
            IDictionary<string, object> Attributes = new Dictionary<string, object>();
            for (int i = 0; i < row.Count(); i++)
              Attributes.Add(FieldHeadersInfo.Fields[i].FieldName, row[i].ToString());

            Feature feature = new Feature(Attributes);

            Features.Add(feature);
              }
            }
              }
              catch (IOException)
              {
            MessageBox.Show("Error reading csv file");
              }
              catch (Exception)
              {
            MessageBox.Show("Error occured");
              }
        }
开发者ID:Esri,项目名称:spatialsearch-opencsv-censusreport,代码行数:39,代码来源:CsvWidget.xaml.cs


注:本文中的CsvParser.ReadOneRow方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。