Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

POI setFillBackgroundColor problem

843789Oct 13 2009 — edited Oct 16 2009
My background color keeps coming out black rather than the color I set. I'm using POI version 3.5 with Excel 2007.
	public void createWorkSheet(String model, String pcfg, String desc)
	{
		try{
			this.fileout = new FileOutputStream("container-sheet.xls");
			this.wb = new HSSFWorkbook();
			this.ws = wb.createSheet("Container Worksheet");
			int size = 3000;
			for(int x = 0; x < 6; x++)
			{
				this.ws.setColumnWidth(x, size);
				size = (size == 3000) ? 4000 : 3000;
			}

			// index from 0,0 ... cell A1 is cell(0,0)
			HSSFRow row1 = this.ws.createRow((short) 0);
			HSSFCell cellA1 = row1.createCell((short) 0);
			cellA1.setCellValue("Container:");
			cellA1.setCellStyle(setBold());

			HSSFCell cellB1 = row1.createCell((short) 1);
			cellB1.setCellValue("TGHU0453616");

			HSSFCell cellC1 = row1.createCell((short) 2);
			cellC1.setCellValue("Date:");
			cellC1.setCellStyle(setBold());

			HSSFCell cellD1 = row1.createCell((short) 3);
			cellD1.setCellValue(printDate());

			HSSFCell cellE1 = row1.createCell((short) 4);
			cellE1.setCellValue("Dock#");
			cellE1.setCellStyle(setBold());

			HSSFRow row2 = this.ws.createRow((short) 1);
			HSSFCell cellA2 = row2.createCell((short) 0);
			cellA2.setCellValue("PO#");
//here is where I call the method to set the background color
			cellA2.setCellStyle(setBoldBackgroundGrey());

			this.wb.write(fileout);
			fileout.flush();
			fileout.close();
		}catch(Exception e){
			e.printStackTrace();
		}
	}

public HSSFCellStyle setBoldBackgroundGrey()
	{
		HSSFCellStyle cellStyle = this.wb.createCellStyle();
		HSSFFont font = this.wb.createFont();
		font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
		cellStyle.setFont(font);
                //below is where I set the color
		cellStyle.setFillBackgroundColor(HSSFColor.AQUA.index);
		cellStyle.setFillPattern(cellStyle.SOLID_FOREGROUND);


		return cellStyle;
	}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 13 2009
Added on Oct 13 2009
2 comments
804 views