【发布时间】:2016-06-09 13:40:00
【问题描述】:
我正在使用 ColdFusion 和 SpreadsheetNew、SpreadsheetAddRows、SpreadsheetFormatRows 等函数创建 Excel 文件。根据我阅读的位于here 的文档,它们是颜色和fgcolor 的属性。我有点困惑,这两者之间的区别是什么。一种是文本颜色,另一种是背景颜色吗?我一直在使用 fgcolor 来设置行的背景颜色。
// HEADER ROW FORMAT
formatHeaderRow = StructNew();
formatHeaderRow.fgcolor="royal_blue";
我的主要问题是,根据文档,我可以提供 org.apache.poi.hssf.util.HSSFColor 颜色类中的任何值作为我的颜色。但是,我真的需要提供 HEX 值或 RGB。我知道 Excel 可以处理它,因为您可以在 excel 的颜色选择器中输入任何一个。有没有办法为我的行颜色输入 HEX 或 RGB 值?
谢谢!
更新
<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
-
嗯...好问题。 My answer 假定为 CF11。 CF9 使用的是旧版本的 POI,所以我不确定是否存在相同的方法。
-
@JamesAMohler - 我正在使用 CF 10,我相信 Leigh 的回答会奏效。谢谢!
标签: coldfusion apache-poi coldfusion-10 cfspreadsheet