可以使用coldfusion来读取excel表格上单元格的背景颜色

我有一个Excel表,其中添加有一个红色的背景,变化有一个黄色的背景,删除是灰色的。 我希望做的是通过表单,并根据单元格的背景颜色,执行相关的数据库操作。

通常我会在自己的列中进行每种types的操作,或者添加另一列来确定操作。

我有什么select来获取电子表格对象中的“格式”?

谢谢

依靠细胞颜色听起来脆脆IMO。 指定一个明确的行动栏将是一个更好的方法国际海事组织。

这就是说,可以访问颜色。 但是,没有内置的CF方法。 你必须深入到基本的兴趣点。 首先遍历电子表格中的单元格 :

<cfscript> // get the sheet you want to read cfSheet = SpreadSheetRead("c:/path/to/somefile.xlsx"); workbook = cfSheet.getWorkBook(); sheetIndex = workbook.getActiveSheetIndex(); sheet = workbook.getSheetAt( sheetIndex ); // process the rows and columns rows = sheet.rowIterator(); while (rows.hasNext()) { currentRow = rows.next(); // loop through populated cells in this row cells = currentRow.cellIterator(); while (cells.hasNext()) { currentCell = cells.next(); // .... get color } } </cfscript> 

然后为每个单元格提取样式颜色 。 没有testing,但这样的事情应该工作。 (见XSSFColor )

  cellColor = currentCell.getCellStyle().getFillForegroundColorColor(); colorValue = cellColor.getARGBHex(); 

更新:

正如@Sean在评论中提到的,CF9没有上述方法。 不幸的是, getFillForegroundColorColor()getARGBHex()是在3.7左右的时候推出的,但CF捆绑了一个较早的版本:3.5(我认为)。 因此,您必须改用索引颜色方法(或升级POI JAR)。

  // only create once colors = createObject("java", "org.apache.poi.ss.usermodel.IndexedColors"); //.... cellColor = currentCell.getCellStyle().getFillForegroundColor(); if (cellColor == colors.RED.getIndex()) { WriteDump("This cell is RED. Do something..."); } 
Interesting Posts