本文整理汇总了Java中org.apache.poi.hssf.usermodel.HSSFPalette.getColor方法的典型用法代码示例。如果您正苦于以下问题:Java HSSFPalette.getColor方法的具体用法?Java HSSFPalette.getColor怎么用?Java HSSFPalette.getColor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.hssf.usermodel.HSSFPalette
的用法示例。
在下文中一共展示了HSSFPalette.getColor方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createColor
import org.apache.poi.hssf.usermodel.HSSFPalette; //导入方法依赖的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;
}
示例2: buildHSSFColor
import org.apache.poi.hssf.usermodel.HSSFPalette; //导入方法依赖的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;
}
示例3: getHSSFColorString
import org.apache.poi.hssf.usermodel.HSSFPalette; //导入方法依赖的package包/类
/**
* HSSF色の文字列表現を取得する
*
* @param workbook ブック
* @param index 色インデックス
* @return HSSF色の文字列表現
*/
private static String getHSSFColorString( HSSFWorkbook workbook, short index) {
HSSFPalette palette = workbook.getCustomPalette();
if ( palette.getColor( index) != null) {
HSSFColor color = palette.getColor( index);
return color.getHexString();
} else {
return "";
}
}
示例4: getHSSFColorString
import org.apache.poi.hssf.usermodel.HSSFPalette; //导入方法依赖的package包/类
private static String getHSSFColorString( HSSFWorkbook workbook, short index) {
HSSFPalette palette = workbook.getCustomPalette();
if ( palette.getColor( index) != null) {
HSSFColor color = palette.getColor( index);
return color.getHexString();
} else {
return "";
}
}
示例5: poiStyle2Netxilia
import org.apache.poi.hssf.usermodel.HSSFPalette; //导入方法依赖的package包/类
public static Styles poiStyle2Netxilia(CellStyle poiStyle, Font font, HSSFPalette palette,
NetxiliaStyleResolver styleResolver) {
List<Style> entries = new ArrayList<Style>();
if (!poiStyle.getWrapText()) {
entries.add(DefaultStyle.nowrap.getStyle());
}
// font
if (font.getItalic()) {
entries.add(DefaultStyle.italic.getStyle());
}
if (font.getStrikeout()) {
entries.add(DefaultStyle.strikeout.getStyle());
}
if (font.getBoldweight() == Font.BOLDWEIGHT_BOLD) {
entries.add(DefaultStyle.bold.getStyle());
}
if (font.getUnderline() != Font.U_NONE) {
entries.add(DefaultStyle.underline.getStyle());
}
// borders
if (poiStyle.getBorderBottom() != CellStyle.BORDER_NONE) {
entries.add(DefaultStyle.borderBottom.getStyle());
}
if (poiStyle.getBorderLeft() != CellStyle.BORDER_NONE) {
entries.add(DefaultStyle.borderLeft.getStyle());
}
if (poiStyle.getBorderTop() != CellStyle.BORDER_NONE) {
entries.add(DefaultStyle.borderTop.getStyle());
}
if (poiStyle.getBorderRight() != CellStyle.BORDER_NONE) {
entries.add(DefaultStyle.borderRight.getStyle());
}
// align
switch (poiStyle.getAlignment()) {
case CellStyle.ALIGN_LEFT:
entries.add(DefaultStyle.alignLeft.getStyle());
break;
case CellStyle.ALIGN_RIGHT:
entries.add(DefaultStyle.alignRight.getStyle());
break;
case CellStyle.ALIGN_CENTER:
entries.add(DefaultStyle.alignCenter.getStyle());
break;
case CellStyle.ALIGN_JUSTIFY:
entries.add(DefaultStyle.alignJustify.getStyle());
break;
}
if (font != null && font.getColor() != 0) {
HSSFColor poiForeground = palette.getColor(font.getColor());
if (poiForeground != null && poiForeground != HSSFColor.AUTOMATIC.getInstance()) {
Style foregroundDef = styleResolver.approximateForeground(poiForeground.getTriplet()[0],
poiForeground.getTriplet()[1], poiForeground.getTriplet()[2]);
if (foregroundDef != null) {
entries.add(foregroundDef);
}
}
}
if (poiStyle.getFillForegroundColor() != 0) {
HSSFColor poiBackground = palette.getColor(poiStyle.getFillForegroundColor());
if (poiBackground != null && poiBackground != HSSFColor.AUTOMATIC.getInstance()) {
Style backgroundDef = styleResolver.approximateBackground(poiBackground.getTriplet()[0],
poiBackground.getTriplet()[1], poiBackground.getTriplet()[2]);
if (backgroundDef != null) {
entries.add(backgroundDef);
}
}
}
return entries.size() > 0 ? Styles.styles(entries) : null;
}
示例6: xlsToHtml
import org.apache.poi.hssf.usermodel.HSSFPalette; //导入方法依赖的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();
}
示例7: getHssfColor
import org.apache.poi.hssf.usermodel.HSSFPalette; //导入方法依赖的package包/类
public static Color getHssfColor(Workbook workbook, short colorIndex) {
HSSFWorkbook book = (HSSFWorkbook) workbook;
HSSFPalette palette = book.getCustomPalette();
HSSFColor color = palette.getColor(colorIndex);
return color;
}