Java Code Examples for org.apache.poi.hssf.usermodel.HSSFCellStyle#setFillForegroundColor()

The following examples show how to use org.apache.poi.hssf.usermodel.HSSFCellStyle#setFillForegroundColor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: POIUtils.java    From ermasterr with Apache License 2.0 7 votes vote down vote up
public static HSSFCellStyle copyCellStyle(final HSSFWorkbook workbook, final HSSFCellStyle style) {

        final HSSFCellStyle newCellStyle = workbook.createCellStyle();

        newCellStyle.setAlignment(style.getAlignment());
        newCellStyle.setBorderBottom(style.getBorderBottom());
        newCellStyle.setBorderLeft(style.getBorderLeft());
        newCellStyle.setBorderRight(style.getBorderRight());
        newCellStyle.setBorderTop(style.getBorderTop());
        newCellStyle.setBottomBorderColor(style.getBottomBorderColor());
        newCellStyle.setDataFormat(style.getDataFormat());
        newCellStyle.setFillBackgroundColor(style.getFillBackgroundColor());
        newCellStyle.setFillForegroundColor(style.getFillForegroundColor());
        newCellStyle.setFillPattern(style.getFillPattern());
        newCellStyle.setHidden(style.getHidden());
        newCellStyle.setIndention(style.getIndention());
        newCellStyle.setLeftBorderColor(style.getLeftBorderColor());
        newCellStyle.setLocked(style.getLocked());
        newCellStyle.setRightBorderColor(style.getRightBorderColor());
        newCellStyle.setRotation(style.getRotation());
        newCellStyle.setTopBorderColor(style.getTopBorderColor());
        newCellStyle.setVerticalAlignment(style.getVerticalAlignment());
        newCellStyle.setWrapText(style.getWrapText());

        final HSSFFont font = workbook.getFontAt(style.getFontIndex());
        newCellStyle.setFont(font);

        return newCellStyle;
    }
 
Example 2
Source File: TitleStyleBuilder.java    From bdf3 with Apache License 2.0 6 votes vote down vote up
private HSSFCellStyle createHSSFCellStyle(Workbook wb, int[] bgColor, int[] fontColor, int fontSize) {
	HSSFWorkbook workbook = (HSSFWorkbook) wb;
	HSSFPalette palette = workbook.getCustomPalette();
	
	palette.setColorAtIndex((short) 9, (byte) fontColor[0], (byte) fontColor[1], (byte) fontColor[2]);
	palette.setColorAtIndex((short) 10, (byte) bgColor[0], (byte) bgColor[1], (byte) bgColor[2]);

	HSSFFont titleFont = workbook.createFont();
	titleFont.setCharSet(HSSFFont.DEFAULT_CHARSET);
	titleFont.setFontName("宋体");
	titleFont.setColor((short) 9);
	titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
	titleFont.setFontHeightInPoints((short) fontSize);

	HSSFCellStyle titleStyle = (HSSFCellStyle) createBorderCellStyle(workbook, true);
	titleStyle.setFont(titleFont);
	titleStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
	titleStyle.setFillForegroundColor((short) 10);
	titleStyle.setAlignment(CellStyle.ALIGN_CENTER);
	titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);

	return titleStyle;
}
 
Example 3
Source File: ExcelTempletService.java    From jeecg with Apache License 2.0 6 votes vote down vote up
/**
 * exce表头单元格样式处理
 * @param workbook
 * @return
 */
public static HSSFCellStyle getTitleStyle(HSSFWorkbook workbook) {
	// 产生Excel表头
	HSSFCellStyle titleStyle = workbook.createCellStyle();
	titleStyle.setBorderBottom(HSSFCellStyle.BORDER_DOUBLE); // 设置边框样式
	titleStyle.setBorderLeft((short) 2); // 左边框
	titleStyle.setBorderRight((short) 2); // 右边框
	titleStyle.setBorderTop((short) 2); // 左边框
	titleStyle.setBorderBottom((short) 2); // 右边框
	titleStyle.setBorderTop(HSSFCellStyle.BORDER_DOUBLE); // 顶边框
	titleStyle.setFillForegroundColor(HSSFColor.SKY_BLUE.index); // 填充的背景颜色
	titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);

	titleStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); // 填充图案

	return titleStyle;
}
 
Example 4
Source File: StyleManagerHUtils.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void addBackgroundColourToStyle(Workbook workbook, CellStyle style, String colour) {
	if(colour == null) {
		return ;
	}
	if(IStyle.TRANSPARENT_VALUE.equals(colour)) {
		return ;
	}
	if(style instanceof HSSFCellStyle) {
		HSSFCellStyle cellStyle = (HSSFCellStyle)style;
		short colourIndex = getHColour((HSSFWorkbook)workbook, colour);
		if( colourIndex > 0 ) {
			cellStyle.setFillForegroundColor(colourIndex);
			cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
		}
	}
}
 
Example 5
Source File: ExcelExportUtil.java    From jeewx with Apache License 2.0 6 votes vote down vote up
/**
 * 字段说明的Style
 * @param workbook
 * @return
 */
public static HSSFCellStyle getTitleStyle(HSSFWorkbook workbook, ExcelTitle entity) {
	HSSFCellStyle titleStyle = workbook.createCellStyle();
	titleStyle.setFillForegroundColor(entity.getHeaderColor()); // 填充的背景颜色
	titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
	titleStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
	titleStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); // 填充图案
	titleStyle.setWrapText(true);
	return titleStyle;
}
 
Example 6
Source File: ExcelTempletService.java    From jeewx with Apache License 2.0 6 votes vote down vote up
/**
 * exce表头单元格样式处理
 * @param workbook
 * @return
 */
public static HSSFCellStyle getTitleStyle(HSSFWorkbook workbook) {
	// 产生Excel表头
	HSSFCellStyle titleStyle = workbook.createCellStyle();
	titleStyle.setBorderBottom(HSSFCellStyle.BORDER_DOUBLE); // 设置边框样式
	titleStyle.setBorderLeft((short) 2); // 左边框
	titleStyle.setBorderRight((short) 2); // 右边框
	titleStyle.setBorderTop((short) 2); // 左边框
	titleStyle.setBorderBottom((short) 2); // 右边框
	titleStyle.setBorderTop(HSSFCellStyle.BORDER_DOUBLE); // 顶边框
	titleStyle.setFillForegroundColor(HSSFColor.SKY_BLUE.index); // 填充的背景颜色
	titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);

	titleStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); // 填充图案

	return titleStyle;
}
 
Example 7
Source File: CommonExcelServiceImpl.java    From jeecg with Apache License 2.0 5 votes vote down vote up
public static HSSFCellStyle getTwoStyle(HSSFWorkbook workbook) {
	// 产生Excel表头
	HSSFCellStyle style = workbook.createCellStyle();
	style.setBorderLeft((short) 1); // 左边框
	style.setBorderRight((short) 1); // 右边框
	style.setBorderBottom((short) 1);
	style.setBorderTop((short) 1);
	style.setFillForegroundColor(HSSFColor.LIGHT_TURQUOISE.index); // 填充的背景颜色
	style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); // 填充图案
	return style;
}
 
Example 8
Source File: CgReportExcelServiceImpl.java    From jeewx with Apache License 2.0 5 votes vote down vote up
/**
 * exce表头单元格样式处理
 * @param workbook
 * @return
 */
public static HSSFCellStyle getTitleStyle(HSSFWorkbook workbook) {
	// 产生Excel表头
	HSSFCellStyle titleStyle = workbook.createCellStyle();
	titleStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); // 左边框
	titleStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); // 右边框
	titleStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 底边框
	titleStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); // 顶边框
	titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
	titleStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); // 填充的背景颜色
	titleStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); // 填充图案

	return titleStyle;
}
 
Example 9
Source File: CgReportExcelServiceImpl.java    From jeewx with Apache License 2.0 5 votes vote down vote up
public static HSSFCellStyle getTwoStyle(HSSFWorkbook workbook) {
	// 产生Excel表头
	HSSFCellStyle style = workbook.createCellStyle();
	style.setBorderLeft((short) 1); // 左边框
	style.setBorderRight((short) 1); // 右边框
	style.setBorderBottom((short) 1);
	style.setBorderTop((short) 1);
	style.setFillForegroundColor(HSSFColor.LIGHT_TURQUOISE.index); // 填充的背景颜色
	style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); // 填充图案
	return style;
}
 
Example 10
Source File: ExcelExportUtil.java    From jeewx with Apache License 2.0 5 votes vote down vote up
/**
 * 表明的Style
 * @param workbook
 * @return
 */
public static HSSFCellStyle getHeaderStyle(HSSFWorkbook workbook, ExcelTitle entity) {
	HSSFCellStyle titleStyle = workbook.createCellStyle();
	Font font = workbook.createFont();
	font.setFontHeightInPoints((short) 24);
	titleStyle.setFont(font);
	titleStyle.setFillForegroundColor(entity.getColor()); 
	titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
	titleStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
	return titleStyle;
}
 
Example 11
Source File: CommonExcelServiceImpl.java    From jeecg with Apache License 2.0 5 votes vote down vote up
/**
 * exce表头单元格样式处理
 * @param workbook
 * @return
 */
public static HSSFCellStyle getTitleStyle(HSSFWorkbook workbook) {
	// 产生Excel表头
	HSSFCellStyle titleStyle = workbook.createCellStyle();
	titleStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); // 左边框
	titleStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); // 右边框
	titleStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 底边框
	titleStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); // 顶边框
	titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
	titleStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); // 填充的背景颜色
	titleStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); // 填充图案

	return titleStyle;
}
 
Example 12
Source File: InvestmentSummaryController.java    From primefaces-blueprints with The Unlicense 5 votes vote down vote up
public void postProcessXLS(Object document) {  
    HSSFWorkbook wb = (HSSFWorkbook) document;  
    HSSFSheet sheet = wb.getSheetAt(0);  
    HSSFRow header = sheet.getRow(0);  
      
    HSSFCellStyle cellStyle = wb.createCellStyle();    
    cellStyle.setFillForegroundColor(HSSFColor.GREEN.index);  
    cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);  
      
    for(int i=0; i < header.getPhysicalNumberOfCells();i++) {  
        HSSFCell cell = header.getCell(i);  
          
        cell.setCellStyle(cellStyle);  
    }  
    
    Row row=sheet.createRow((short)sheet.getLastRowNum()+3);
    Cell cellDisclaimer = row.createCell(0);
    HSSFFont customFont= wb.createFont();
    customFont.setFontHeightInPoints((short)10);
    customFont.setFontName("Arial");
    customFont.setColor(IndexedColors.BLACK.getIndex());
    customFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    customFont.setItalic(true);
    
    cellDisclaimer.setCellValue("Disclaimer");
    HSSFCellStyle cellStyleDisclaimer = wb.createCellStyle();
    cellStyleDisclaimer.setFont(customFont);
    cellDisclaimer.setCellStyle(cellStyleDisclaimer);
    
    Row row1=sheet.createRow(sheet.getLastRowNum()+2);
    Cell cellDisclaimerContent1 = row1.createCell(0);
    cellDisclaimerContent1.setCellValue("The information contained in this website is for information purposes only, and does not constitute, nor is it intended to constitute, the provision of financial product advice.");
    
    Row row2=sheet.createRow(sheet.getLastRowNum()+1);
    Cell cellDisclaimerContent2 = row2.createCell(0);
    cellDisclaimerContent2.setCellValue("This website is intended to track the investor account summary information,investments and transaction in a partcular period of time. ");
    
}
 
Example 13
Source File: AccountSummaryController.java    From primefaces-blueprints with The Unlicense 5 votes vote down vote up
public void postProcessXLS(Object document) {  
    HSSFWorkbook wb = (HSSFWorkbook) document;  
    HSSFSheet sheet = wb.getSheetAt(0);  
    HSSFRow header = sheet.getRow(0);  
    HSSFCellStyle cellStyle = wb.createCellStyle();    
    cellStyle.setFillForegroundColor(HSSFColor.GREEN.index);  
    cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);  
      
    for(int i=0; i < header.getPhysicalNumberOfCells();i++) {  
        HSSFCell cell = header.getCell(i);  
          
        cell.setCellStyle(cellStyle);  
    }  
    Row row=sheet.createRow((short)sheet.getLastRowNum()+3);
    Cell cellDisclaimer = row.createCell(0);
    HSSFFont customFont= wb.createFont();
    customFont.setFontHeightInPoints((short)10);
    customFont.setFontName("Arial");
    customFont.setColor(IndexedColors.BLACK.getIndex());
    customFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    customFont.setItalic(true);
    
    cellDisclaimer.setCellValue("Disclaimer");
    HSSFCellStyle cellStyleDisclaimer = wb.createCellStyle();
    cellStyleDisclaimer.setFont(customFont);
    cellDisclaimer.setCellStyle(cellStyleDisclaimer);
    
    Row row1=sheet.createRow(sheet.getLastRowNum()+2);
    Cell cellDisclaimerContent1 = row1.createCell(0);
    cellDisclaimerContent1.setCellValue("The information contained in this website is for information purposes only, and does not constitute, nor is it intended to constitute, the provision of financial product advice.");	    
    Row row2=sheet.createRow(sheet.getLastRowNum()+1);
    Cell cellDisclaimerContent2 = row2.createCell(0);
    cellDisclaimerContent2.setCellValue("This website is intended to track the investor account summary information,investments and transaction in a partcular period of time. ");
    
}
 
Example 14
Source File: TransactionSummaryController.java    From primefaces-blueprints with The Unlicense 5 votes vote down vote up
public void postProcessXLS(Object document) {
	HSSFWorkbook wb = (HSSFWorkbook) document;
	HSSFSheet sheet = wb.getSheetAt(0);
	HSSFRow header = sheet.getRow(0);

	HSSFCellStyle cellStyle = wb.createCellStyle();
	cellStyle.setFillForegroundColor(HSSFColor.GREEN.index);
	cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

	for (int i = 0; i < header.getPhysicalNumberOfCells(); i++) {
		HSSFCell cell = header.getCell(i);

		cell.setCellStyle(cellStyle);
	}

	Row row = sheet.createRow((short) sheet.getLastRowNum() + 3);
	Cell cellDisclaimer = row.createCell(0);
	HSSFFont customFont = wb.createFont();
	customFont.setFontHeightInPoints((short) 10);
	customFont.setFontName("Arial");
	customFont.setColor(IndexedColors.BLACK.getIndex());
	customFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
	customFont.setItalic(true);

	cellDisclaimer.setCellValue("Disclaimer");
	HSSFCellStyle cellStyleDisclaimer = wb.createCellStyle();
	cellStyleDisclaimer.setFont(customFont);
	cellDisclaimer.setCellStyle(cellStyleDisclaimer);

	Row row1 = sheet.createRow(sheet.getLastRowNum() + 2);
	Cell cellDisclaimerContent1 = row1.createCell(0);
	cellDisclaimerContent1
			.setCellValue("The information contained in this website is for information purposes only, and does not constitute, nor is it intended to constitute, the provision of financial product advice.");

	Row row2 = sheet.createRow(sheet.getLastRowNum() + 1);
	Cell cellDisclaimerContent2 = row2.createCell(0);
	cellDisclaimerContent2
			.setCellValue("This website is intended to track the investor account summary information,investments and transaction in a partcular period of time. ");

}
 
Example 15
Source File: ExcelTempletService.java    From jeecg with Apache License 2.0 5 votes vote down vote up
public static HSSFCellStyle getTwoStyle(HSSFWorkbook workbook) {
	// 产生Excel表头
	HSSFCellStyle style = workbook.createCellStyle();
	style.setBorderLeft((short) 1); // 左边框
	style.setBorderRight((short) 1); // 右边框
	style.setBorderBottom((short) 1);
	style.setBorderTop((short) 1);
	style.setFillForegroundColor(HSSFColor.LIGHT_TURQUOISE.index); // 填充的背景颜色
	style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); // 填充图案
	return style;
}
 
Example 16
Source File: POIUtils.java    From ermaster-b with Apache License 2.0 5 votes vote down vote up
public static HSSFCellStyle copyCellStyle(HSSFWorkbook workbook,
		HSSFCellStyle style) {

	HSSFCellStyle newCellStyle = workbook.createCellStyle();

	newCellStyle.setAlignment(style.getAlignment());
	newCellStyle.setBorderBottom(style.getBorderBottom());
	newCellStyle.setBorderLeft(style.getBorderLeft());
	newCellStyle.setBorderRight(style.getBorderRight());
	newCellStyle.setBorderTop(style.getBorderTop());
	newCellStyle.setBottomBorderColor(style.getBottomBorderColor());
	newCellStyle.setDataFormat(style.getDataFormat());
	newCellStyle.setFillBackgroundColor(style.getFillBackgroundColor());
	newCellStyle.setFillForegroundColor(style.getFillForegroundColor());
	newCellStyle.setFillPattern(style.getFillPattern());
	newCellStyle.setHidden(style.getHidden());
	newCellStyle.setIndention(style.getIndention());
	newCellStyle.setLeftBorderColor(style.getLeftBorderColor());
	newCellStyle.setLocked(style.getLocked());
	newCellStyle.setRightBorderColor(style.getRightBorderColor());
	newCellStyle.setRotation(style.getRotation());
	newCellStyle.setTopBorderColor(style.getTopBorderColor());
	newCellStyle.setVerticalAlignment(style.getVerticalAlignment());
	newCellStyle.setWrapText(style.getWrapText());

	HSSFFont font = workbook.getFontAt(style.getFontIndex());
	newCellStyle.setFont(font);

	return newCellStyle;
}
 
Example 17
Source File: JU_Excel2003Color.java    From hy.common.report with Apache License 2.0 5 votes vote down vote up
@Test
public void test_001()
{
    HSSFWorkbook v_Workbook = new HSSFWorkbook();
    HSSFSheet    v_Sheet    = v_Workbook.createSheet("测试单元格颜色");
    
    v_Sheet.setColumnWidth(0 ,2560);
    
    for (int v_RowIndex=0; v_RowIndex<4000; v_RowIndex++)
    {
        HSSFRow v_Row = v_Sheet.createRow(v_RowIndex);
        
        for (int v_ColIndex=0; v_ColIndex<1; v_ColIndex++)
        {
            HSSFCell      v_Cell = v_Row.createCell(v_ColIndex);
            HSSFCellStyle v_CellStyle = v_Workbook.createCellStyle();
            
            v_CellStyle.setFillForegroundColor((short)(v_RowIndex + 1));
            v_CellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
            
            v_Cell.setCellStyle(v_CellStyle);
            v_Cell.setCellValue("" + (v_RowIndex + 1));
        }
    }
    
    ExcelHelp.save(v_Workbook ,"/Users/hy/Downloads/测试2003版本的单元格颜色");
}
 
Example 18
Source File: PoiExport.java    From hrms with Apache License 2.0 4 votes vote down vote up
public InputStream exportExcel(String fileName, String[] headTitle,
		List<String> list) throws IOException {

	Workbook wb = new HSSFWorkbook();
	//FileOutputStream fileOut = new FileOutputStream(fileName);
	HSSFCellStyle style = (HSSFCellStyle) wb.createCellStyle();
	
	// 设置这些样式
	style.setFillForegroundColor(HSSFColor.SKY_BLUE.index);
	style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
	style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
	style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
	style.setBorderRight(HSSFCellStyle.BORDER_THIN);
	style.setBorderTop(HSSFCellStyle.BORDER_THIN);
	style.setAlignment(HSSFCellStyle.ALIGN_CENTER);

	// 生成一个字体
	HSSFFont font = (HSSFFont) wb.createFont();
	font.setColor(HSSFColor.VIOLET.index);
	font.setFontHeightInPoints((short) 12);
	font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

	// 把字体应用到当前的样式
	style.setFont(font);
	// 创建工作簿
	Sheet sheet = wb.createSheet("sheet1");
	// sheet.setDefaultColumnWidth((short)15);

	// 创建头部
	Row row = sheet.createRow((short) 0);
	for (int i = 0; i < headTitle.length; i++) {
		row.createCell(i).setCellValue(headTitle[i]);
	}
	// 填充数据
	for (int i = 0; i < list.size(); i++) {
		Row r = sheet.createRow((short) (i + 1));
		String[] strArray = list.get(i).split(",");
		for (int j = 0; j < headTitle.length; j++) {
			r.createCell(j).setCellValue(strArray[j]);
			if (strArray[j].length()>3) {
				sheet.setColumnWidth((short)j, 5000);
			}
		}
		
	}
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	try {
		wb.write(baos);
	} catch (IOException e) {
		e.printStackTrace();
	}
	byte[] ba = baos.toByteArray();
	ByteArrayInputStream excelStream = new ByteArrayInputStream(ba);
	return excelStream;

}
 
Example 19
Source File: CourseLoadOverviewBean.java    From fenixedu-academic with GNU Lesser General Public License v3.0 4 votes vote down vote up
public StyledExcelSpreadsheet getInconsistencySpreadsheet() {
    final StyledExcelSpreadsheet spreadsheet =
            new StyledExcelSpreadsheet(BundleUtil.getString(Bundle.ACADEMIC, "label.course.load.inconsistency.filename")
                    + "_" + executionSemester.getExecutionYear().getYear().replace('/', '_') + "_"
                    + executionSemester.getSemester());
    CellStyle normalStyle = spreadsheet.getExcelStyle().getValueStyle();
    normalStyle.setAlignment(HorizontalAlignment.CENTER);

    HSSFWorkbook wb = spreadsheet.getWorkbook();
    HSSFFont font = wb.createFont();
    font.setColor(HSSFColor.BLACK.index);
    font.setFontHeightInPoints((short) 8);
    HSSFCellStyle redStyle = wb.createCellStyle();
    redStyle.setFont(font);
    redStyle.setAlignment(HorizontalAlignment.CENTER);
    redStyle.setFillForegroundColor(HSSFColor.ORANGE.index);
    redStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    HSSFCellStyle yellowStyle = wb.createCellStyle();
    yellowStyle.setFont(font);
    yellowStyle.setAlignment(HorizontalAlignment.CENTER);
    yellowStyle.setFillForegroundColor(HSSFColor.YELLOW.index);
    yellowStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);

    spreadsheet.newHeaderRow();
    spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.department"));
    spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.degree"));
    spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.executionCourse"));
    spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.shift"));
    spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.shiftType"));
    spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.load.competenceCourse"));
    spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.load.curricularCourse"));
    spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.load.executionCourse"));
    spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.load.lessonInstances"));
    spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.load.lesson.count"));
    spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.load.lessonInstances.count"));

    for (final ExecutionCourse executionCourse : executionSemester.getAssociatedExecutionCoursesSet()) {
        for (final CourseLoad courseLoad : executionCourse.getCourseLoadsSet()) {
            for (final Shift shift : courseLoad.getShiftsSet()) {
                spreadsheet.newRow();
                spreadsheet.addCell(getDepartmentString(executionCourse));
                spreadsheet.addCell(executionCourse.getDegreePresentationString());
                spreadsheet.addCell(executionCourse.getName());
                spreadsheet.addCell(shift.getNome());
                spreadsheet.addCell(courseLoad.getType().getFullNameTipoAula());
                final BigDecimal competenceCourseLoad =
                        new BigDecimal(getCompetenceCourseLoad(courseLoad)).setScale(2, RoundingMode.HALF_EVEN);
                final BigDecimal curricularCourseLoad =
                        new BigDecimal(getCurricularCourseLoad(courseLoad)).setScale(2, RoundingMode.HALF_EVEN);
                final BigDecimal executionLoad = courseLoad.getTotalQuantity().setScale(2, RoundingMode.HALF_EVEN);
                final BigDecimal shiftCourseLoad = getShiftCourseLoad(shift).setScale(2, RoundingMode.HALF_EVEN);
                if (competenceCourseLoad.signum() < 0) {
                    spreadsheet.addCell(getCompetenceCourseLoadStrings(courseLoad), redStyle);
                } else {
                    spreadsheet.addCell(competenceCourseLoad);
                }
                if (!competenceCourseLoad.equals(curricularCourseLoad) || curricularCourseLoad.signum() < 0) {
                    spreadsheet.addCell(getCurricularCourseLoadString(courseLoad), redStyle);
                } else {
                    spreadsheet.addCell(curricularCourseLoad);
                }
                if (!executionLoad.equals(curricularCourseLoad)) {
                    spreadsheet.addCell(executionLoad, redStyle);
                } else {
                    spreadsheet.addCell(executionLoad);
                }
                if (!shiftCourseLoad.equals(executionLoad)) {
                    if (isLargeDifference(shiftCourseLoad, executionLoad,
                            competenceCourseLoad.divide(new BigDecimal(14), 2, RoundingMode.HALF_EVEN))) {
                        spreadsheet.addCell(shiftCourseLoad, redStyle);
                    } else {
                        spreadsheet.addCell(shiftCourseLoad, yellowStyle);
                    }
                } else {
                    spreadsheet.addCell(shiftCourseLoad);
                }
                spreadsheet.addCell(shift.getAssociatedLessonsSet().size());
                spreadsheet.addCell(getLessonInstanceCount(shift));
            }
        }
    }

    final HSSFSheet sheet = wb.getSheetAt(0);
    sheet.createFreezePane(0, 1, 0, 1);
    sheet.autoSizeColumn(1, true);
    sheet.autoSizeColumn(2, true);
    sheet.autoSizeColumn(3, true);
    sheet.autoSizeColumn(4, true);
    sheet.autoSizeColumn(5, true);
    sheet.autoSizeColumn(6, true);
    sheet.autoSizeColumn(7, true);
    sheet.autoSizeColumn(8, true);
    sheet.autoSizeColumn(9, true);

    return spreadsheet;
}
 
Example 20
Source File: TableSheetGenerator.java    From ermaster-b with Apache License 2.0 4 votes vote down vote up
private void setIndexMatrixColor(HSSFWorkbook workbook,
		HSSFCellStyle indexStyle) {
	indexStyle.setFillForegroundColor(HSSFColor.WHITE.index);
	HSSFFont font = workbook.getFontAt(indexStyle.getFontIndex());
	font.setColor(HSSFColor.BLACK.index);
}