Creating an Excel Workbook

Setting Colors

Colors can be set on Cells: background, borders and text color. Colors are created based on RGB values (Red, Green, Blue). RGB values can be easily determined using any Image or Color Editor. Predefined Excel colors are defined in the ColorDescriptor class. Bellow is a sample code to set some Cell colors:

import com.sodius.mdw.metamodel.excel.util.ColorDescriptor;
...
Workbook workbook = ...;
CellStyle cellStyle = ...;
Cell myCell = ...;
...
cellStyle.setBackground(workbook.getColor(ColorDescriptor.GREEN)); // standard color
cellStyle.setBottomColor(workbook.getColor(new ColorDescriptor(51, 102, 255))); // RGB color
myCell.setStyle(cellStyle);

Excel *.xls compatibility

Excel 2003 format (*.xls) only supports a limited set of colors, the ones defined as constants in the ColorDescriptor class. If custom colors are used in the model, the nearest predefined color will be used when writing the *.xls file.