private CSVTitle FindTitleCache() { if (_title == null || _title._columnIndex != _columnIndex) { _title = _container.FindTitle(_columnIndex); } return(_title); }
/// <summary> /// 解析表头信息 /// </summary> /// <param name="sr"></param> protected virtual void ResolveTitle(StringReader sr) { string titleLine_ = sr.ReadLine(); string[] titles = titleLine_.Split(COMMA); for (int i = 0; i < titles.Length; i++) { CSVTitle title = new CSVTitle(titles[i], 0, i, _table, DataType.Unknown); _table.AddTitle(title); } }
/// <summary> /// 获取列数据类型 /// </summary> /// <param name="titleName"></param> /// <returns></returns> public DataType GetColumnType(string titleName) { CSVTitle title = FindTitle(titleName); if (title == null) { throw (new Exception(string.Format("Can not find column with title:{0}", titleName))); } return(title.dataType); }
/// <summary> /// 设置列数据类型 /// </summary> /// <param name="titleName"></param> /// <param name="type"></param> public void SetColumnType(string titleName, DataType type) { CSVTitle title = FindTitle(titleName); if (title == null) { return; } title.dataType = type; }
/// <summary> /// 获取指定标题的单元 /// </summary> /// <param name="titleName"></param> /// <returns></returns> public CSVEntry GetEntry(string titleName) { if (string.IsNullOrEmpty(titleName)) { return(null); } CSVTitle title_ = null; int titleIndex_ = _container.FindTitle(titleName, out title_); if (title_ == null) { return(null); } return(GetEntry(titleIndex_)); }
/// <summary> /// 查找指定名称的列标题,并返回列索引 /// </summary> /// <param name="titleName"></param> /// <param name="title"></param> /// <returns></returns> public int FindTitle(string titleName, out CSVTitle title) { for (int i = 0; i < _titles.Count; i++) { if (_titles[i] == null) { continue; } if (_titles[i].IsMatchTitle(titleName)) { title = _titles[i]; return(i); } } title = null; return(-1); }
internal void AddTitle(CSVTitle title) { _titles.Add(title); }