本文整理匯總了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;
}