本文整理了Java中org.apache.poi.ss.usermodel.Cell.setCellStyle()
方法的一些代码示例,展示了Cell.setCellStyle()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cell.setCellStyle()
方法的具体详情如下:
包路径:org.apache.poi.ss.usermodel.Cell
类名称:Cell
方法名:setCellStyle
[英]Set the style for the cell. The style should be an CellStyle created/retreived from the Workbook.
[中]设置单元格的样式。样式应为从工作簿创建/检索的单元格样式。
代码示例来源:origin: stackoverflow.com
Cell cell;
cell = rowxl.createCell(0);
cell.setCellValue("ABC");
cell.setCellStyle(style);
cell = rowxl.createCell(1);
cell.setCellValue("aaa");
cell.setCellStyle(style);
代码示例来源:origin: alibaba/easyexcel
public static Cell createCell(Row row, int colNum, CellStyle cellStyle, Object cellValue, Boolean isNum) {
Cell cell = row.createCell(colNum);
cell.setCellStyle(cellStyle);
if (null != cellValue) {
if (isNum) {
cell.setCellValue(Double.parseDouble(cellValue.toString()));
} else {
cell.setCellValue(cellValue.toString());
}
}
return cell;
}
代码示例来源:origin: pentaho/pentaho-kettle
Cell cell = xlsRow.createCell( 5 );
CellStyle cellStyle = stepData.wb.createCellStyle();
cellStyle.setBorderRight( BorderStyle.THICK );
cellStyle.setFillPattern( FillPatternType.FINE_DOTS );
cell.setCellStyle( cellStyle );
cell = xlsRow.createCell( 6 );
cellStyle.setDataFormat( format.getFormat( "##0,000.0" ) );
cell.setCellStyle( cellStyle );
代码示例来源:origin: primefaces/primefaces
protected void addColumnValue(Row row, String value) {
int cellIndex = row.getLastCellNum() == -1 ? 0 : row.getLastCellNum();
Cell cell = row.createCell(cellIndex);
cell.setCellValue(createRichTextString(value));
if (facetStyle != null) {
cell.setCellStyle(facetStyle);
}
}
代码示例来源:origin: looly/hutool
final CellStyle cellStyle = styleSet.getCellStyle();
if(isHeader && null != headCellStyle) {
cell.setCellStyle(headCellStyle);
} else if (null != cellStyle) {
cell.setCellStyle(cellStyle);
cell.setCellValue(StrUtil.EMPTY);
}else if (value instanceof FormulaCellValue) {
} else if (value instanceof Date) {
if (null != styleSet && null != styleSet.getCellStyleForDate()) {
cell.setCellStyle(styleSet.getCellStyleForDate());
cell.setCellValue((Date) value);
} else if (value instanceof Calendar) {
cell.setCellValue((Calendar) value);
} else if (value instanceof Boolean) {
cell.setCellValue((Boolean) value);
} else if (value instanceof Number) {
if ((value instanceof Double || value instanceof Float) && null != styleSet && null != styleSet.getCellStyleForNumber()) {
cell.setCellStyle(styleSet.getCellStyleForNumber());
cell.setCellValue(((Number) value).doubleValue());
代码示例来源:origin: stackoverflow.com
Workbook wb = WorkbookFactory.create(new File("existing.xls"));
CellStyle origStyle = wb.getCellStyleAt(1); // Or from a cell
Workbook newWB = new XSSFWorkbook();
Sheet sheet = newWB.createSheet();
Row r1 = sheet.createRow(0);
Cell c1 = r1.createCell(0);
CellStyle newStyle = newWB.createCellStyle();
newStyle.cloneStyleFrom(origStyle);
c1.setCellStyle(newStyle);
newWB.write(new FileOutpuStream("new.xlsx"));
代码示例来源:origin: primefaces/primefaces
protected void addColumnValue(Row row, List<UIComponent> components, UIColumn column) {
int cellIndex = row.getLastCellNum() == -1 ? 0 : row.getLastCellNum();
Cell cell = row.createCell(cellIndex);
FacesContext context = FacesContext.getCurrentInstance();
if (column.getExportFunction() != null) {
cell.setCellValue(createRichTextString(exportColumnByFunction(context, column)));
}
else {
StringBuilder builder = new StringBuilder();
for (UIComponent component : components) {
if (component.isRendered()) {
String value = exportValue(context, component);
if (value != null) {
builder.append(value);
}
}
}
cell.setCellValue(createRichTextString(builder.toString()));
}
if (cellStyle != null) {
cell.setCellStyle(cellStyle);
}
}
代码示例来源:origin: looly/hutool
final CellStyle cellStyle = styleSet.getCellStyle();
if(isHeader && null != headCellStyle) {
cell.setCellStyle(headCellStyle);
} else if (null != cellStyle) {
cell.setCellStyle(cellStyle);
cell.setCellValue(StrUtil.EMPTY);
}else if (value instanceof FormulaCellValue) {
} else if (value instanceof Date) {
if (null != styleSet && null != styleSet.getCellStyleForDate()) {
cell.setCellStyle(styleSet.getCellStyleForDate());
cell.setCellValue((Date) value);
} else if (value instanceof Calendar) {
cell.setCellValue((Calendar) value);
} else if (value instanceof Boolean) {
cell.setCellValue((Boolean) value);
} else if (value instanceof Number) {
if ((value instanceof Double || value instanceof Float) && null != styleSet && null != styleSet.getCellStyleForNumber()) {
cell.setCellStyle(styleSet.getCellStyleForNumber());
cell.setCellValue(((Number) value).doubleValue());
代码示例来源:origin: asakusafw/asakusafw
public Cell nextCell() {
Cell cell = row.createCell(column++);
cell.setCellStyle(info.dataStyle);
return cell;
}
代码示例来源:origin: stackoverflow.com
Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet("format sheet");
CellStyle style;
DataFormat format = wb.createDataFormat();
Row row;
Cell cell;
short rowNum = 0;
short colNum = 0;
row = sheet.createRow(rowNum++);
cell = row.createCell(colNum);
cell.setCellValue(11111.25);
style = wb.createCellStyle();
style.setDataFormat(format.getFormat("0.0"));
cell.setCellStyle(style);
row = sheet.createRow(rowNum++);
cell = row.createCell(colNum);
cell.setCellValue(11111.25);
style = wb.createCellStyle();
style.setDataFormat(format.getFormat("#,##0.0000"));
cell.setCellStyle(style);
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
代码示例来源:origin: org.apache.poi/poi
/**
* Creates a cell, gives it a value, and applies a style if provided
*
* @param row the row to create the cell in
* @param column the column index to create the cell in
* @param value The value of the cell
* @param style If the style is not null, then set
* @return A new Cell
*/
public static Cell createCell(Row row, int column, String value, CellStyle style) {
Cell cell = getCell(row, column);
cell.setCellValue(cell.getRow().getSheet().getWorkbook().getCreationHelper()
.createRichTextString(value));
if (style != null) {
cell.setCellStyle(style);
}
return cell;
}
代码示例来源:origin: stackoverflow.com
Row myRow1= sheet.createRow((short) 0);
Row myRow2 = sheet.createRow((short) 1);
for (int i = 1; i <= 10; ++i)
{
Cell blankCell1 = myRow1.createCell(i);
blankCell1.setCellStyle(style);
Cell blankCell2 = myRow2.createCell(i);
blankCell2.setCellStyle(style);
}
代码示例来源:origin: pentaho/pentaho-kettle
if ( cell == null ) {
cellExisted = false;
cell = xlsRow.createCell( posX );
cell.setCellStyle( data.getCachedStyle( fieldNr ) );
} else {
Cell styleCell = getCellFromReference( styleRef );
if ( styleCell != null && cell != styleCell ) {
cell.setCellStyle( styleCell.getCellStyle() );
cell.setCellStyle( data.getCachedLinkStyle( fieldNr ) );
} else {
CellStyle style = cell.getCellStyle();
style.setFont( hlink_font );
cell.setCellStyle( style );
data.cacheLinkStyle( fieldNr, cell.getCellStyle() );
case ValueMetaInterface.TYPE_DATE:
if ( v != null && vMeta.getDate( v ) != null ) {
cell.setCellValue( vMeta.getDate( v ) );
cell.setCellValue( vMeta.getBoolean( v ) );
case ValueMetaInterface.TYPE_BINARY:
if ( v != null ) {
cell.setCellValue( vMeta.getString( v ) );
代码示例来源: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();
styleMap.put(stHashCode, newCellStyle);
destCell.setCellStyle(newCellStyle);
destCell.setCellValue(srcCell.getStringCellValue());
break;
case NUMERIC:
destCell.setCellValue(srcCell.getNumericCellValue());
break;
case BLANK:
break;
case BOOLEAN:
destCell.setCellValue(srcCell.getBooleanCellValue());
break;
case ERROR:
代码示例来源:origin: subtlelib/poi
@VisibleForTesting
Cell createCell(int rowHeightMultiplier, Style style) {
assignRowHeight(rowHeightMultiplier);
Cell cell = row.createCell(index);
cell.setCellStyle(styleRegistry.registerStyle(style));
index += step;
step = 1;
return cell;
}
代码示例来源:origin: stackoverflow.com
String file = "c:\\poitest.xlsx";
FileOutputStream outputStream = new FileOutputStream(file);
Workbook wb = new XSSFWorkbook();
CellStyle unlockedCellStyle = wb.createCellStyle();
unlockedCellStyle.setLocked(false);
Sheet sheet = wb.createSheet();
sheet.protectSheet("password");
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellValue("TEST");
cell.setCellStyle(unlockedCellStyle);
wb.write(outputStream);
outputStream.close();
代码示例来源:origin: stackoverflow.com
Cell cell = xssfCurrentRow.createCell( intCellPosition );
cell.setCellValue( blah );
cell.setCellStyle( (CellStyle) styles.get("style1") );
代码示例来源:origin: stackoverflow.com
for (int i = 0; i < 10000; i++) {
Row row = sheet.createRow(i);
Cell cell = row.createCell((short) 0);
CellStyle style = workbook.createCellStyle();
Font font = workbook.createFont();
font.setBoldweight(Font.BOLDWEIGHT_BOLD);
style.setFont(font);
cell.setCellStyle(style);
}
代码示例来源:origin: stackoverflow.com
String file = "c:\\poitest.xlsx";
FileOutputStream outputStream = new FileOutputStream(file);
Workbook wb = new XSSFWorkbook();
CellStyle unlockedCellStyle = wb.createCellStyle();
unlockedCellStyle.setLocked(false);
Sheet sheet = wb.createSheet();
sheet.protectSheet("password");
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellValue("TEST");
cell.setCellStyle(unlockedCellStyle);
wb.write(outputStream);
outputStream.close();
代码示例来源:origin: apache/tika
@Override
public void applyStyleAndValue(int dbColNum, ResultSet resultSet, Cell cell) throws SQLException {
double d = resultSet.getDouble(dbColNum);
if (resultSet.wasNull()) {
} else {
cell.setCellStyle(style);
}
cell.setCellValue(resultSet.getDouble(dbColNum));
}
}
内容来源于网络,如有侵权,请联系作者删除!