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


Java HSSFCellStyle类代码示例

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


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

示例1: getCellStyle

import org.apache.poi.hssf.usermodel.HSSFCellStyle; //导入依赖的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

示例2: createHSSFCellStyle

import org.apache.poi.hssf.usermodel.HSSFCellStyle; //导入依赖的package包/类
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.setBold(true); 
	titleFont.setFontHeightInPoints((short) fontSize);

	HSSFCellStyle titleStyle = (HSSFCellStyle) createBorderCellStyle(workbook, true);
	titleStyle.setFont(titleFont);
	titleStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
	titleStyle.setFillForegroundColor((short) 10);
	titleStyle.setAlignment(HorizontalAlignment.CENTER);
	titleStyle.setVerticalAlignment(VerticalAlignment.CENTER);

	return titleStyle;
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:24,代码来源:TitleStyleBuilder.java

示例3: createColumnHeaders

import org.apache.poi.hssf.usermodel.HSSFCellStyle; //导入依赖的package包/类
/**
 */
protected void createColumnHeaders() {
	final HSSFRow headersRow = this.sheet.createRow(0);
	final HSSFFont font = this.workbook.createFont();
	font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
	final HSSFCellStyle style = this.workbook.createCellStyle();
	style.setFont(font);
	style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
	int counter = 1;
	for (int i = 0; i < this.model.getColumnCount(); i++) {
		final HSSFCell cell = headersRow.createCell(counter++);
		// cell.setEncoding(HSSFCell.ENCODING_UTF_16);
		cell.setCellValue(this.model.getColumnName(i));
		cell.setCellStyle(style);
	}
}
 
开发者ID:kiswanij,项目名称:jk-util,代码行数:18,代码来源:JKExcelUtil.java

示例4: copySheets

import org.apache.poi.hssf.usermodel.HSSFCellStyle; //导入依赖的package包/类
/**
 * @param newSheet the sheet to create from the copy.
 * @param sheet the sheet to copy.
 * @param copyStyle true copy the style.
 */
public static void copySheets(HSSFSheet newSheet, HSSFSheet sheet, boolean copyStyle) {
    int maxColumnNum = 0;
    Map<Integer, HSSFCellStyle> styleMap = (copyStyle) ? new HashMap<Integer, HSSFCellStyle>() : null;
    for (int i = sheet.getFirstRowNum(); i <= sheet.getLastRowNum(); i++) {
        HSSFRow srcRow = sheet.getRow(i);
        HSSFRow destRow = newSheet.createRow(i);
        if (srcRow != null) {
            Util.copyRow(sheet, newSheet, srcRow, destRow, styleMap);
            if (srcRow.getLastCellNum() > maxColumnNum) {
                maxColumnNum = srcRow.getLastCellNum();
            }
        }
    }
    for (int i = 0; i <= maxColumnNum; i++) {
        newSheet.setColumnWidth(i, sheet.getColumnWidth(i));
    }
   //Util.copyPictures(newSheet,sheet) ;
}
 
开发者ID:likelet,项目名称:DAtools,代码行数:24,代码来源:Util.java

示例5: convertAlignToHtml

import org.apache.poi.hssf.usermodel.HSSFCellStyle; //导入依赖的package包/类
/**
 * 单元格小平对齐
 */
private String convertAlignToHtml(short alignment) {
	String align = "left";
	switch (alignment) {
		case HSSFCellStyle.ALIGN_LEFT: {
			align = "left";
		} break;
		case HSSFCellStyle.ALIGN_CENTER: {
			align = "center";
		} break;
		case HSSFCellStyle.ALIGN_RIGHT: {
			align = "right";
		} break;
	}
	return align;
}
 
开发者ID:MobClub,项目名称:BBSSDK-for-Android,代码行数:19,代码来源:OfficeConverter.java

示例6: convertVerticalAlignToHtml

import org.apache.poi.hssf.usermodel.HSSFCellStyle; //导入依赖的package包/类
/**
 * 单元格垂直对齐
 */
private String convertVerticalAlignToHtml(short verticalAlignment) {
	String align = "middle";
	switch (verticalAlignment) {
		case HSSFCellStyle.VERTICAL_BOTTOM: {
			align = "bottom";
		} break;
		case HSSFCellStyle.VERTICAL_CENTER: {
			align = "center";
		} break;
		case HSSFCellStyle.VERTICAL_TOP: {
			align = "top";
		} break;
	}
	return align;
}
 
开发者ID:MobClub,项目名称:BBSSDK-for-Android,代码行数:19,代码来源:OfficeConverter.java

示例7: border

import org.apache.poi.hssf.usermodel.HSSFCellStyle; //导入依赖的package包/类
/**
 * 设置边框
 *
 * @param border_status <br>
 *                      BORDER_BOTTOM   底边框 <br>
 *                      BORDER_LEFT     左边框 <br>
 *                      BORDER_RIGHT    右边框 <br>
 *                      BORDER_TOP      顶边框 <br>
 * @return
 */
public ExcelStyle border(Short... border_status) {
    List<Short> shorts = new ArrayList<>();
    for (Short st : border_status) {
        shorts.add(st);
    }
    if (shorts.size() < 1) return this;
    if (shorts.contains(BORDER_BOTTOM)) {
        this.cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
    }
    if (shorts.contains(BORDER_LEFT)) {
        this.cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
    }
    if (shorts.contains(BORDER_RIGHT)) {
        this.cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
    }
    if (shorts.contains(BORDER_TOP)) {
        this.cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
    }
    return this;
}
 
开发者ID:zhangbiy,项目名称:exportExcel,代码行数:31,代码来源:ExcelStyle.java

示例8: createRow

import org.apache.poi.hssf.usermodel.HSSFCellStyle; //导入依赖的package包/类
/**
 *
 * @param rowIndex
 *            int
 */
protected void createRow(final int rowIndex) {
	final HSSFRow row = this.sheet.createRow(rowIndex + 1); // since the
															// rows in
	// excel starts from 1
	// not 0
	final HSSFCellStyle style = this.workbook.createCellStyle();
	style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
	int counter = 1;
	for (int i = 0; i < this.model.getColumnCount(); i++) {
		final HSSFCell cell = row.createCell(counter++);
		// cell.setEncoding(HSSFCell.ENCODING_UTF_16);
		final Object value = this.model.getValueAt(rowIndex, i);
		setValue(cell, value);
		cell.setCellStyle(style);
	}
}
 
开发者ID:kiswanij,项目名称:jk-util,代码行数:22,代码来源:JKExcelUtil.java

示例9: writeCell

import org.apache.poi.hssf.usermodel.HSSFCellStyle; //导入依赖的package包/类
/**
    * Write the value to the cell. Override this method if you have complex data types that may need to be exported.
    * @param value the value of the cell
    * @param cell the cell to write it to
    */
protected void writeCell(Object value, HSSFCell cell, HSSFWorkbook wb)
   {
       if (value instanceof Number)
       {
           Number num = (Number) value;
           cell.setCellValue(num.doubleValue());
       }
       else if (value instanceof Date)
       {
       	HSSFCellStyle cellStyle = wb.createCellStyle();
	    cellStyle.setDataFormat(
	    		wb.getCreationHelper().createDataFormat().getFormat("dd/MM/yyyy HH:mm"));
	    cell.setCellStyle(cellStyle);
		cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
           cell.setCellValue((Date) value);
       }
       else if (value instanceof Calendar)
       {
           cell.setCellValue((Calendar) value);
       }
       else
       {
           cell.setCellValue(new HSSFRichTextString(escapeColumnValue(value)));
       }
   }
 
开发者ID:GovernIB,项目名称:helium,代码行数:31,代码来源:HeliumHssfExportView.java

示例10: createHeader

import org.apache.poi.hssf.usermodel.HSSFCellStyle; //导入依赖的package包/类
private boolean createHeader(WorkbookGeneratorContext context,
                            HSSFSheet sheet,
                            HSSFCellStyle style) {
    if (context.headerNames == null || context.headerNames.isEmpty()) {
        return false;
    }

    int headerRowIndex = 0;
    HSSFRow rowHeader = sheet.createRow(headerRowIndex);
    for (int i = 0; i < context.headerNames.size(); i++) {
        HSSFCell cell = rowHeader.createCell(i);
        sheet.autoSizeColumn((short) i);

        cell.setCellStyle(style);
        cell.setCellValue(new HSSFRichTextString(context.headerNames.get(i)));
    }
    return true;
}
 
开发者ID:otsecbsol,项目名称:linkbinder,代码行数:19,代码来源:PoiWorkbookGeneratorStrategy.java

示例11: getLoadedCellStyle

import org.apache.poi.hssf.usermodel.HSSFCellStyle; //导入依赖的package包/类
protected HSSFCellStyle getLoadedCellStyle(
	FillPatternType mode,
	short backcolor,
	HorizontalAlignment horizontalAlignment,
	VerticalAlignment verticalAlignment,
	short rotation,
	HSSFFont font,
	BoxStyle box,
	boolean isWrapText,
	boolean isCellLocked,
	boolean isCellHidden,
	boolean isShrinkToFit
	)
{
	StyleInfo style = new StyleInfo(mode, backcolor, horizontalAlignment, verticalAlignment, rotation, font, box, isWrapText, isCellLocked, isCellHidden, isShrinkToFit);
	return getLoadedCellStyle(style);
}
 
开发者ID:TIBCOSoftware,项目名称:jasperreports,代码行数:18,代码来源:JRXlsExporter.java

示例12: addBlankElement

import org.apache.poi.hssf.usermodel.HSSFCellStyle; //导入依赖的package包/类
protected void addBlankElement(HSSFCellStyle cellStyle, boolean repeatValue, String currentColumnName) throws JRException {
	if (columnNames.size() > 0) {
		if (columnNames.contains(currentColumnName) && !currentRow.containsKey(currentColumnName) && isColumnReadOnTime(currentRow, currentColumnName)) {	// the column is for export but was not read yet and comes in the expected order
			addBlankCell(cellStyle, currentRow, currentColumnName); 
		} else if ( (columnNames.contains(currentColumnName) && !currentRow.containsKey(currentColumnName) && !isColumnReadOnTime(currentRow, currentColumnName)) 	// the column is for export, was not read yet, but it is read after it should be
				|| (columnNames.contains(currentColumnName) && currentRow.containsKey(currentColumnName)) ) {	// the column is for export and was already read
			
			if(rowIndex == 1 && getCurrentItemConfiguration().isWriteHeader()) {
				writeReportHeader();
			}
			
			writeCurrentRow(currentRow, repeatedValues);
			currentRow.clear();
			addBlankCell(cellStyle, currentRow, currentColumnName);
		}
		
		// set auto fill columns
		if(repeatValue) {
			if (repeatValue && currentColumnName != null && currentColumnName.length() > 0 && cellStyle != null) {
				addBlankCell(cellStyle, repeatedValues, currentColumnName);
			}
		} else {
			repeatedValues.remove(currentColumnName);
		}
	}
}
 
开发者ID:TIBCOSoftware,项目名称:jasperreports,代码行数:27,代码来源:JRXlsMetadataExporter.java

示例13: CellSettings

import org.apache.poi.hssf.usermodel.HSSFCellStyle; //导入依赖的package包/类
public CellSettings(
	CellType cellType,
	HSSFCellStyle cellStyle,
	Object cellValue,
	String formula,
	Hyperlink link
	) 
{
	this.cellType = cellType;
	this.cellStyle = cellStyle;
	this.cellValue = cellValue;
	this.formula = formula;
	this.link = link;
}
 
开发者ID:TIBCOSoftware,项目名称:jasperreports,代码行数:15,代码来源:JRXlsMetadataExporter.java

示例14: importValues

import org.apache.poi.hssf.usermodel.HSSFCellStyle; //导入依赖的package包/类
public void importValues(				
	CellType cellType,
	HSSFCellStyle cellStyle,
	Object cellValue,
	String formula,
	Hyperlink link
	) 
{
	this.cellType = cellType;
	this.cellStyle = cellStyle;
	this.cellValue = cellValue;
	this.formula = formula;
	this.link = link;
}
 
开发者ID:TIBCOSoftware,项目名称:jasperreports,代码行数:15,代码来源:JRXlsMetadataExporter.java

示例15: createHeader

import org.apache.poi.hssf.usermodel.HSSFCellStyle; //导入依赖的package包/类
public static boolean createHeader(HSSFWorkbook workbook, HSSFSheet sheet,String[] header) throws Exception{
	boolean flag = false;
	try {
		HSSFCellStyle cellStyle = workbook.createCellStyle();
		cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
	 	cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);

		HSSFRow head_row = sheet.createRow(0); // 创建行
		// 操作head
		for (short h = 0; h < header.length; h++) {
			createcsv(head_row, h, header[h], cellStyle);
		}
		flag = true;
	} catch (Exception e) {
		logger.error(sheet.getSheetName() + " : 抬头标题创建失败");
		throw e;
	}
	return flag;
}
 
开发者ID:wufeisoft,项目名称:data,代码行数:20,代码来源:CreateExcelUtil.java


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