我使用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