2016-11-10 52 views
0

我一直試圖讓我的標題被引用,但不幸的是我不知道如何。 [FieldQuoted('"', QuoteMode.AlwaysQuoted, MultilineMode.NotAllow)] FileHelpers中的引用標題

僅適用於數據,而不是頭,雖然我可以只:

  UserSubEngine.HeaderText = '"WHATEVER,WHATEVER,WHATEVER"'; 

我不想在一行寫出來的23個不同的標題。

我寧願使用:

  UserSubEngine.HeaderText = UserSubEngine.GetFileHeader(); 

,如果在所有可能的。

有什麼建議嗎?

回答

0

HeaderText是要走的路。 FieldQuoted不會影響GetFileHeader()的輸出。

以下是source code的相關部分。

/// <summary> 
/// Builds a line with the name of the fields, for a delimited files it 
/// uses the same delimiter, for a fixed length field it writes the 
/// fields names separated with tabs 
/// </summary> 
/// <returns>field names structured for the heading of the file</returns> 
public string GetFileHeader() 
{ 
    var delimiter = "\t"; 

    if (RecordInfo.IsDelimited) 
     delimiter = ((DelimitedRecordOptions) Options).Delimiter; 

    var res = new StringBuilder(); 
    for (int i = 0; i < RecordInfo.Fields.Length; i++) { 
     if (i > 0) 
      res.Append(delimiter); 

     var field = RecordInfo.Fields[i]; 
     res.Append(field.FieldCaption != null 
      ? field.FieldCaption 
      : field.FieldFriendlyName); 
    } 

    return res.ToString(); 
} 
+0

的HeaderText是不是我想用什麼,那是可笑笨拙,嚴重編程的方式,必須有一個更好的解決方案。有 –

+0

有。這對你來說是一個很好的機會[在這裏](https://github.com/MarcosMeli/FileHelpers)。修復上面的'GetFileHeader()'並提交一個拉請求。 – shamp00