org.apache.poi.ss.usermodel.Cell.getCellStyle()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.6k)|赞(0)|评价(0)|浏览(294)

本文整理了Java中org.apache.poi.ss.usermodel.Cell.getCellStyle()方法的一些代码示例,展示了Cell.getCellStyle()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cell.getCellStyle()方法的具体详情如下:
包路径:org.apache.poi.ss.usermodel.Cell
类名称:Cell
方法名:getCellStyle

Cell.getCellStyle介绍

[英]Return the cell's style.
[中]返回单元格的样式。

代码示例

代码示例来源:origin: org.apache.poi/poi

/**
 * Create and return a Format based on the format string from a  cell's
 * style. If the pattern cannot be parsed, return a default pattern.
 *
 * @param cell The Excel cell
 * @return A Format representing the excel format. May return null.
 */
public Format createFormat(Cell cell) {
  int formatIndex = cell.getCellStyle().getDataFormat();
  String formatStr = cell.getCellStyle().getDataFormatString();
  return createFormat(cell.getNumericCellValue(), formatIndex, formatStr);
}

代码示例来源:origin: looly/hutool

/**
 * 为指定单元格获取或者创建样式,返回样式后可以设置样式内容
 * 
 * @param x X坐标,从0计数,既列号
 * @param y Y坐标,从0计数,既行号
 * @return {@link CellStyle}
 * @since 4.1.4
 */
public CellStyle getOrCreateCellStyle(int x, int y) {
  final Cell cell = getOrCreateCell(x, y);
  CellStyle cellStyle = cell.getCellStyle();
  if (null == cellStyle) {
    cellStyle = this.workbook.createCellStyle();
    cell.setCellStyle(cellStyle);
  }
  return cellStyle;
}

代码示例来源:origin: looly/hutool

/**
 * 为指定单元格获取或者创建样式,返回样式后可以设置样式内容
 * 
 * @param x X坐标,从0计数,既列号
 * @param y Y坐标,从0计数,既行号
 * @return {@link CellStyle}
 * @since 4.1.4
 */
public CellStyle getOrCreateCellStyle(int x, int y) {
  final Cell cell = getOrCreateCell(x, y);
  CellStyle cellStyle = cell.getCellStyle();
  if (null == cellStyle) {
    cellStyle = this.workbook.createCellStyle();
    cell.setCellStyle(cellStyle);
  }
  return cellStyle;
}

代码示例来源:origin: org.apache.poi/poi

/**
* @param cell cell to extract format from
* @param cfEvaluator ConditionalFormattingEvaluator to use, or null if none in this context
* @return number format from highest-priority rule with a number format, or the cell style, or null if none of the above apply/are defined
*/
public static ExcelNumberFormat from(Cell cell, ConditionalFormattingEvaluator cfEvaluator) {
  if (cell == null) return null;
    ExcelNumberFormat nf = null;
    if (cfEvaluator != null) {
    // first one wins (priority order, per Excel help)
    List<EvaluationConditionalFormatRule> rules = cfEvaluator.getConditionalFormattingForCell(cell);
    for (EvaluationConditionalFormatRule rule : rules) {
      nf = rule.getNumberFormat();
      if (nf != null) break;
    }
  }
  if (nf == null) {
    CellStyle style = cell.getCellStyle();
    nf = ExcelNumberFormat.from(style);
  }
  return nf;
}

代码示例来源:origin: org.apache.poi/poi

/**
 *  Check if a cell contains a date, checking only for internal
 *   excel date formats.
 *  As Excel stores a great many of its dates in "non-internal"
 *   date formats, you will not normally want to use this method.
 *  @see #isADateFormat(int,String)
 *  @see #isInternalDateFormat(int)
 */
public static boolean isCellInternalDateFormatted(Cell cell) {
  if (cell == null) return false;
  boolean bDate = false;
  double d = cell.getNumericCellValue();
  if ( DateUtil.isValidExcelDate(d) ) {
    CellStyle style = cell.getCellStyle();
    int i = style.getDataFormat();
    bDate = isInternalDateFormat(i);
  }
  return bDate;
}

代码示例来源:origin: looly/hutool

/**
 * 获取数字类型的单元格值
 * 
 * @param cell 单元格
 * @return 单元格值,可能为Long、Double、Date
 */
private static Object getNumericValue(Cell cell) {
  final double value = cell.getNumericCellValue();
  final CellStyle style = cell.getCellStyle();
  if (null == style) {
    return value;
  }
  final short formatIndex = style.getDataFormat();
  // 判断是否为日期
  if (isDateType(cell, formatIndex)) {
    return DateUtil.date(cell.getDateCellValue());// 使用Hutool的DateTime包装
  }
  final String format = style.getDataFormatString();
  // 普通数字
  if (null != format && format.indexOf(StrUtil.C_DOT) < 0) {
    final long longPart = (long) value;
    if (longPart == value) {
      // 对于无小数部分的数字类型,转为Long
      return longPart;
    }
  }
  return value;
}

代码示例来源:origin: looly/hutool

/**
 * 获取数字类型的单元格值
 * 
 * @param cell 单元格
 * @return 单元格值,可能为Long、Double、Date
 */
private static Object getNumericValue(Cell cell) {
  final double value = cell.getNumericCellValue();
  final CellStyle style = cell.getCellStyle();
  if (null == style) {
    return value;
  }
  final short formatIndex = style.getDataFormat();
  // 判断是否为日期
  if (isDateType(cell, formatIndex)) {
    return DateUtil.date(cell.getDateCellValue());// 使用Hutool的DateTime包装
  }
  final String format = style.getDataFormatString();
  // 普通数字
  if (null != format && format.indexOf(StrUtil.C_DOT) < 0) {
    final long longPart = (long) value;
    if (longPart == value) {
      // 对于无小数部分的数字类型,转为Long
      return longPart;
    }
  }
  return value;
}

代码示例来源:origin: org.apache.poi/poi

public static void cloneCellContent(Cell srcCell, Cell destCell, Map<Integer, CellStyle> styleMap) {   
   if(styleMap != null) {   
     if(srcCell.getSheet().getWorkbook() == destCell.getSheet().getWorkbook()){   
       destCell.setCellStyle(srcCell.getCellStyle());   
     } else {
       int stHashCode = srcCell.getCellStyle().hashCode();   
       CellStyle newCellStyle = styleMap.get(stHashCode);   
       if(newCellStyle == null){   
         newCellStyle = destCell.getSheet().getWorkbook().createCellStyle();   
         newCellStyle.cloneStyleFrom(srcCell.getCellStyle());   
         styleMap.put(stHashCode, newCellStyle);

代码示例来源:origin: org.apache.poi/poi-ooxml

_out.write("<c");
writeAttribute("r", ref);
CellStyle cellStyle = cell.getCellStyle();
if (cellStyle.getIndex() != 0) {

代码示例来源:origin: org.apache.poi/poi

private ValueAndFormat getCellValue(Cell cell) {
  if (cell != null) {
    final String format = cell.getCellStyle().getDataFormatString();
    CellType type = cell.getCellType();
    if (type == CellType.FORMULA) {
      type = cell.getCachedFormulaResultType();
    }
    switch (type) {
      case NUMERIC:
        return new ValueAndFormat(Double.valueOf(cell.getNumericCellValue()), format, decimalTextFormat);
      case STRING:
      case BOOLEAN:
        return new ValueAndFormat(cell.getStringCellValue(), format);
      default:
        break;
    }
  }
  return new ValueAndFormat("", "");
}
/**

代码示例来源:origin: org.apache.poi/poi-ooxml

private void handleNonStringCell(StringBuilder text, Cell cell, DataFormatter formatter) {
  CellType type = cell.getCellType();
  if (type == CellType.FORMULA) {
    type = cell.getCachedFormulaResultType();
  }
  if (type == CellType.NUMERIC) {
    CellStyle cs = cell.getCellStyle();
    if (cs != null && cs.getDataFormatString() != null) {
      String contents = formatter.formatRawCellContents(
          cell.getNumericCellValue(), cs.getDataFormat(), cs.getDataFormatString());
      checkMaxTextSize(text, contents);
      text.append(contents);
      return;
    }
  }
  // No supported styling applies to this cell
  String contents = ((XSSFCell)cell).getRawValue();
  if (contents != null) {
    checkMaxTextSize(text, contents);
    text.append(contents);
  }
}

代码示例来源:origin: org.apache.poi/poi

CellStyle originalStyle = cell.getCellStyle();
CellStyle newStyle = null;
Map<String, Object> values = getFormatProperties(originalStyle);

代码示例来源:origin: org.apache.poi/poi

CellStyle style = cell.getCellStyle();
CellType cellType = cell.getCellType();

代码示例来源:origin: pentaho/pentaho-kettle

/**
 * Set specified cell format
 *
 * @param excelFieldFormat the specified format
 * @param cell             the cell to set up format
 */
private void setDataFormat( String excelFieldFormat, Cell cell ) {
 if ( log.isDebug() ) {
  logDebug( BaseMessages.getString( PKG, "ExcelWriterStep.Log.SetDataFormat", excelFieldFormat, CellReference.convertNumToColString( cell.getColumnIndex() ), cell.getRowIndex() ) );
 }
 DataFormat format = data.wb.createDataFormat();
 short formatIndex = format.getFormat( excelFieldFormat );
 CellStyle style = data.wb.createCellStyle();
 style.cloneStyleFrom( cell.getCellStyle() );
 style.setDataFormat( formatIndex );
 cell.setCellStyle( style );
}

代码示例来源:origin: pentaho/pentaho-kettle

Cell styleCell = getCellFromReference( styleRef );
 if ( styleCell != null && cell != styleCell ) {
  cell.setCellStyle( styleCell.getCellStyle() );
data.cacheStyle( fieldNr, cell.getCellStyle() );
} else {
 Font origFont = data.wb.getFontAt( cell.getCellStyle().getFontIndex() );
 Font hlink_font = data.wb.createFont();
 CellStyle style = cell.getCellStyle();
 style.setFont( hlink_font );
 cell.setCellStyle( style );
 data.cacheLinkStyle( fieldNr, cell.getCellStyle() );

代码示例来源:origin: pentaho/pentaho-kettle

CellStyle baseCellStyle = baseCell.getCellStyle();
DataFormat format = stepData.wb.createDataFormat();
for ( int i = 0; i < stepData.inputRowMeta.size(); i++ ) {
 Cell cell = xlsRow.getCell( i );
 CellStyle cellStyle = cell.getCellStyle();

代码示例来源:origin: pentaho/pentaho-kettle

cellStyle.cloneStyleFrom( cell.getCellStyle() );
cell = xlsRow.createCell( 6 );
cellStyle.setDataFormat( format.getFormat( "##0,000.0" ) );

代码示例来源:origin: org.apache.poi/poi-ooxml

setCellStyle(srcCell == null ? null : srcCell.getCellStyle());

代码示例来源:origin: com.haulmont.thirdparty/poi

/**
 * Create and return a Format based on the format string from a  cell's
 * style. If the pattern cannot be parsed, return a default pattern.
 *
 * @param cell The Excel cell
 * @return A Format representing the excel format. May return null.
 */
public Format createFormat(Cell cell) {
  int formatIndex = cell.getCellStyle().getDataFormat();
  String formatStr = cell.getCellStyle().getDataFormatString();
  return createFormat(cell.getNumericCellValue(), formatIndex, formatStr);
}

代码示例来源:origin: com.b2international.snowowl/com.b2international.snowowl.datastore.server

/**
 * Returns true if the cell (NOT the text inside) is set to bold.
 * @param cell
 * @return
 */
public static boolean isBold(Cell cell) {
  CellStyle style = cell.getCellStyle();
  Workbook workBook = cell.getSheet().getWorkbook();
  Font font = workBook.getFontAt(style.getFontIndex());
  XSSFFont xssfFont = (XSSFFont) font;
  return xssfFont.getBold();
}

相关文章