當前位置: 首頁>>代碼示例>>Java>>正文


Java HSSFWorkbook.getCustomPalette方法代碼示例

本文整理匯總了Java中org.apache.poi.hssf.usermodel.HSSFWorkbook.getCustomPalette方法的典型用法代碼示例。如果您正苦於以下問題:Java HSSFWorkbook.getCustomPalette方法的具體用法?Java HSSFWorkbook.getCustomPalette怎麽用?Java HSSFWorkbook.getCustomPalette使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.poi.hssf.usermodel.HSSFWorkbook的用法示例。


在下文中一共展示了HSSFWorkbook.getCustomPalette方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createColor

import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的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

示例2: createHSSFCellStyle

import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的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: replaceColorsPallete

import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的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

示例4: buildHSSFColor

import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
private HSSFColor buildHSSFColor(HSSFWorkbook wb,String colorStr){
	String[] color=colorStr.split(",");
	HSSFPalette palette=wb.getCustomPalette();
	byte r=BigInteger.valueOf(Integer.valueOf(color[0])).byteValue();
	byte g=BigInteger.valueOf(Integer.valueOf(color[1])).byteValue();
	byte b=BigInteger.valueOf(Integer.valueOf(color[2])).byteValue();
	HSSFColor targetColor=palette.findColor(r,g,b);
	if(targetColor==null){
		palette.setColorAtIndex(HSSFColorPredefined.LAVENDER.getIndex(), r, g,b);
		targetColor=palette.getColor(HSSFColorPredefined.LAVENDER.getIndex());
	}
	return targetColor;
}
 
開發者ID:youseries,項目名稱:ureport,代碼行數:14,代碼來源:CellStyleContext.java

示例5: xlsToHtml

import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
private void xlsToHtml() throws Throwable {
	FileOutputStream output = new FileOutputStream(new File(htmlPath));
	StringBuffer htmlHeaderSB = new StringBuffer();
	htmlHeaderSB.append("<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' "
			+ "xmlns='http://www.w3.org/TR/REC-html40'>");
	htmlHeaderSB.append("<head><meta http-equiv=Content-Type content='text/html; charset=utf-8'><meta name=ProgId content=Excel.Sheet>"
			+ "</head><body>");
	output.write(htmlHeaderSB.toString().getBytes());
	HSSFSheet sheet;
	HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(filePath)); // 獲整個Excel
	for (int sheetIndex = 0; sheetIndex < workbook.getNumberOfSheets(); sheetIndex++) {
		if (workbook.getSheetAt(sheetIndex) != null) {
			sheet = workbook.getSheetAt(sheetIndex);// 獲得不為空的這個sheet
			if (sheet != null) {
				int firstRowNum = sheet.getFirstRowNum(); // 第一行
				int lastRowNum = sheet.getLastRowNum(); // 最後一行
				// 構造Table
				output.write(("<table width=\"100%\" style=\"border:1px solid #000;border-width:1px 0 0 1px;margin:2px 0 2px 0;"
						+ "border-collapse:collapse;\">").getBytes());
				for (int rowNum = firstRowNum; rowNum <= lastRowNum; rowNum++) {
					if (sheet.getRow(rowNum) != null) {// 如果行不為空,
						HSSFRow row = sheet.getRow(rowNum);
						short firstCellNum = row.getFirstCellNum(); // 該行的第一個單元格
						short lastCellNum = row.getLastCellNum(); // 該行的最後一個單元格
						int height = (int) (row.getHeight() / 15.625); // 行的高度
						output.write(("<tr height=\"" + height + "\" style=\"border:1px solid #000;border-width:0 1px 1px 0;"
								+ "margin:2px 0 2px 0;\">").getBytes());
						for (short cellNum = firstCellNum; cellNum <= lastCellNum; cellNum++) { // 循環該行的每一個單元格
							HSSFCell cell = row.getCell(cellNum);
							if (cell != null) {
								if (cell.getCellType() != HSSFCell.CELL_TYPE_BLANK) {
									StringBuffer tdStyle = new StringBuffer("<td style=\"border:1px solid #000; border-width:0 1px 1px 0;"
											+ "margin:2px 0 2px 0; ");
									HSSFCellStyle cellStyle = cell.getCellStyle();
									HSSFPalette palette = workbook.getCustomPalette(); // 類HSSFPalette用於求顏色的國際標準形式
									HSSFColor hColor = palette.getColor(cellStyle.getFillForegroundColor());
									HSSFColor hColor2 = palette.getColor(cellStyle.getFont(workbook).getColor());
									String bgColor = convertToStardColor(hColor);// 背景顏色
									short boldWeight = cellStyle.getFont(workbook).getBoldweight(); // 字體粗細
									short fontHeight = (short) (cellStyle.getFont(workbook).getFontHeight() / 2); // 字體大小
									String fontColor = convertToStardColor(hColor2); // 字體顏色
									if (bgColor != null && !"".equals(bgColor.trim())) {
										tdStyle.append(" background-color:");
										tdStyle.append(bgColor);
										tdStyle.append("; ");
									}
									if (fontColor != null && !"".equals(fontColor.trim())) {
										tdStyle.append(" color:");
										tdStyle.append(fontColor);
										tdStyle.append("; ");
									}
									tdStyle.append(" font-weight:");
									tdStyle.append(boldWeight);
									tdStyle.append("; ");
									tdStyle.append(" font-size: ");
									tdStyle.append(fontHeight);
									tdStyle.append("%;");
									output.write((tdStyle + "\"").getBytes());

									int width = (int) (sheet.getColumnWidth(cellNum) / 35.7); //
									int cellRegionCol = getMergerCellRegionCol(sheet, rowNum, cellNum); // 合並的列(solspan)
									int cellRegionRow = getMergerCellRegionRow(sheet, rowNum, cellNum);// 合並的行(rowspan)
									String align = convertAlignToHtml(cellStyle.getAlignment()); //
									String vAlign = convertVerticalAlignToHtml(cellStyle.getVerticalAlignment());

									output.write((" align=\"" + align + "\" valign=\"" + vAlign + "\" width=\"" + width + "\" ").getBytes());
									output.write((" colspan=\"" + cellRegionCol + "\" rowspan=\"" + cellRegionRow + "\"").getBytes());
									output.write((">" + getCellValue(cell) + "</td>").getBytes());
								}
							}
						}
						output.write("</tr>".getBytes());
					}
				}
				output.write(("</table>").getBytes());
			}
		}
	}
	output.write(("</body></html>").getBytes());
	output.close();
}
 
開發者ID:MobClub,項目名稱:BBSSDK-for-Android,代碼行數:82,代碼來源:OfficeConverter.java

示例6: createHSSFCellStyles

import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
private Map<String, CellStyle> createHSSFCellStyles(Workbook wb, int[] contextBgColor, int[] contextFontColor, int contextFontSize, int contextFontAlign, int[] headerBgColor,
		int[] headerFontColor, int headerFontSize, int headerAlign) {
	Map<String, CellStyle> styles = new HashMap<String, CellStyle>();

	HSSFWorkbook workbook = (HSSFWorkbook) wb;
	HSSFPalette palette = workbook.getCustomPalette();
	palette.setColorAtIndex((short) 11, (byte) contextBgColor[0], (byte) contextBgColor[1], (byte) contextBgColor[2]);
	palette.setColorAtIndex((short) 12, (byte) contextFontColor[0], (byte) contextFontColor[1], (byte) contextFontColor[2]);
	palette.setColorAtIndex((short) 13, (byte) headerBgColor[0], (byte) headerBgColor[1], (byte) headerBgColor[2]);
	palette.setColorAtIndex((short) 14, (byte) headerFontColor[0], (byte) headerFontColor[1], (byte) headerFontColor[2]);

	HSSFFont headerFont = workbook.createFont();
	headerFont.setCharSet(HSSFFont.DEFAULT_CHARSET);
	headerFont.setFontName("宋體");
	headerFont.setColor((short) 14);
	headerFont.setBold(true);
	headerFont.setFontHeightInPoints((short) headerFontSize);
	CellStyle headerStyle = this.createBorderCellStyle(workbook, true);

	headerStyle.setFont(headerFont);
	headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
	headerStyle.setFillForegroundColor((short) 13);
	this.setCellStyleAligment(headerStyle, headerAlign);
	headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
	styles.put(GridStyleType.headerStyle.name(), headerStyle);

	HSSFFont dataFont = workbook.createFont();
	dataFont.setColor((short) 12);
	dataFont.setFontHeightInPoints((short) contextFontSize);
	dataFont.setCharSet(HSSFFont.DEFAULT_CHARSET);
	dataFont.setFontName("宋體");

	CellStyle dataAlignLeftStyle = this.createBorderCellStyle(workbook, true);
	dataAlignLeftStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
	dataAlignLeftStyle.setFillForegroundColor((short) 11);
	dataAlignLeftStyle.setFont(dataFont);
	dataAlignLeftStyle.setVerticalAlignment(VerticalAlignment.CENTER);
	dataAlignLeftStyle.setWrapText(true);
	dataAlignLeftStyle.setAlignment(HorizontalAlignment.LEFT);
	styles.put(GridStyleType.dataAlignLeftStyle.name(), dataAlignLeftStyle);

	CellStyle dataAlignCenterStyle = this.createBorderCellStyle(workbook, true);
	dataAlignCenterStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
	dataAlignCenterStyle.setFillForegroundColor((short) 11);
	dataAlignCenterStyle.setFont(dataFont);
	dataAlignCenterStyle.setVerticalAlignment(VerticalAlignment.CENTER);
	dataAlignCenterStyle.setWrapText(true);
	dataAlignCenterStyle.setAlignment(HorizontalAlignment.CENTER);
	styles.put(GridStyleType.dataAlignCenterStyle.name(), dataAlignCenterStyle);

	CellStyle dataAlignRightStyle = this.createBorderCellStyle(workbook, true);
	dataAlignRightStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
	dataAlignRightStyle.setFillForegroundColor((short) 11);
	dataAlignRightStyle.setFont(dataFont);
	dataAlignRightStyle.setVerticalAlignment(VerticalAlignment.CENTER);
	dataAlignRightStyle.setWrapText(true);
	dataAlignRightStyle.setAlignment(HorizontalAlignment.RIGHT);
	styles.put(GridStyleType.dataAlignRightStyle.name(), dataAlignRightStyle);

	CellStyle dateStyle = this.createBorderCellStyle(workbook, true);
	CreationHelper helper = workbook.getCreationHelper();
	dateStyle.setDataFormat(helper.createDataFormat().getFormat("m/d/yy h:mm"));
	dateStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
	dateStyle.setFillForegroundColor((short) 11);
	dateStyle.setFont(dataFont);
	dateStyle.setVerticalAlignment(VerticalAlignment.CENTER);
	this.setCellStyleAligment(dateStyle, contextFontAlign);
	styles.put(GridStyleType.dateStyle.name(), dateStyle);

	return styles;
}
 
開發者ID:bsteker,項目名稱:bdf2,代碼行數:72,代碼來源:GridStyleBuilder.java

示例7: HSSFHtmlHelper

import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
public HSSFHtmlHelper(HSSFWorkbook wb) {
    this.wb = wb;
    colors = wb.getCustomPalette();
}
 
開發者ID:rushingpig,項目名稱:poix,代碼行數:5,代碼來源:StylerHelper.java


注:本文中的org.apache.poi.hssf.usermodel.HSSFWorkbook.getCustomPalette方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。