マニュアル キャンセル

CSVRead

 

説明

CSVファイルを読み取って順序付き構造体にします。

履歴

  • ColdFusion(2025 リリース):関数が追加されました。 

シンタックス

CSVRead(source,outputFormat,rowFilter [, csvFormatConfiguration])
CSVRead(source,outputFormat,rowFilter [, csvFormatConfiguration])
CSVRead(source,outputFormat,rowFilter [, csvFormatConfiguration]) 

パラメーター

名前

 

 

必須

 

 

Type

 

 

説明

 

 

source

 

 

はい

 

 

文字列 

 

 

CSVを読み取る必要があるファイルのパス。

 

  • outputFormat

 

 

 

 

はい

 

 

 

 

文字列 

 

 

入力 CSV から読み取るオブジェクトのタイプ。指定できる値は次のとおりです。
  • csvstring
  • arrayOfCFArray
  • arrayofjavaarray
  • arrayofstruct
  • query
  • xlsx
  • csvrecorditerable

rowFilter

 

 

いいえ

 

 

UDF

 

 

2つのパラメーター row array と row number を受け入れる UDF。true または false を返しますが、これらは行を読み取るかどうかを表します。 

csvFormatConfiguration

 

 

いいえ

 

 

Struct

 

 

CSV ファイルの情報を書き込むための設定が含まれる構造体。 

 

構造体では、次の値を使用できます。

Key

 

 

Value

 

 

allowMissingColumnNames

 

 

True の場合、ヘッダー行で列名が見つからなくなります。デフォルトは true です。 

 

 

commentMarker

 

 

行をコメントとして扱い、処理中に無視することを示すために使用される文字または文字のシーケンス。

 

 

delimiter

 

 

文字区切りを設定します。 

 

 

 

 

duplicateHeaderMode

 

 

ヘッダー名の重複動作を設定します。有効な値は次のとおりです。   

  • ALLOW_ALL
  • ALLOW_EMPTY
  • DISALLOW

 

 

 

encoding

 

 

CSV の値に使用されるエンコーディング。デフォルトは UTF-8 です。次のエンドポイントがサポートされています。
  • utf-8 
  • iso-8859-1
  • windows-1252 
  • us- ascii
  • shift_jis 
  • iso-2022-jp
  • euc -jp 
  • euc - kr
  • big5
  • euc - cn
  • utf -16  

escapeCharacter

 

 

エスケープ文字を設定します。 

 

 

headerComments

 

 

ヘッダーコメントセットを指定された値に設定します。コメントは、ヘッダーの前の先頭に印刷されます。 

 

 

header

 

 

ヘッダーになる行の値を設定します。 

 

 

ignoreEmptyLines

 

 

レコード間の空の行を無視する場合は True。空の行を空のレコードに変換する場合は False。デフォルトは True です。 

 

 

ignoreHeaderCase

 

 

パーサーのケースマッピングの動作を設定します。名前/値にアクセスする場合は True。変更を行わない場合は False。デフォルトは True です。 

 

 

 

 

nullString

 

 

 

 

CSVRead では nullString によって、指定された文字列が NULL 値に置き換えられます。 

 

 

quoteCharacter

 

 

引用文字を設定します。  

 

 

 

 

quoteMode

 

 

引用モードを設定します。有効な値は次のとおりです。   

  • ALL_NON_NULL

  • NON_NUMBER  

  • NONE

recordSeparator 

 

 

CSVレコードを区切る文字。例えば、カンマや /n などです。

 

 

skipHeaderRecord 

 

 

ファイルの先頭で、指定した数のレコード/行を無視します。値はブーリアンである必要があります。

 

 

trailingDelimiter 

 

 

末尾に区切り記号を追加する場合は True。デフォルトは True です。

 

 

trim 

 

 

前後の空白をトリミングする場合は true。デフォルトは True です。

 

 

次のマトリックスは、サポートされているさまざまな出力形式を示しています。

parameters

 

 

ArrayofCFArray

 

 

ArrayofJavaArray

 

 

xlsx

 

 

csvrecorditable

 

 

csvString

 

 

ArrayOfStruct

 

 

query

 

 

allowMissingColumnNames = false

 

 

NA 

 

 

NA

 

 

NA 

 

 

NA

 

 

〇 

 

 

はい

 

 

〇 

 

 

allowMissingColumnNames = true

 

 

NA 

 

 

NA

 

 

NA 

 

 

NA

 

 

〇 

 

 

はい

 

 

〇 

 

 

CommentMarker

 

 

〇 

 

 

はい

 

 

〇 

 

 

はい

 

 

〇 

 

 

はい

 

 

〇 

 

 

delimiter

 

 

〇 

 

 

はい

 

 

〇 

 

 

はい

 

 

〇 

 

 

はい

 

 

〇 

 

 

duplicateHeaderMode = ALLOW_ALL

 

 

NA 

 

 

NA

 

 

NA 

 

 

NA

 

 

〇 

 

 

はい

 

 

〇 

 

 

duplicateHeaderMode = ALLOW_EMPTY

 

 

NA 

 

 

NA

 

 

NA 

 

 

NA

 

 

〇 

 

 

はい

 

 

〇 

 

 

duplicateHeaderMode = DISALLOW

 

 

NA 

 

 

NA

 

 

NA 

 

 

NA

 

 

〇 

 

 

はい

 

 

〇 

 

 

escapeCharacter

 

 

〇 

 

 

はい

 

 

〇 

 

 

はい

 

 

NA 

 

 

はい

 

 

〇 

 

 

header

 

 

NA 

 

 

NA

 

 

NA 

 

 

NA

 

 

NA 

 

 

はい

 

 

〇 

 

 

ignoreEmptyLines=false

 

 

〇 

 

 

はい

 

 

〇 

 

 

はい

 

 

〇 

 

 

はい

 

 

〇 

 

 

ignoreEmptyLines=true

 

 

〇 

 

 

はい

 

 

〇 

 

 

はい

 

 

〇 

 

 

はい

 

 

〇 

 

 

ignoreHeaderCase=false

 

 

NA 

 

 

NA

 

 

NA 

 

 

NA

 

 

NA 

 

 

はい

 

 

NA 

 

 

ignoreHeaderCase=true

 

 

NA 

 

 

NA

 

 

NA 

 

 

NA

 

 

NA 

 

 

はい

 

 

NA 

 

 

nullString

 

 

〇 

 

 

はい

 

 

NA 

 

 

はい

 

 

NA 

 

 

はい

 

 

〇 

 

 

quoteCharacter

 

 

〇 

 

 

はい

 

 

〇 

 

 

はい

 

 

〇 

 

 

はい

 

 

〇 

 

 

recordSeparator

 

 

NA 

 

 

NA

 

 

NA 

 

 

NA

 

 

〇 

 

 

NA

 

 

NA 

 

 

skipHeaderRecord=false

 

 

NA 

 

 

NA

 

 

NA 

 

 

NA

 

 

〇 

 

 

はい

 

 

〇 

 

 

skipHeaderRecord=true

 

 

NA 

 

 

NA

 

 

NA 

 

 

NA

 

 

〇 

 

 

はい

 

 

〇 

 

 

trailingDelimiter=false

 

 

〇 

 

 

はい

 

 

〇 

 

 

はい

 

 

〇 

 

 

はい

 

 

〇 

 

 

trailingDelimiter=true

 

 

〇 

 

 

はい

 

 

〇 

 

 

はい

 

 

〇 

 

 

はい

 

 

〇 

 

 

trim

 

 

NA 

 

 

NA

 

 

NA 

 

 

NA

 

 

〇 

 

 

NA

 

 

NA 

 

 

例 1

CSV から csvstring として読み取ります。

<cfscript>
theFile=GetDirectoryFromPath(GetCurrentTemplatePath()) & &quot;customers-100.csv&quot;;
format=&quot;csvstring&quot;
csvObj = csvread(filepath = theFile, outputformat = format)
writeDump(csvObj)
</cfscript>
<cfscript> theFile=GetDirectoryFromPath(GetCurrentTemplatePath()) & &quot;customers-100.csv&quot;; format=&quot;csvstring&quot; csvObj = csvread(filepath = theFile, outputformat = format) writeDump(csvObj) </cfscript>
<cfscript> 
    theFile=GetDirectoryFromPath(GetCurrentTemplatePath()) & &quot;customers-100.csv&quot;; 
    format=&quot;csvstring&quot; 
    csvObj = csvread(filepath = theFile, outputformat = format) 
    writeDump(csvObj) 
</cfscript> 

出力 - 部分的

インデックス,顧客 ID,名,姓,会社,市区町村,国,電話 1,電話 2,メール,購読日,Web サイト 1,DD37Cf93aecA6Dc,Sheryl,Baxter,Rasmussen Group,East Leonard,Chile,229.077.5154,397.884.0519x718,zunigavanessa@smith.info,2020-08-24,http://www.stephenson.com/ 2,1Ef7b82A4CAAD10,Preston,Lozano,Vega-Gentry,East Jimmychester,Djibouti,5153435776,686-620-1820x944,vmata@colon.com,2021-04-23,http://www.hobbs.com/ 3,6F94879bDAfE5a6,Roy,Berry,Murillo-Perry,Isabelborough,Antigua and Barbuda,+1-539-402-0259,(496)978-3969x58947,beckycarr@hogan.com,2020-03-25,http://www.lawrence.com/ 4,5Cef8BFA16c5e3c,Linda,Olsen,&quot;Dominguez, Mcmillan and Donovan&quot;,Bensonview,Dominican Republic,001-808-617-6467x12895,+1-813-324-8756,stanleyblackwell@benson.org,2020-06-02,http://www.good-lyons.com/ 5,053d585Ab6b3159,Joanna,Bender,&quot;Martin, Lang and Andrade&quot;,West Priscilla,Slovakia (Slovak Republic),001-234-203-0635x76146,001-199-446-3860x3486,colinalvarado@miles.net,2021-04-17,https://goodwin-ingram.com/ 6,2d08FB17EE273F4,Aimee,Downs,Steele Group,Chavezborough,Bosnia and Herzegovina,(283)437-3886x88321,999-728-1637,louis27@gilbert.com,2020-02-25,http://www.berger.net/ 7,EA4d384DfDbBf77,Darren,Peck,&quot;Lester, Woodard and Mitchell&quot;,Lake Ana,Pitcairn Islands,(496)452-6181x3291,+1-247-266-0963x4995,tgates@cantrell.com,2021-08-24,https://www.le.com/ 8,0e04AFde9f225dE,Brett,Mullen,&quot;Sanford, Davenport and Giles&quot;,Kimport,Bulgaria,001-583-352-7197x297,001-333-145-0369,asnow@colon.com,2021-04-12,https://hammond-ramsey.com/ 9,C2dE4dEEc489ae0,Sheryl,Meyers,Browning-Simon,Robersonstad,Cyprus,854-138-4911x5772,+1-448-910-2276x729,mariokhan@ryan-pope.org,2020-01-13,https://www.bullock.net/ 10,8C2811a503C7c5a,Michelle,Gallagher,Beck-Hendrix,Elaineberg,Timor-Leste,739.218.2516x459,001-054-401-0347x617,mdyer@escobar.net,2021-11-08,https://arias.com/ 11,216E205d6eBb815,Carl,Schroeder,&quot;Oconnell, Meza and Everett&quot;,Shannonville,Guernsey,637-854-0256x825,114.336.0784x788,kirksalas@webb.com,2021-10-20,https://simmons-hurley.com/ 12,CEDec94deE6d69B,Jenna,Dodson,&quot;Hoffman, Reed and Mcclain&quot;,East Andrea,Vietnam,(041)737-3846,+1-556-888-3485x42608,mark42@robbins.com,2020-11-29,http://www.douglas.net/ 13,e35426EbDEceaFF,Tracey,Mata,Graham-Francis,South Joannamouth,Togo,001-949-844-8787,(855)713-8773,alex56@walls.org,2021-12-02,http://www.beck.com/ 14,A08A8aF8BE9FaD4,Kristine,Cox,Carpenter-Cook,Jodyberg,Sri Lanka,786-284-3358x62152,+1-315-627-1796x8074,holdenmiranda@clarke.com,2021-02-08,https://www.brandt.com/ 15,6fEaA1b7cab7B6C,Faith,Lutz,Carter-
インデックス,顧客 ID,名,姓,会社,市区町村,国,電話 1,電話 2,メール,購読日,Web サイト 1,DD37Cf93aecA6Dc,Sheryl,Baxter,Rasmussen Group,East Leonard,Chile,229.077.5154,397.884.0519x718,zunigavanessa@smith.info,2020-08-24,http://www.stephenson.com/ 2,1Ef7b82A4CAAD10,Preston,Lozano,Vega-Gentry,East Jimmychester,Djibouti,5153435776,686-620-1820x944,vmata@colon.com,2021-04-23,http://www.hobbs.com/ 3,6F94879bDAfE5a6,Roy,Berry,Murillo-Perry,Isabelborough,Antigua and Barbuda,+1-539-402-0259,(496)978-3969x58947,beckycarr@hogan.com,2020-03-25,http://www.lawrence.com/ 4,5Cef8BFA16c5e3c,Linda,Olsen,&quot;Dominguez, Mcmillan and Donovan&quot;,Bensonview,Dominican Republic,001-808-617-6467x12895,+1-813-324-8756,stanleyblackwell@benson.org,2020-06-02,http://www.good-lyons.com/ 5,053d585Ab6b3159,Joanna,Bender,&quot;Martin, Lang and Andrade&quot;,West Priscilla,Slovakia (Slovak Republic),001-234-203-0635x76146,001-199-446-3860x3486,colinalvarado@miles.net,2021-04-17,https://goodwin-ingram.com/ 6,2d08FB17EE273F4,Aimee,Downs,Steele Group,Chavezborough,Bosnia and Herzegovina,(283)437-3886x88321,999-728-1637,louis27@gilbert.com,2020-02-25,http://www.berger.net/ 7,EA4d384DfDbBf77,Darren,Peck,&quot;Lester, Woodard and Mitchell&quot;,Lake Ana,Pitcairn Islands,(496)452-6181x3291,+1-247-266-0963x4995,tgates@cantrell.com,2021-08-24,https://www.le.com/ 8,0e04AFde9f225dE,Brett,Mullen,&quot;Sanford, Davenport and Giles&quot;,Kimport,Bulgaria,001-583-352-7197x297,001-333-145-0369,asnow@colon.com,2021-04-12,https://hammond-ramsey.com/ 9,C2dE4dEEc489ae0,Sheryl,Meyers,Browning-Simon,Robersonstad,Cyprus,854-138-4911x5772,+1-448-910-2276x729,mariokhan@ryan-pope.org,2020-01-13,https://www.bullock.net/ 10,8C2811a503C7c5a,Michelle,Gallagher,Beck-Hendrix,Elaineberg,Timor-Leste,739.218.2516x459,001-054-401-0347x617,mdyer@escobar.net,2021-11-08,https://arias.com/ 11,216E205d6eBb815,Carl,Schroeder,&quot;Oconnell, Meza and Everett&quot;,Shannonville,Guernsey,637-854-0256x825,114.336.0784x788,kirksalas@webb.com,2021-10-20,https://simmons-hurley.com/ 12,CEDec94deE6d69B,Jenna,Dodson,&quot;Hoffman, Reed and Mcclain&quot;,East Andrea,Vietnam,(041)737-3846,+1-556-888-3485x42608,mark42@robbins.com,2020-11-29,http://www.douglas.net/ 13,e35426EbDEceaFF,Tracey,Mata,Graham-Francis,South Joannamouth,Togo,001-949-844-8787,(855)713-8773,alex56@walls.org,2021-12-02,http://www.beck.com/ 14,A08A8aF8BE9FaD4,Kristine,Cox,Carpenter-Cook,Jodyberg,Sri Lanka,786-284-3358x62152,+1-315-627-1796x8074,holdenmiranda@clarke.com,2021-02-08,https://www.brandt.com/ 15,6fEaA1b7cab7B6C,Faith,Lutz,Carter-
インデックス,顧客 ID,名,姓,会社,市区町村,国,電話 1,電話 2,メール,購読日,Web サイト 1,DD37Cf93aecA6Dc,Sheryl,Baxter,Rasmussen Group,East Leonard,Chile,229.077.5154,397.884.0519x718,zunigavanessa@smith.info,2020-08-24,http://www.stephenson.com/ 2,1Ef7b82A4CAAD10,Preston,Lozano,Vega-Gentry,East Jimmychester,Djibouti,5153435776,686-620-1820x944,vmata@colon.com,2021-04-23,http://www.hobbs.com/ 3,6F94879bDAfE5a6,Roy,Berry,Murillo-Perry,Isabelborough,Antigua and Barbuda,+1-539-402-0259,(496)978-3969x58947,beckycarr@hogan.com,2020-03-25,http://www.lawrence.com/ 4,5Cef8BFA16c5e3c,Linda,Olsen,&quot;Dominguez, Mcmillan and Donovan&quot;,Bensonview,Dominican Republic,001-808-617-6467x12895,+1-813-324-8756,stanleyblackwell@benson.org,2020-06-02,http://www.good-lyons.com/ 5,053d585Ab6b3159,Joanna,Bender,&quot;Martin, Lang and Andrade&quot;,West Priscilla,Slovakia (Slovak Republic),001-234-203-0635x76146,001-199-446-3860x3486,colinalvarado@miles.net,2021-04-17,https://goodwin-ingram.com/ 6,2d08FB17EE273F4,Aimee,Downs,Steele Group,Chavezborough,Bosnia and Herzegovina,(283)437-3886x88321,999-728-1637,louis27@gilbert.com,2020-02-25,http://www.berger.net/ 7,EA4d384DfDbBf77,Darren,Peck,&quot;Lester, Woodard and Mitchell&quot;,Lake Ana,Pitcairn Islands,(496)452-6181x3291,+1-247-266-0963x4995,tgates@cantrell.com,2021-08-24,https://www.le.com/ 8,0e04AFde9f225dE,Brett,Mullen,&quot;Sanford, Davenport and Giles&quot;,Kimport,Bulgaria,001-583-352-7197x297,001-333-145-0369,asnow@colon.com,2021-04-12,https://hammond-ramsey.com/ 9,C2dE4dEEc489ae0,Sheryl,Meyers,Browning-Simon,Robersonstad,Cyprus,854-138-4911x5772,+1-448-910-2276x729,mariokhan@ryan-pope.org,2020-01-13,https://www.bullock.net/ 10,8C2811a503C7c5a,Michelle,Gallagher,Beck-Hendrix,Elaineberg,Timor-Leste,739.218.2516x459,001-054-401-0347x617,mdyer@escobar.net,2021-11-08,https://arias.com/ 11,216E205d6eBb815,Carl,Schroeder,&quot;Oconnell, Meza and Everett&quot;,Shannonville,Guernsey,637-854-0256x825,114.336.0784x788,kirksalas@webb.com,2021-10-20,https://simmons-hurley.com/ 12,CEDec94deE6d69B,Jenna,Dodson,&quot;Hoffman, Reed and Mcclain&quot;,East Andrea,Vietnam,(041)737-3846,+1-556-888-3485x42608,mark42@robbins.com,2020-11-29,http://www.douglas.net/ 13,e35426EbDEceaFF,Tracey,Mata,Graham-Francis,South Joannamouth,Togo,001-949-844-8787,(855)713-8773,alex56@walls.org,2021-12-02,http://www.beck.com/ 14,A08A8aF8BE9FaD4,Kristine,Cox,Carpenter-Cook,Jodyberg,Sri Lanka,786-284-3358x62152,+1-315-627-1796x8074,holdenmiranda@clarke.com,2021-02-08,https://www.brandt.com/ 15,6fEaA1b7cab7B6C,Faith,Lutz,Carter- 

例 2

CSV から配列の配列として読み取ります。

<cfscript>
theFile=GetDirectoryFromPath(GetCurrentTemplatePath()) & &quot;customers-100.csv&quot;;
format=&quot;arrayofcfarray&quot;
csvObj = csvread(filepath = theFile, outputformat = format)
writeDump(csvObj)
</cfscript>
<cfscript> theFile=GetDirectoryFromPath(GetCurrentTemplatePath()) & &quot;customers-100.csv&quot;; format=&quot;arrayofcfarray&quot; csvObj = csvread(filepath = theFile, outputformat = format) writeDump(csvObj) </cfscript>
<cfscript> 
    theFile=GetDirectoryFromPath(GetCurrentTemplatePath()) & &quot;customers-100.csv&quot;; 
    format=&quot;arrayofcfarray&quot; 
    csvObj = csvread(filepath = theFile, outputformat = format) 
    writeDump(csvObj) 
</cfscript> 

例 3

CSV から XLSX として読み取ります

<cfscript>
theFile=GetDirectoryFromPath(GetCurrentTemplatePath()) & &quot;customers-100.csv&quot;;
format=&quot;xlsx&quot;
csvObj = csvread(filepath = theFile, outputformat = format)
writeDump(csvObj)
</cfscript>
<cfscript> theFile=GetDirectoryFromPath(GetCurrentTemplatePath()) & &quot;customers-100.csv&quot;; format=&quot;xlsx&quot; csvObj = csvread(filepath = theFile, outputformat = format) writeDump(csvObj) </cfscript>
<cfscript> 
    theFile=GetDirectoryFromPath(GetCurrentTemplatePath()) & &quot;customers-100.csv&quot;; 
    format=&quot;xlsx&quot; 
    csvObj = csvread(filepath = theFile, outputformat = format) 
    writeDump(csvObj) 
</cfscript> 

例 4

CSV から構造体の配列として読み取ります。

CSV の値を構造体の配列として読み取る場合は、CSV のヘッダーを配列として指定し、その配列を設定構造体に渡す必要があります。 

例を参照してください。

<cfscript>
theFile=GetDirectoryFromPath(GetCurrentTemplatePath()) & &quot;customers-100.csv&quot;;
format=&quot;arrayofstruct&quot;
headerArray=[&quot;Index&quot;,&quot; Customer Id&quot;, &quot;Name&quot;, &quot;Last Name&quot;, &quot;Company&quot;,&quot;City&quot;,&quot;Country&quot;,&quot;Phone 1&quot;, &quot;Phone 2&quot;, &quot;Email&quot;, &quot;Subscription Date&quot;,&quot;Website&quot;]
readconfiguration={
&quot;header&quot;=#headerArray#
}
csvObj = csvread(filepath = theFile, outputformat = format, csvformatconfiguration=readconfiguration)
writeDump(csvObj)
</cfscript>
<cfscript> theFile=GetDirectoryFromPath(GetCurrentTemplatePath()) & &quot;customers-100.csv&quot;; format=&quot;arrayofstruct&quot; headerArray=[&quot;Index&quot;,&quot; Customer Id&quot;, &quot;Name&quot;, &quot;Last Name&quot;, &quot;Company&quot;,&quot;City&quot;,&quot;Country&quot;,&quot;Phone 1&quot;, &quot;Phone 2&quot;, &quot;Email&quot;, &quot;Subscription Date&quot;,&quot;Website&quot;] readconfiguration={ &quot;header&quot;=#headerArray# } csvObj = csvread(filepath = theFile, outputformat = format, csvformatconfiguration=readconfiguration) writeDump(csvObj) </cfscript>
<cfscript> 
    theFile=GetDirectoryFromPath(GetCurrentTemplatePath()) & &quot;customers-100.csv&quot;; 
    format=&quot;arrayofstruct&quot; 
    headerArray=[&quot;Index&quot;,&quot; Customer Id&quot;, &quot;Name&quot;, &quot;Last Name&quot;, &quot;Company&quot;,&quot;City&quot;,&quot;Country&quot;,&quot;Phone 1&quot;, &quot;Phone 2&quot;, &quot;Email&quot;, &quot;Subscription Date&quot;,&quot;Website&quot;] 
    readconfiguration={ 
        &quot;header&quot;=#headerArray# 
    } 
    csvObj = csvread(filepath = theFile, outputformat = format, csvformatconfiguration=readconfiguration) 
    writeDump(csvObj) 
</cfscript>

ヘルプをすばやく簡単に入手

新規ユーザーの場合