2017-09-06 53 views
0

我想一個單元格的背景顏色設置爲這樣如何將單元格的背景顏色設置爲任何RGB值?

XSSFCellStyle instructionStyle = wb.createCellStyle(); 
    instructionStyle.setWrapText(true); 
    XSSFColor myColor = new XSSFColor(new java.awt.Color(0, 73,144)); 
    instructionStyle.setFillForegroundColor(myColor); 
    instructionStyle.setAlignment(HorizontalAlignment.CENTER); 

的RGB值,甚至將其編譯的是水平對齊一邊向中央有一個小區的look.can有人告訴我,沒有其他作用此代碼有什麼問題?謝謝

+2

請參見[快速指南填充和顏色](https://poi.apache.org/spreadsheet/quick-guide.html#Fills+and+colors)。請注意設置[CellStyle.setFillPattern](https://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/CellStyle.html#setFillPattern%28org.apache.poi.ss.usermodel.FillPatternType% 29)。所以對於實際的'apache poi'版本:'instructionStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);'。 @ apache-poi:更新你的快速指南! –

回答

1

你可以嘗試添加以下內容嗎?

instructionStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); 
+0

謝謝,那有效。但爲什麼? –

+0

Axel Richter在他的評論中回答了這個問題。這只是這個API的工作方式。默認填充模式不會填充... – Phil

相關問題