5

cfscript スプレッドシートNew メソッドを使用して動的にスプレッドシートを作成しています。

すなわち

<cfscript>
  downloadDoc = spreadsheetNew("spreadSheetName");
  spreadsheetAddRow(downloadDoc,"spreadsheetCols");
  ....
</cfscript>

私が作成している列の 1 つには、ユーザーが空白の列に入力した値と現在の値 (別の列にある) との差の割合を示す式が含まれています。

私がこれを構築しているユーザーは、条件付き書式を追加して、値に基づいて数式セルの色を変更するように要求しました (つまり、変更が 20% を超える場合、または -20% 未満の場合、セルを赤にする必要があります)。数式に影響する値の 1 つがユーザーによってキー入力されるため、色の変更は関数ではなく Excel で行う必要があります。

Excel では簡単ですが、これを cfml によって生成される Excel ファイルに組み込む方法がわかりません。 ここに画像の説明を入力

私の質問は、これが cfml を使用して (cfscript または cfspreadsheet タグを介して) 可能かどうか、およびこれを行う方法を知っている人はいますか?

これをグーグルで検索しても何も見つかりませんでした.cfdocs.orgを検索しても何も見つかりませんでした.

4

1 に答える 1

5

Good news! It can be done (though not in CF10; the version of POI shipped with that is too low). Since you're on CF11, this will get you most of the way there. This particular demo turns anything greater than 100 red.

<cfset var poiSheet = downloadDoc.getWorkBook().getSheet("Sheet1")>
<cfset poiSheet.setFitToPage(true)>

<cfset comparison = CreateObject("java", "org.apache.poi.ss.usermodel.ComparisonOperator")>

<cfset rule = poiSheet.getSheetConditionalFormatting().createConditionalFormattingRule( comparison.GE, "100.0", javacast("null", ""))>
<cfset patternFmt = rule.createPatternFormatting()>
<cfset color = CreateObject("java", "org.apache.poi.ss.usermodel.IndexedColors")>

<cfset patternFmt.setFillBackgroundColor(javacast("short", color.RED.index))>

<cfset cellRangeAddress = CreateObject("java", "org.apache.poi.ss.util.CellRangeAddress")>
<cfset regions = [ cellRangeAddress.valueOf("A1:A6") ]>
<cfset poiSheet.getSheetConditionalFormatting().addConditionalFormatting(regions, rule)>

Taken from a combination of

(but note that the examples given in the latter don't really work)

于 2016-01-26T17:48:03.530 に答える