共用方式為


Csv.Document

語法

 
Csv.Document(source as any, optional columns as any, optional delimiter as any, optional extraValues as nullable number, optional encoding as nullable number) as table

關於

以資料表形式傳回 CSV 文件的內容。

  • columns 可為 null、資料行數、資料行名稱清單、資料表類型或選項記錄。
  • delimiter 可以是單一字元、字元清單或 "" 值,表示資料列應該以連續空白字元分割。 預設值:","
  • 如需 extraValues 支援的值,請參閱 ExtraValues.Type
  • encoding 指定文字編碼類型。

如果針對 columns 指定了記錄 (且 delimiterextraValuesencoding 均為 null),則可提供下列記錄欄位:

  • Delimiter:單一字元數據行分隔符。 預設值:","
  • Columns:可為 null、資料行數、資料行名稱清單或資料表類型。 如果資料行數少於輸出中找到的資料行數,則會忽略額外的資料行。 如果資料行數高於輸出中找到的資料行數,則額外的資料行就會是 null。 未指定時,資料行數將取決於輸出中找到的項目。
  • Encoding:檔案的文字編碼。 預設值:65001 (UTF-8)。
  • CsvStyle:指定引號的處理方式。
  • QuoteStyle:指定如何處理以引號括住的分行符號。
    • QuoteStyle.Csv (預設):括住的分行符號會視為資料一部分,而不會做為目前資料列的結尾。
    • QuoteStyle.None:所有分行符號均會視為目前資料列的結尾,即使其出現在括住的值中也是一樣。

範例 1

使用資料行標頭處理 CSV 文字。

使用方式

let
    csv = Text.Combine({"OrderID,Item", "1,Fishing rod", "2,1 lb. worms"}, "#(cr)#(lf)")
in
    Table.PromoteHeaders(Csv.Document(csv))

輸出

Table.FromRecords({
    [OrderID = "1", Item = "Fishing rod"],
    [OrderID = "2", Item = "1 lb. worms"]
})

範例 2

處理具有多個分隔符的 CSV 文字。 在此範例中,第三個參數會指定要使用的分隔符模式 #|# ,而不是預設值。

使用方式

let
    csv = Text.Combine({"OrderID#|#Color", "1#|#Red", "2#|#Blue"}, "#(cr)#(lf)")
in
    Table.PromoteHeaders(Csv.Document(csv, null, "#|#"))

輸出

Table.FromRecords({
    [OrderID = "1", Color = "Red"],
    [OrderID = "2", Color = "Blue"]
})