BAEL-5204: Change the font color of a cell with Apache POI (#11554)
* BAEL-5204: First commit "Change the font color of a cell with Apache POI" * BAEL-5204: Create class and unit test * BAEL-5204: finalize unit test * BAEL-5204: fix indent * BAEL-5204: add missing excel template
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package com.baeldung.poi.excel.cellstyle;
|
||||
|
||||
import org.apache.poi.hssf.util.HSSFColor.HSSFColorPredefined;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellStyle;
|
||||
import org.apache.poi.ss.usermodel.Font;
|
||||
import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
||||
import org.apache.poi.ss.usermodel.VerticalAlignment;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
|
||||
public class CellStyler {
|
||||
public CellStyle createWarningColor(Workbook workbook) {
|
||||
CellStyle style = workbook.createCellStyle();
|
||||
|
||||
Font font = workbook.createFont();
|
||||
font.setFontName("Courier New");
|
||||
font.setBold(true);
|
||||
font.setUnderline(Font.U_SINGLE);
|
||||
font.setColor(HSSFColorPredefined.DARK_RED.getIndex());
|
||||
style.setFont(font);
|
||||
|
||||
style.setAlignment(HorizontalAlignment.CENTER);
|
||||
style.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
return style;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user