我使用ColdFusion和SpreadsheetNew,SpreadsheetAddRows,SpreadsheetFormatRows等函數創建Excel文件。根據我已閱讀的文檔位於here他們是顏色和fgcolor propery。對於兩者之間的區別我有點困惑。一個是文字顏色,另一個是背景顏色?我一直在使用fgcolor設置行的背景顏色。SpreadsheetFormatRows格式的顏色ColdFusion
// HEADER ROW FORMAT
formatHeaderRow = StructNew();
formatHeaderRow.fgcolor="royal_blue";
我的主要問題是,根據我可以在org.apache.poi.hssf.util.HSSFColor
顏色類作爲我的顏色提供任何價值的文檔。但是,我真的需要提供HEX值或RGB。我知道Excel可以處理它,因爲您可以在Excel的colorpicker中輸入。有沒有辦法爲我的行顏色輸入HEX或RGB值?
謝謝!
UPDATE
<cfscript>
// create XLSX workbook with a few cells
// and grab underlying POI objects
cfSheet = Spreadsheetnew("Sheet1", true);
poiWorkbook = cfSheet.getWorkBook();
poiSheet = poiWorkbook.getSheet("Sheet1");
// Create reusuable style objects
// NOTE: Excel limits the maximum number of styles allowed. So do not create a new
// style for every cell. Create distinct styles once, and apply to multiple cells/rows.
Color = createObject("java", "java.awt.Color");
// Style 1: Cell with background color (only)
backgroundOnlyStyle = poiWorkbook.createCellStyle();
backgroundOnlyStyle.setFillPattern(backgroundOnlyStyle.SOLID_FOREGROUND);
XSSFColor = createObject("java", "org.apache.poi.xssf.usermodel.XSSFColor");
backgroundOnlyStyle.setFillForegroundColor(XSSFColor.init(Color.decode("##055910")));
// Apply styles to cell A1. Note: POI indexes are 0-based
SpreadSheetSetCellValue(cfSheet, "background color only", 1, 1);
poiSheet.getRow(0).setRowStyle(backgroundOnlyStyle);
</cfscript>
<!--- stream it to the browser --->
<cfheader name="Content-Disposition" value="inline; filename=reportName.xlsx">
<cfcontent type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" variable="#SpreadSheetReadBinary(cfSheet)#">
的ColdFusion的任何特定版本。文檔鏈接去CF 9 –
嗯...好問題。 [我的答案](http://stackoverflow.com/a/37734884/104223)假定CF11。 CF9使用舊版本的POI,所以我不確定這些方法是否存在。 – Leigh
@JamesAMohler - 我使用CF 10,我相信Leigh的答案會奏效。謝謝! – Phil