StreamingspreadsheetProcess

免責事項

一部の古いメソッドでスプレッドシートの読み取りと書き込みを行う場合、呼び出し時にまだメモリに読み込まれていない行を操作しようとすると、ストリーミングスプレッドシートオブジェクトでは機能しないことがあります。

説明

ユーザ定義関数を行ごとに実行して、スプレッドシートからシートを読み込みます。

戻り値 

ストリーミングスプレッドシートオブジェクトを処理しました。 

履歴

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

シンタックス

streamingSpreadsheetProcess(source [, options],rowProcessor) 

パラメーター

名前 必須 オプション rowProcessor
source はい 文字列 読み込むスプレッドシートのファイルパス。
オプション いいえ 構造体

ストリーミングスプレッドシートを読み取るための設定が含まれる構造体。キーは次のとおりです。 

  • sheetName
  • 非同期
  • randomAccessWindowSize
rowProcessor はい UDF 各行に対して実行するメソッド。このメソッドは、スプレッドシートオブジェクトと行番号の 2 つのパラメーターを受け入れます。スプレッドシートオブジェクトを返す必要があります。

 

<cfscript> 
    theFile=GetDirectoryFromPath(GetCurrentTemplatePath()) & &quot;streamingSpreadsheetProcessInput.xlsx&quot;; 
    theFile1=GetDirectoryFromPath(GetCurrentTemplatePath()) & &quot;streamingSpreadsheetProcessOutput.xlsx&quot;; 
    obj = streamingSpreadsheetNew(&quot;theSheet&quot;,4) 
    SpreadsheetAddRow(obj,&quot;150,ENGL1,,&quot;,1,1); 
    SpreadsheetAddRow(obj,&quot;150,ENGL2,97,Poetry 1&quot;,2,1); 
    for ( i=3;i<=10000;i++){ 
        SpreadsheetAddRow(obj,&quot;150,ENGL,95,Poetry 1&quot;,i,1); 
    } 
    spreadsheetwrite(obj, theFile,&quot;,true,false); 
        myFormat = StructNew(); 
            myFormat.color = &quot;blue&quot;; 
            myFormat.bold = &quot;true&quot;; 
            myFormat.underline = &quot;true&quot;; 
            myFormat.alignment = &quot;center&quot;; 
            myFormat.font = &quot;Arial&quot;; 
        secondFormat = StructNew(); 
            secondFormat.color = &quot;red&quot;; 
            secondFormat.bold = &quot;true&quot;; 
            secondFormat.underline = &quot;true&quot;; 
            secondFormat.alignment = &quot;center&quot;; 
            secondFormat.font = &quot;Arial&quot;; 
        function func(spreadsheetObj, row) 
        { 
            if(row % 2 eq 1){ 
                SpreadsheetFormatRow(spreadsheetObj, myFormat, row); 
            }else{ 
                SpreadsheetFormatRow(spreadsheetObj, secondFormat, row); 
            } 
            return spreadsheetObj 
        } 

     processedSpreadsheet = StreamingSpreadsheetProcess(#theFile#, func) 
    writeoutput(processedSpreadsheet.SummaryInfo.SPREADSHEETTYPE) 
    spreadsheetwrite(processedSpreadsheet, &quot;#theFile1#&quot;, &quot;&quot;, &quot;yes&quot;, &quot;no&quot;) 
</cfscript> 

このスクリプトは、ストリーミングスプレッドシートを作成し、その行に条件付きフォーマットを適用して、処理されたスプレッドシートを保存します。書式設定オプションは構造体として定義されます。UDF 関数は、スプレッドシートオブジェクトと行インデックスをパラメーターとして受け取ります。この関数は、偶数および奇数の行インデックスをチェックし、それに応じてセルの書式を適用します。次に、streamingSpreadsheetProcess 関数は、書式設定 UDF を使用してスプレッドシートを処理します。作成されるスプレッドシートには、定義済みのフォーマットが適用されます。

出力 - 切り捨て

例 - 非同期の使用

<cfscript>
    theFile=GetDirectoryFromPath(GetCurrentTemplatePath()) & &quot;streamingSpreadsheetInput.xlsx&quot;;
    theFile1=GetDirectoryFromPath(GetCurrentTemplatePath()) &&quot;streamingSpreadsheetOutput.xlsx&quot;;
    obj = streamingSpreadsheetNew(&quot;theSheet&quot;,4)
    SpreadsheetAddRow(obj,&quot;150,ENGL1,1,&quot;,1,1);
    SpreadsheetAddRow(obj,&quot;150,ENGL2,97,Poetry 1&quot;,2,1);
    for ( i=3;i<=100000;i++){
        SpreadsheetAddRow(obj,&quot;150,ENGL,95,Poetry 1&quot;,i,1);
    }
    spreadsheetwrite(obj, theFile,&quot;,true,false);
        myFormat = StructNew();
        myFormat.color = &quot;blue&quot;;
        myFormat.bold = &quot;true&quot;;
        myFormat.underline = &quot;true&quot;;
        myFormat.alignment = &quot;center&quot;;
        myFormat.font = &quot;Arial&quot;;
        secondFormat = StructNew();
        secondFormat.color = &quot;red&quot;;
        secondFormat.bold = &quot;true&quot;;
        secondFormat.underline = &quot;true&quot;;
        secondFormat.alignment = &quot;center&quot;;
        secondFormat.font = &quot;Arial&quot;;
        
        
     function func(spreadsheetObj, row)
    {
        if(row % 2 eq 1){
            SpreadsheetFormatRow(spreadsheetObj, myFormat, row);
            
        }else{
            SpreadsheetFormatRow(spreadsheetObj, secondFormat, row);
        }
       
        return spreadsheetObj
    }
    function writeResult(spreadsheetObj) {
     
        spreadsheetwrite(spreadsheetObj, &quot;#theFile1#&quot;, &quot;&quot;, &quot;yes&quot;, &quot;no&quot;)
        
    }
    
 
    processedSpreadsheet = StreamingSpreadsheetProcess(#theFile#, func,{&quot;sheetName&quot;:&quot;theSheet&quot;, &quot;async&quot;:true})
    processedSpreadsheet.then(writeResult)
    data =processedSpreadsheet.get();
    writeoutput(data.SummaryInfo.SPREADSHEETTYPE)
    writeOutput(&quot; &quot;)
    writeoutput(data.SummaryInfo.SHEETNAMES)
    fileExist = FileExists(theFile1);
    writeOutput(&quot; &quot;)
    writeOutput(&quot;#fileExist#&quot;)
    writeOutput(&quot; &quot;)
</cfscript>

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

新規ユーザーの場合