本文整理汇总了Java中org.apache.poi.ss.usermodel.Cell.getCellStyle方法的典型用法代码示例。如果您正苦于以下问题:Java Cell.getCellStyle方法的具体用法?Java Cell.getCellStyle怎么用?Java Cell.getCellStyle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.ss.usermodel.Cell
的用法示例。
在下文中一共展示了Cell.getCellStyle方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildGridExcelData
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
private int buildGridExcelData(ReportGrid gridModel, Sheet sheet, int starDataRow, Map<String, CellStyle> styles) {
CellStyle dataAlignLeftStyle = styles.get(GridStyleType.dataAlignLeftStyle.name());
CellStyle dataAlignCenterStyle = styles.get(GridStyleType.dataAlignCenterStyle.name());
CellStyle dataAlignRightStyle = styles.get(GridStyleType.dataAlignRightStyle.name());
IFillCellInterceptor interceptor = ContextHolder.getBean(IFillCellInterceptor.BEAN_ID);
List<ReportGridHeader> bottomGridExcelHeader = new ArrayList<ReportGridHeader>();
this.calculateBottomColumnHeader(gridModel.getGridHeaderModelList(), bottomGridExcelHeader);
List<Map<String, Object>> excelDatas = gridModel.getGridDataModel().getDatas();
String treeColumn = gridModel.getGridDataModel().getTreeColumn();
int excelDataIndex = 0;
int rowSize = excelDatas.size();
Cell cell;
Row row;
for (int rowNum = starDataRow; rowNum <= starDataRow + rowSize - 1; rowNum++) {
row = sheet.createRow(rowNum);
Map<String, Object> map = excelDatas.get(excelDataIndex);
int j = 0;
for (ReportGridHeader header : bottomGridExcelHeader) {
Object value = map.get(header.getColumnName());
int dataAlign = header.getDataAlign();
cell = row.createCell(j);
if (dataAlign == 1) {
cell.setCellStyle(dataAlignCenterStyle);
} else if (dataAlign == 2) {
cell.setCellStyle(dataAlignRightStyle);
} else {
cell.setCellStyle(dataAlignLeftStyle);
}
if (value != null) {
if (header.getColumnName().equalsIgnoreCase(treeColumn)) {
int level = this.calculateIndentationCount(value.toString());
cell.setCellStyle(new GridStyleBuilder().createIndentationCellStyle(sheet.getWorkbook(), level == 0 ? 0 : level * 2));
cell.setCellValue(value.toString());
} else {
if (value instanceof BigDecimal || value instanceof Float || value instanceof Double){
CellStyle style = cell.getCellStyle();
DataFormat format = sheet.getWorkbook().createDataFormat();
String displayFormat = header.getDisplayFormat();
if (StringUtils.isEmpty(displayFormat))
style.setDataFormat(format.getFormat("#,##0.00"));
else
style.setDataFormat(format.getFormat(displayFormat));
cell.setCellStyle(style);
}
interceptor.fillCellValue(sheet, row, cell, value);
}
} else {
cell.setCellValue("");
}
sheet.setColumnWidth(cell.getColumnIndex(), header.getWidth() / 6 > 255 ? 254 * 256 : header.getWidth() / 6 * 256);
j++;
}
excelDataIndex++;
}
return starDataRow + rowSize;
}