本文整理匯總了Java中org.apache.poi.ss.usermodel.IndexedColors類的典型用法代碼示例。如果您正苦於以下問題:Java IndexedColors類的具體用法?Java IndexedColors怎麽用?Java IndexedColors使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
IndexedColors類屬於org.apache.poi.ss.usermodel包,在下文中一共展示了IndexedColors類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: defaultDataCellStyle
import org.apache.poi.ss.usermodel.IndexedColors; //導入依賴的package包/類
/**
* Returns the default data cell style. Obtained from:
* http://svn.apache.org/repos/asf/poi
* /trunk/src/examples/src/org/apache/poi/ss/examples/TimesheetDemo.java
*
* @param wb the wb
* @return the cell style
*/
protected CellStyle defaultDataCellStyle(final Workbook wb) {
CellStyle style;
style = wb.createCellStyle();
style.setAlignment(HorizontalAlignment.CENTER);
style.setWrapText(true);
style.setBorderRight(BorderStyle.THIN);
style.setRightBorderColor(IndexedColors.BLACK.getIndex());
style.setBorderLeft(BorderStyle.THIN);
style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
style.setBorderTop(BorderStyle.THIN);
style.setTopBorderColor(IndexedColors.BLACK.getIndex());
style.setBorderBottom(BorderStyle.THIN);
style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
style.setDataFormat(doubleDataFormat);
return style;
}
示例2: defaultHeaderCellStyle
import org.apache.poi.ss.usermodel.IndexedColors; //導入依賴的package包/類
/**
* Returns the default header style. Obtained from:
* http://svn.apache.org/repos/asf/poi
* /trunk/src/examples/src/org/apache/poi/ss/examples/TimesheetDemo.java
*
* @param wb the wb
* @return the cell style
*/
protected CellStyle defaultHeaderCellStyle(final Workbook wb) {
CellStyle style;
final Font monthFont = wb.createFont();
monthFont.setFontHeightInPoints((short) 11);
monthFont.setColor(IndexedColors.WHITE.getIndex());
style = wb.createCellStyle();
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
style.setFont(monthFont);
style.setWrapText(true);
return style;
}
示例3: createStyles
import org.apache.poi.ss.usermodel.IndexedColors; //導入依賴的package包/類
/**
* 創建表格樣式
* @param wb 工作薄對象
* @return 樣式列表
*/
private Map<String, CellStyle> createStyles(Workbook wb) {
Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
CellStyle style = wb.createCellStyle();
style.setAlignment(CellStyle.ALIGN_CENTER);
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
Font titleFont = wb.createFont();
titleFont.setFontName("Arial");
titleFont.setFontHeightInPoints((short) 16);
titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
style.setFont(titleFont);
styles.put("title", style);
style = wb.createCellStyle();
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
style.setBorderRight(CellStyle.BORDER_THIN);
style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setBorderLeft(CellStyle.BORDER_THIN);
style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setBorderTop(CellStyle.BORDER_THIN);
style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setBorderBottom(CellStyle.BORDER_THIN);
style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
Font dataFont = wb.createFont();
dataFont.setFontName("Arial");
dataFont.setFontHeightInPoints((short) 10);
style.setFont(dataFont);
styles.put("data", style);
style = wb.createCellStyle();
style.cloneStyleFrom(styles.get("data"));
style.setAlignment(CellStyle.ALIGN_LEFT);
styles.put("data1", style);
style = wb.createCellStyle();
style.cloneStyleFrom(styles.get("data"));
style.setAlignment(CellStyle.ALIGN_CENTER);
styles.put("data2", style);
style = wb.createCellStyle();
style.cloneStyleFrom(styles.get("data"));
style.setAlignment(CellStyle.ALIGN_RIGHT);
styles.put("data3", style);
style = wb.createCellStyle();
style.cloneStyleFrom(styles.get("data"));
// style.setWrapText(true);
style.setAlignment(CellStyle.ALIGN_CENTER);
style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
Font headerFont = wb.createFont();
headerFont.setFontName("Arial");
headerFont.setFontHeightInPoints((short) 10);
headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
headerFont.setColor(IndexedColors.WHITE.getIndex());
style.setFont(headerFont);
styles.put("header", style);
return styles;
}
示例4: createHeadStyle
import org.apache.poi.ss.usermodel.IndexedColors; //導入依賴的package包/類
CellStyle createHeadStyle() {
if (headerCellStyle != null) {
return headerCellStyle;
}
CellStyle style = wb.createCellStyle();
// 設置這些樣式
style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.index);
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
style.setAlignment(CellStyle.ALIGN_CENTER);
// 生成一個字體
Font font = wb.createFont();
font.setColor(IndexedColors.BLACK.index);
font.setFontHeightInPoints((short) 12);
font.setBoldweight(Font.BOLDWEIGHT_BOLD);
// 把字體應用到當前的樣式
style.setFont(font);
headerCellStyle = style;
return style;
}
示例5: createHeadDateStyle
import org.apache.poi.ss.usermodel.IndexedColors; //導入依賴的package包/類
CellStyle createHeadDateStyle() {
if (headDateCellStyle != null) {
return headDateCellStyle;
}
CellStyle cellStyle = wb.createCellStyle();
DataFormat format = wb.createDataFormat();
cellStyle.setDataFormat(format.getFormat("m/d/yy h:mm"));
// 設置這些樣式
cellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.index);
cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
cellStyle.setAlignment(CellStyle.ALIGN_CENTER);
// 生成一個字體
Font font = wb.createFont();
font.setColor(IndexedColors.BLACK.index);
font.setFontHeightInPoints((short) 12);
font.setBoldweight(Font.BOLDWEIGHT_BOLD);
// 把字體應用到當前的樣式
cellStyle.setFont(font);
headDateCellStyle = cellStyle;
return cellStyle;
}
示例6: createLinkStyle
import org.apache.poi.ss.usermodel.IndexedColors; //導入依賴的package包/類
private CellStyle createLinkStyle(boolean bordered) {
final Font hlinkFont = wb.createFont();
hlinkFont.setUnderline(Font.U_SINGLE);
hlinkFont.setColor(IndexedColors.BLUE.getIndex());
final CellStyle style;
if (bordered) {
style = createBorderedStyle(wb);
} else {
style = wb.createCellStyle();
}
style.setFont(hlinkFont);
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
style.setIndention((short) 1);
style.setWrapText(true);
return style;
}
示例7: createBorderedStyle
import org.apache.poi.ss.usermodel.IndexedColors; //導入依賴的package包/類
private static CellStyle createBorderedStyle(Workbook wb) {
CellStyle style = wb.createCellStyle();
style.setBorderRight(CellStyle.BORDER_THIN);
style.setRightBorderColor(IndexedColors.BLACK.getIndex());
style.setBorderBottom(CellStyle.BORDER_THIN);
style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
style.setBorderLeft(CellStyle.BORDER_THIN);
style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
style.setBorderTop(CellStyle.BORDER_THIN);
style.setTopBorderColor(IndexedColors.BLACK.getIndex());
return style;
}
示例8: formatCellStatus
import org.apache.poi.ss.usermodel.IndexedColors; //導入依賴的package包/類
protected void formatCellStatus(Sheet sheet, Cell cell) {
cell.setCellStyle(styles.get("status"));
SheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting();
ConditionalFormattingRule ruleGreen = sheetCF.createConditionalFormattingRule(ComparisonOperator.EQUAL, "1");
PatternFormatting fill1 = ruleGreen.createPatternFormatting();
fill1.setFillBackgroundColor(IndexedColors.GREEN.index);
fill1.setFillPattern(PatternFormatting.SOLID_FOREGROUND);
//
ConditionalFormattingRule ruleRed = sheetCF.createConditionalFormattingRule(ComparisonOperator.EQUAL, "0");
PatternFormatting fill2 = ruleRed.createPatternFormatting();
fill2.setFillBackgroundColor(IndexedColors.RED.index);
fill2.setFillPattern(PatternFormatting.SOLID_FOREGROUND);
//
ConditionalFormattingRule ruleOrange = sheetCF.createConditionalFormattingRule(ComparisonOperator.EQUAL, "2");
PatternFormatting fill3 = ruleOrange.createPatternFormatting();
fill3.setFillBackgroundColor(IndexedColors.ORANGE.index);
fill3.setFillPattern(PatternFormatting.SOLID_FOREGROUND);
//
String name = CellReference.convertNumToColString(cell.getColumnIndex());
String location = "$" + name + "$" + cell.getRowIndex() + ":$" + name + "$" + (cell.getRowIndex() + 1);
CellRangeAddress[] regions = { CellRangeAddress.valueOf(location) };
ConditionalFormattingRule[] cfRules = new ConditionalFormattingRule[] { ruleGreen, ruleRed, ruleOrange };
sheetCF.addConditionalFormatting(regions, cfRules);
}
示例9: createStyles
import org.apache.poi.ss.usermodel.IndexedColors; //導入依賴的package包/類
/**
* excel 樣式
*
* @return
*/
public Map<String, CellStyle> createStyles(Workbook workbook) {
Map<String, CellStyle> styles = new HashMap();
CellStyle style = workbook.createCellStyle();
style.setAlignment((short) 2);
style.setVerticalAlignment((short) 1);
Font titleFont = workbook.createFont();
titleFont.setFontName("Arial");
titleFont.setFontHeightInPoints((short) 16);
titleFont.setBoldweight((short) 700);
style.setFont(titleFont);
styles.put("title", style);
style = workbook.createCellStyle();
style.setVerticalAlignment((short) 1);
style.setBorderRight((short) 1);
style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setBorderLeft((short) 1);
style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setBorderTop((short) 1);
style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setBorderBottom((short) 1);
style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
Font dataFont = workbook.createFont();
dataFont.setFontName("Arial");
dataFont.setFontHeightInPoints((short) 10);
style.setFont(dataFont);
styles.put("data", style);
style = workbook.createCellStyle();
style.cloneStyleFrom((CellStyle) styles.get("data"));
style.setAlignment((short) 1);
styles.put("data1", style);
style = workbook.createCellStyle();
style.cloneStyleFrom((CellStyle) styles.get("data"));
style.setAlignment((short) 2);
styles.put("data2", style);
style = workbook.createCellStyle();
style.cloneStyleFrom((CellStyle) styles.get("data"));
style.setAlignment((short) 3);
styles.put("data3", style);
style = workbook.createCellStyle();
style.cloneStyleFrom((CellStyle) styles.get("data"));
style.setAlignment((short) 2);
style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setFillPattern((short) 1);
Font headerFont = workbook.createFont();
headerFont.setFontName("Arial");
headerFont.setFontHeightInPoints((short) 10);
headerFont.setBoldweight((short) 700);
headerFont.setColor(IndexedColors.WHITE.getIndex());
style.setFont(headerFont);
styles.put("header", style);
return styles;
}
示例10: createBorderCellStyle
import org.apache.poi.ss.usermodel.IndexedColors; //導入依賴的package包/類
public CellStyle createBorderCellStyle(Workbook workbook, boolean showBorder) {
CellStyle style = workbook.createCellStyle();
if (showBorder) {
style.setBorderRight(BorderStyle.THIN);
style.setRightBorderColor(IndexedColors.BLACK.getIndex());
style.setBorderBottom(BorderStyle.THIN);
style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
style.setBorderLeft(BorderStyle.THIN);
style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
style.setBorderTop(BorderStyle.THIN);
style.setTopBorderColor(IndexedColors.BLACK.getIndex());
}
return style;
}
示例11: crateCaptionCellStyle
import org.apache.poi.ss.usermodel.IndexedColors; //導入依賴的package包/類
/**
*
* @return
*/
protected CellStyle crateCaptionCellStyle() {
Font font = workbook.createFont();
font.setColor(Font.COLOR_NORMAL);
CellStyle cellStyle = workbook.createCellStyle();
cellStyle.setWrapText(false);
font.setFontHeight((short) 250);
cellStyle.setFont(font);
cellStyle.setFillForegroundColor(IndexedColors.BLUE_GREY.index);
cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
cellStyle.setAlignment(CellStyle.ALIGN_CENTER);
return cellStyle;
}
示例12: setBold
import org.apache.poi.ss.usermodel.IndexedColors; //導入依賴的package包/類
/**
* Set a bold font for the given cell with a given font size (in pt).
*
* @param wb
* the workbook that contains the cell
* @param cell
* the cell where the text is contained
* @param size
* the size in pt of the text
*/
public static void setBold(Workbook wb, HSSFCell cell, short size) {
Font font = wb.createFont();
font.setFontHeightInPoints((short) size);
font.setFontName("Arial");
font.setColor(IndexedColors.BLACK.getIndex());
font.setBold(true);
font.setItalic(false);
CellStyle style = wb.createCellStyle();
style.setFont(font);
cell.setCellStyle(style);
}
示例13: setLink
import org.apache.poi.ss.usermodel.IndexedColors; //導入依賴的package包/類
/**
* Set a link to a cell. The link type should one of {@link Hyperlink}
*
* @param wb
* the workbook which contains the cell
* @param cell
* the cell where the link is stored
* @param address
* the cell destination address
* @param linkType
* the type selected among {@link Hyperlink}
*/
public static void setLink(Workbook wb, HSSFCell cell, String address, int linkType) {
CreationHelper helper = wb.getCreationHelper();
CellStyle style = wb.createCellStyle();
Font font = wb.createFont();
font.setUnderline(Font.U_SINGLE);
font.setColor(IndexedColors.BLUE.getIndex());
style.setFont(font);
Hyperlink link = helper.createHyperlink(linkType);
link.setAddress(address);
cell.setHyperlink(link);
cell.setCellStyle(style);
}
示例14: test2
import org.apache.poi.ss.usermodel.IndexedColors; //導入依賴的package包/類
@Test
public void test2() throws IOException{
Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet("new sheet");
// Create a row and put some cells in it. Rows are 0 based.
Row row = sheet.createRow(1);
// Create a cell and put a value in it.
// Style the cell with borders all around.
CellStyle style = wb.createCellStyle();
// style.setFillBackgroundColor(IndexedColors.AUTOMATIC.getIndex());
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
style.setFillForegroundColor(IndexedColors.LIGHT_ORANGE.index);
Font font = wb.createFont();
font.setFontHeightInPoints((short)24);
font.setFontName("Courier New");
font.setItalic(true);
font.setStrikeout(true);
style.setFont(font);
CellUtil.createCell(row, 1, "nihao",style);
//style.setFont(font);
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
}
示例15: createTitle
import org.apache.poi.ss.usermodel.IndexedColors; //導入依賴的package包/類
protected void createTitle() {
short lineThickness = (short) (6 * BASE_HEIGHT);
// Top Line
Row row = sheet.createRow(ROW_4);
row.setHeight(lineThickness);
XSSFCellStyle style = wb.createCellStyle();
style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
setDummyTitleStyle(row,style);
// Title
row = sheet.createRow(ROW_5);
row.setHeightInPoints(100);
sheet.addMergedRegion(CellRangeAddress.valueOf("B5:G5"));
Font font = wb.createFont();
font.setFontHeightInPoints((short)28);
font.setFontName("Trebuchet MS");
font.setBoldweight(Font.BOLDWEIGHT_BOLD);
style = wb.createCellStyle();
style.setFont(font);
style.setAlignment(CellStyle.ALIGN_CENTER);
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
setDummyTitleStyle(row,style);
row.getCell(COL_B).setCellValue("Open Source License Verification Report");
// Bottom Line
row = sheet.createRow(ROW_6);
row.setHeight(lineThickness);
style = wb.createCellStyle();
style.setFillForegroundColor(DARK_BLUE);
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
setDummyTitleStyle(row,style);
}