當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。