当前位置: 首页>>代码示例>>Java>>正文


Java HSSFColor类代码示例

本文整理汇总了Java中org.apache.poi.hssf.util.HSSFColor的典型用法代码示例。如果您正苦于以下问题:Java HSSFColor类的具体用法?Java HSSFColor怎么用?Java HSSFColor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HSSFColor类属于org.apache.poi.hssf.util包,在下文中一共展示了HSSFColor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: makeHeader

import org.apache.poi.hssf.util.HSSFColor; //导入依赖的package包/类
private void makeHeader ( final List<Field> columns, final HSSFSheet sheet )
{
    final Font font = sheet.getWorkbook ().createFont ();
    font.setFontName ( "Arial" );
    font.setBoldweight ( Font.BOLDWEIGHT_BOLD );
    font.setColor ( HSSFColor.WHITE.index );

    final CellStyle style = sheet.getWorkbook ().createCellStyle ();
    style.setFont ( font );
    style.setFillForegroundColor ( HSSFColor.BLACK.index );
    style.setFillPattern ( PatternFormatting.SOLID_FOREGROUND );

    final HSSFRow row = sheet.createRow ( 0 );

    for ( int i = 0; i < columns.size (); i++ )
    {
        final Field field = columns.get ( i );

        final HSSFCell cell = row.createCell ( i );
        cell.setCellValue ( field.getHeader () );
        cell.setCellStyle ( style );
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:24,代码来源:ExportEventsImpl.java

示例2: getCellStyle

import org.apache.poi.hssf.util.HSSFColor; //导入依赖的package包/类
/**
 * 获取单元格式样式
 *
 * @param wb
 * @param color
 * @return
 */
private static HSSFCellStyle getCellStyle(HSSFWorkbook wb, int color) {
    if (STYLE_MAP.get(color) != null) {
        return STYLE_MAP.get(color);
    }
    HSSFCellStyle style = wb.createCellStyle();
    if (color != -1) {
        style.setFillForegroundColor(Short.valueOf(color + ""));
        style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        style.setAlignment(CellStyle.ALIGN_CENTER);
    }
    style.setBorderBottom(CellStyle.BORDER_THIN);
    style.setBorderLeft(CellStyle.BORDER_THIN);
    style.setBorderRight(CellStyle.BORDER_THIN);
    style.setBorderTop(CellStyle.BORDER_THIN);
    style.setBottomBorderColor(HSSFColor.BLACK.index);
    style.setLeftBorderColor(HSSFColor.BLACK.index);
    style.setRightBorderColor(HSSFColor.BLACK.index);
    style.setTopBorderColor(HSSFColor.BLACK.index);
    STYLE_MAP.put(color, style);
    return style;
}
 
开发者ID:ajtdnyy,项目名称:PackagePlugin,代码行数:29,代码来源:FileUtil.java

示例3: createColor

import org.apache.poi.hssf.util.HSSFColor; //导入依赖的package包/类
/**
 * 创建颜色。
 * 
 * 写本方法的原因是:从2003版本的模板中复制单元格颜色时,会出现颜色失真的问题。
 * 
 * 但最终也没有解决。因为:当单元格的颜色设置为非标准颜色时,就会失真,但设置为标准颜色时,是正常的。
 * 
 * 也因为此,本方法与 i_ToCellStyle.setFillBackgroundColor(i_FromCellStyle.getFillBackgroundColor()); 的效果是相同的。
 * 
 * 本方法作为研究使用而保留下来,但不没有使用价值。
 * 
 * @author      ZhengWei(HY)
 * @createDate  2017-03-21
 * @version     v1.0
 *
 * @param i_FromColor
 * @param i_DataWorkbook
 * @return
 */
@Deprecated
public final static HSSFColor createColor(HSSFColor i_FromColor ,HSSFWorkbook i_DataWorkbook)
{
    short [] v_RGBHex    = i_FromColor.getTriplet();
    byte     v_ByteRed   = (byte)v_RGBHex[0];
    byte     v_ByteGreen = (byte)v_RGBHex[1];
    byte     v_ByteBlue  = (byte)v_RGBHex[2];
    
    HSSFPalette v_Palette   = i_DataWorkbook.getCustomPalette();
    HSSFColor   v_DataColor = v_Palette.findColor(v_ByteRed ,v_ByteGreen ,v_ByteBlue);
    
    if ( v_DataColor == null )
    {
        v_Palette.setColorAtIndex(i_FromColor.getIndex() ,v_ByteRed ,v_ByteGreen ,v_ByteBlue);
        
        return v_Palette.getColor(i_FromColor.getIndex());
    }
    
    return  v_DataColor;
}
 
开发者ID:HY-ZhengWei,项目名称:hy.common.report,代码行数:40,代码来源:JavaToExcel.java

示例4: setRegionBorder

import org.apache.poi.hssf.util.HSSFColor; //导入依赖的package包/类
/**
 * 获取合并单元格式
 *
 * @param sheet
 * @param row
 * @param columnFrom
 * @param columnTo
 * @return
 */
private static void setRegionBorder(HSSFSheet sheet, int row, int columnFrom, int columnTo) {
    CellRangeAddress region = new CellRangeAddress(row, row, columnFrom, columnTo);
    sheet.addMergedRegion(region);
    final short border = CellStyle.BORDER_THIN;
    HSSFWorkbook wb = sheet.getWorkbook();
    RegionUtil.setBorderBottom(border, region, sheet, wb);
    RegionUtil.setBorderTop(border, region, sheet, wb);
    RegionUtil.setBorderLeft(border, region, sheet, wb);
    RegionUtil.setBorderRight(border, region, sheet, wb);
    RegionUtil.setBottomBorderColor(HSSFColor.BLACK.index, region, sheet, wb);
    RegionUtil.setTopBorderColor(HSSFColor.BLACK.index, region, sheet, wb);
    RegionUtil.setLeftBorderColor(HSSFColor.BLACK.index, region, sheet, wb);
    RegionUtil.setRightBorderColor(HSSFColor.BLACK.index, region, sheet, wb);
}
 
开发者ID:ajtdnyy,项目名称:PackagePlugin,代码行数:24,代码来源:FileUtil.java

示例5: openOutputData

import org.apache.poi.hssf.util.HSSFColor; //导入依赖的package包/类
/**
 * @throws TechnicalException
 *             is thrown if you have a technical error (format, configuration, datas, ...) in NoraUi.
 */
void openOutputData() throws TechnicalException {
    this.dataOutExtension = validExtension(dataOutPath);
    try (FileInputStream fileOut = new FileInputStream(dataOutPath + scenarioName + "." + dataOutExtension);) {
        initWorkbook(fileOut, dataOutExtension);
    } catch (final IOException e) {
        throw new TechnicalException(Messages.getMessage(TechnicalException.TECHNICAL_ERROR_MESSAGE_DATA_IOEXCEPTION), e);
    }

    styleSuccess = workbook.createCellStyle();
    final Font fontSuccess = workbook.createFont();
    fontSuccess.setColor(HSSFColor.HSSFColorPredefined.GREEN.getIndex());
    styleSuccess.setFont(fontSuccess);

    styleFailed = workbook.createCellStyle();
    final Font fontFailed = workbook.createFont();
    fontFailed.setColor(HSSFColor.HSSFColorPredefined.RED.getIndex());
    styleFailed.setFont(fontFailed);

    styleWarning = workbook.createCellStyle();
    final Font fontWarning = workbook.createFont();
    fontWarning.setColor(HSSFColor.HSSFColorPredefined.ORANGE.getIndex());
    styleWarning.setFont(fontWarning);
}
 
开发者ID:NoraUi,项目名称:NoraUi,代码行数:28,代码来源:ExcelDataProvider.java

示例6: convertToStardColor

import org.apache.poi.hssf.util.HSSFColor; //导入依赖的package包/类
/**
 * 单元格背景色转换
 */
private String convertToStardColor(HSSFColor hc) {
	StringBuffer sb = new StringBuffer("");
	if (hc != null) {
		int a = HSSFColor.AUTOMATIC.index;
		int b = hc.getIndex();
		if (a == b) {
			return null;
		}
		sb.append("#");
		for (int i = 0; i < hc.getTriplet().length; i++) {
			String str;
			String strTmp = Integer.toHexString(hc.getTriplet()[i]);
			if (strTmp != null && strTmp.length() < 2) {
				str = "0" + strTmp;
			} else {
				str = strTmp;
			}
			sb.append(str);
		}
	}
	return sb.toString();
}
 
开发者ID:MobClub,项目名称:BBSSDK-for-Android,代码行数:26,代码来源:OfficeConverter.java

示例7: getNearestColor

import org.apache.poi.hssf.util.HSSFColor; //导入依赖的package包/类
/**
 *
 */
protected HSSFColor getNearestColor(Color awtColor)
{
	HSSFColor color = hssfColorsCache.get(awtColor);		
	if (color == null)
	{
		int minDiff = Integer.MAX_VALUE;
		for (Map.Entry<HSSFColor, short[]> hssfColorEntry : hssfColorsRgbs.entrySet())
		{
			HSSFColor crtColor = hssfColorEntry.getKey();
			short[] rgb = hssfColorEntry.getValue();
			
			int diff = Math.abs(rgb[0] - awtColor.getRed()) + Math.abs(rgb[1] - awtColor.getGreen()) + Math.abs(rgb[2] - awtColor.getBlue());

			if (diff < minDiff)
			{
				minDiff = diff;
				color = crtColor;
			}
		}

		hssfColorsCache.put(awtColor, color);
	}
	return color;
}
 
开发者ID:TIBCOSoftware,项目名称:jasperreports,代码行数:28,代码来源:JRXlsExporter.java

示例8: crateTitleCellStyle

import org.apache.poi.hssf.util.HSSFColor; //导入依赖的package包/类
/**
 * 表头单元格样式
 * 
 * @return
 */
protected CellStyle crateTitleCellStyle() {
	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(HSSFColor.BLUE_GREY.index);
	cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
	short border = 1;
	setCellBorder(cellStyle, border, border, border, border);
	cellStyle.setAlignment(CellStyle.ALIGN_LEFT);
	return cellStyle;
}
 
开发者ID:thinking-github,项目名称:nbone,代码行数:20,代码来源:AbstractPoiExcelTemplate.java

示例9: replaceColorsPallete

import org.apache.poi.hssf.util.HSSFColor; //导入依赖的package包/类
private void replaceColorsPallete(Map<HSSFColor, HSSFColor> colorsReplaceMap, Workbook wb) {
    if (! (wb instanceof HSSFWorkbook)) {
        return;
    }

    HSSFWorkbook hssfWb = (HSSFWorkbook) wb;
    final HSSFPalette customPalette = hssfWb.getCustomPalette();
    for (Entry<HSSFColor, HSSFColor> e : colorsReplaceMap.entrySet()) {
        short[] rgb = e.getValue().getTriplet();
        customPalette.setColorAtIndex(e.getKey().getIndex(),
                (byte)rgb[0],
                (byte)rgb[1],
                (byte)rgb[2]
        );
    }
}
 
开发者ID:tecsinapse,项目名称:tecsinapse-data-io,代码行数:17,代码来源:WorkbookUtil.java

示例10: cellStyleBorderTest

import org.apache.poi.hssf.util.HSSFColor; //导入依赖的package包/类
@Test(dataProvider = "cellStyleBorderDs")
public void cellStyleBorderTest(CellStyleBorder cellStyleBorder, HSSFColor color, boolean left, boolean right, boolean top, boolean bottom,
                                HSSFColor color2, String expectedCss, String expectedInvertedCss) {
    Assert.assertEquals(cellStyleBorder.getBorderColor(), color);
    Assert.assertEquals(cellStyleBorder.isLeft(), left);
    Assert.assertEquals(cellStyleBorder.isRight(), right);
    Assert.assertEquals(cellStyleBorder.isTop(), top);
    Assert.assertEquals(cellStyleBorder.isBottom(), bottom);
    Assert.assertEquals(cellStyleBorder.toCss(), expectedCss);

    CellStyleBorder cellStyleBorder2 = cellStyleBorder.duplicate();
    cellStyleBorder2.setBorderColor(color2);
    cellStyleBorder2.setLeft(!left);
    cellStyleBorder2.setRight(!right);
    cellStyleBorder2.setTop(!top);
    cellStyleBorder2.setBottom(!bottom);

    Assert.assertEquals(cellStyleBorder2.getBorderColor(), color2);
    Assert.assertEquals(cellStyleBorder2.isLeft(), !left);
    Assert.assertEquals(cellStyleBorder2.isRight(), !right);
    Assert.assertEquals(cellStyleBorder2.isTop(), !top);
    Assert.assertEquals(cellStyleBorder2.isBottom(), !bottom);
    Assert.assertEquals(cellStyleBorder2.toCss(), expectedInvertedCss);
}
 
开发者ID:tecsinapse,项目名称:tecsinapse-data-io,代码行数:25,代码来源:CellStyleBorderTest.java

示例11: getHeadCellStyle

import org.apache.poi.hssf.util.HSSFColor; //导入依赖的package包/类
/**
 * 
 * @Title: getCellStyle
 * @Description: TODO(设置表头样式)
 * @param wb
 * @return
 */
private CellStyle getHeadCellStyle(Workbook wb) {
	CellStyle style = wb.createCellStyle();
	Font font = wb.createFont();
	font.setFontName("宋体");
	font.setFontHeightInPoints((short) 12);// 设置字体大小
	font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// 加粗
	style.setFillForegroundColor(HSSFColor.LIME.index);// 设置背景色
	style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
	style.setAlignment(HSSFCellStyle.SOLID_FOREGROUND);// 让单元格居中
	style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
	style.setBorderTop(CellStyle.BORDER_THIN);
	style.setBorderLeft(CellStyle.BORDER_THIN);
	style.setBorderRight(CellStyle.BORDER_THIN);
	style.setBorderBottom(CellStyle.BORDER_THIN);
	// style.setWrapText(true);//设置自动换行
	style.setFont(font);
	return style;
}
 
开发者ID:ls960972314,项目名称:report,代码行数:26,代码来源:ReportServiceImpl.java

示例12: getHeaderStyle

import org.apache.poi.hssf.util.HSSFColor; //导入依赖的package包/类
/**
 * header样式
 *
 * @return
 */
public CellStyle getHeaderStyle() {
    CellStyle headerStyle = workbook.createCellStyle();

    // 设置单元格的背景颜色为淡蓝色
    headerStyle.setFillForegroundColor(HSSFColor.PALE_BLUE.index);
    headerStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
    // 设置单元格居中对齐
    headerStyle.setAlignment(CellStyle.ALIGN_CENTER);
    // 设置单元格垂直居中对齐
    headerStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    // 创建单元格内容显示不下时自动换行
    headerStyle.setWrapText(true);
    // 设置单元格字体样式
    Font font = workbook.createFont();
    // 设置字体加粗
    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    font.setFontName("宋体");
    font.setFontHeight((short) 200);
    headerStyle.setFont(font);
    // 设置单元格边框为细线条
    setBorder(headerStyle);

    return headerStyle;
}
 
开发者ID:goribun,项目名称:common-utils,代码行数:30,代码来源:StyleConfiguration.java

示例13: getColor

import org.apache.poi.hssf.util.HSSFColor; //导入依赖的package包/类
@Override
Color getColor(org.apache.poi.ss.usermodel.Color poiColor, Color defaultColor) {
    if (poiColor == null || poiColor == HSSFColorPredefined.AUTOMATIC.getColor()) {
        return defaultColor;
    }

    short[] triplet = ((HSSFColor) poiColor).getTriplet();

    if (triplet == null) {
        return defaultColor;
    }

    int a = 0xff;
    int r = triplet[0];
    int g = triplet[1];
    int b = triplet[2];
    return new Color(r, g, b, a);
}
 
开发者ID:xzel23,项目名称:meja,代码行数:19,代码来源:PoiWorkbook.java

示例14: createPoiFont

import org.apache.poi.hssf.util.HSSFColor; //导入依赖的package包/类
private static org.apache.poi.ss.usermodel.Font createPoiFont(PoiWorkbook workbook, Font other) {
    org.apache.poi.ss.usermodel.Font poiFont = workbook.getPoiWorkbook().createFont();
    poiFont.setFontHeightInPoints((short) Math.round(other.getSizeInPoints()));
    poiFont.setFontName(other.getFamily());

    final org.apache.poi.ss.usermodel.Color poiTextColor = workbook.getPoiColor(other.getColor());
    if (poiFont instanceof HSSFFont && poiTextColor instanceof HSSFColor) {
        poiFont.setColor(((HSSFColor) poiTextColor).getIndex());
    } else if (poiFont instanceof XSSFFont && poiTextColor instanceof XSSFColor) {
        ((XSSFFont) poiFont).setColor((XSSFColor) poiTextColor);
    } else {
        // it should both either be XSSF _or_ HSSF implementations so this
        // line should never be reached.
        throw new IllegalStateException();
    }

    poiFont.setBold(other.isBold());
    poiFont.setItalic(other.isItalic());
    poiFont.setStrikeout(other.isStrikeThrough());
    poiFont.setUnderline(other.isUnderlined() ? org.apache.poi.ss.usermodel.Font.U_SINGLE
            : org.apache.poi.ss.usermodel.Font.U_NONE);

    return poiFont;
}
 
开发者ID:xzel23,项目名称:meja,代码行数:25,代码来源:PoiFont.java

示例15: testColorConversionHssf

import org.apache.poi.hssf.util.HSSFColor; //导入依赖的package包/类
/**
 * Test converting color from Meja to POI color and back again does not
 * change the color value.
 *
 * This test checks the implementation for HSSF.
 */
@Test
public void testColorConversionHssf() {
    PoiWorkbook.PoiHssfWorkbook wb = (PoiWorkbook.PoiHssfWorkbook) PoiWorkbookFactory.instance().createXls();
    // HSSF maps colors to more or less matching nearest colors.
    Set<String> used = new HashSet<>();
    for (Color col : Color.values()) {
        HSSFColor poiColor = wb.getPoiColor(col);
        short[] t = poiColor.getTriplet();
        Color expected = new Color(t[0], t[1], t[2]);
        Color actual = wb.getColor(poiColor, Color.BLACK);
        assertEquals(expected, actual);
        used.add(expected.toString());
    }
    assertTrue(used.size()>20);
}
 
开发者ID:xzel23,项目名称:meja,代码行数:22,代码来源:PoiTest.java


注:本文中的org.apache.poi.hssf.util.HSSFColor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。