本文整理汇总了Java中org.apache.poi.ss.usermodel.Cell.setCellStyle方法的典型用法代码示例。如果您正苦于以下问题:Java Cell.setCellStyle方法的具体用法?Java Cell.setCellStyle怎么用?Java Cell.setCellStyle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.ss.usermodel.Cell
的用法示例。
在下文中一共展示了Cell.setCellStyle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildSheet
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
private void buildSheet(SXSSFWorkbook wb,VariableCategory vc,XSSFCellStyle style){
String name=vc.getName();
Sheet sheet=wb.createSheet(name);
Row row=sheet.createRow(0);
List<Variable> variables=vc.getVariables();
for(int i=0;i<variables.size();i++){
sheet.setColumnWidth(i,4000);
Cell cell=row.createCell(i);
Variable var=variables.get(i);
cell.setCellValue(var.getLabel());
cell.setCellStyle(style);
}
}
示例2: setupTotalCell
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
protected void setupTotalCell(Cell cell, final String propId, final int currentRow, final int startRow, int col) {
cell.setCellStyle(getCellStyle(propId, currentRow, startRow, col, true));
final HorizontalAlignment poiAlignment = getGridHolder().getCellAlignment(propId);
CellUtil.setAlignment(cell, poiAlignment);
Class<?> propType = getGridHolder().getPropertyType(propId);
if (isNumeric(propType)) {
CellRangeAddress cra = new CellRangeAddress(startRow, currentRow - 1, col, col);
if (isHierarchical()) {
// 9 & 109 are for sum. 9 means include hidden cells, 109 means exclude.
// this will show the wrong value if the user expands an outlined category, so
// we will range value it first
cell.setCellFormula("SUM(" + cra.formatAsString(hierarchicalTotalsSheet.getSheetName(),
true) + ")");
} else {
cell.setCellFormula("SUM(" + cra.formatAsString() + ")");
}
} else {
if (0 == col) {
cell.setCellValue(createHelper.createRichTextString("Total"));
}
}
}
示例3: addTitleToSheet
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
public int addTitleToSheet(ReportTitle reportTitle, Sheet sheet, int row, int firstCol, int lastCol) {
if (!reportTitle.isShowTitle()) {
return row;
}
Row titleRow = sheet.createRow(row);
Cell titleCell = titleRow.createCell(firstCol);
titleCell.setCellType(Cell.CELL_TYPE_STRING);
titleCell.setCellValue(reportTitle.getTitle());
CellStyle titleStyle = new TitleStyleBuilder().builder(reportTitle, sheet.getWorkbook());
titleCell.setCellStyle(titleStyle);
CellRangeAddress rangle = new CellRangeAddress(row, row, firstCol, lastCol);
sheet.addMergedRegion(rangle);
this.setCellRangeAddressBorder(rangle, sheet);
return row + 1;
}
示例4: createFirstRow
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
private static List<String> createFirstRow(String sheetName,
List<Locale> locales, Sheet sheet, CellStyle styleTitle) {
int colIdx = 0;
Row titleRow = sheet.createRow(0);
sheet.setColumnWidth(colIdx, 30 * 256);
Cell titleCell = titleRow.createCell(colIdx++);
titleCell.setCellStyle(styleTitle);
titleCell.setCellValue(getDefaultResourceBundle().getString(
BaseBean.LABEL_SHOP_TRANSLARIONS_KEY));
return createColumnHeaders(sheetName, locales, sheet, styleTitle,
colIdx, titleRow);
}
示例5: formatCellStatus
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
protected void formatCellStatus(Sheet sheet, Cell cell) {
cell.setCellStyle(styles.get("status"));
SheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting();
ConditionalFormattingRule ruleGreen = sheetCF.createConditionalFormattingRule(ComparisonOperator.EQUAL, "1");
PatternFormatting fill1 = ruleGreen.createPatternFormatting();
fill1.setFillBackgroundColor(IndexedColors.GREEN.index);
fill1.setFillPattern(PatternFormatting.SOLID_FOREGROUND);
//
ConditionalFormattingRule ruleRed = sheetCF.createConditionalFormattingRule(ComparisonOperator.EQUAL, "0");
PatternFormatting fill2 = ruleRed.createPatternFormatting();
fill2.setFillBackgroundColor(IndexedColors.RED.index);
fill2.setFillPattern(PatternFormatting.SOLID_FOREGROUND);
//
ConditionalFormattingRule ruleOrange = sheetCF.createConditionalFormattingRule(ComparisonOperator.EQUAL, "2");
PatternFormatting fill3 = ruleOrange.createPatternFormatting();
fill3.setFillBackgroundColor(IndexedColors.ORANGE.index);
fill3.setFillPattern(PatternFormatting.SOLID_FOREGROUND);
//
String name = CellReference.convertNumToColString(cell.getColumnIndex());
String location = "$" + name + "$" + cell.getRowIndex() + ":$" + name + "$" + (cell.getRowIndex() + 1);
CellRangeAddress[] regions = { CellRangeAddress.valueOf(location) };
ConditionalFormattingRule[] cfRules = new ConditionalFormattingRule[] { ruleGreen, ruleRed, ruleOrange };
sheetCF.addConditionalFormatting(regions, cfRules);
}
示例6: writeTitle
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
/**
* 向当前Sheet第一行(1-based)写入标题,若用户没有开启写入标题总开关(即{@link #isWriteTitle}为false),
* 或者{@link #titles}为空则不会做任何操作
*/
private void writeTitle() {
if (!this.isWriteTitle || this.titles == null || this.titles.isEmpty()) {
return;
}
this.currentRowInSheet++;
Row row = this.currentSheetPO.createRow(this.currentRowInSheet);
row.setHeight(this.rowHeight < 0 ? -1 : this.rowHeight);
for (int i = 0; i < this.titles.size(); i++) {
Cell cell = row.createCell(i);
cell.setCellStyle(this.defaultTitleCellStyle);
cell.setCellValue(this.titles.get(i));
}
this.realRowInSheet++;
this.realRowInExcel++;
}
示例7: addHeaderRow
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
/**
* Adds the header row. Override this method to change header-row-related
* aspects of the workbook. Alternately, the header Row Object is accessible
* via getHeaderRow() after report creation. To change header CellStyle,
* though, use setHeaderStyle().
*
* @param row the row
*/
protected void addHeaderRow(final int row) {
headerRow = sheet.createRow(row);
Cell headerCell;
headerRow.setHeightInPoints(40);
int col = 0;
for (final String propId : getPropIds()) {
headerCell = headerRow.createCell(col);
headerCell.setCellValue(createHelper.createRichTextString(getGridHolder().getColumnHeader(propId)));
headerCell.setCellStyle(getColumnHeaderStyle(row, col));
final HorizontalAlignment poiAlignment = getGridHolder().getCellAlignment(propId);
CellUtil.setAlignment(headerCell, poiAlignment);
col++;
}
}
示例8: createSheetDataRow
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
private static <T> void createSheetDataRow(List<T> dataList, int dataRowNum,
int listStart, int listEnd,ExportInfo exportInfo,
Map<Field, CellStyle> dataCellStyleMap, List<Field> availableFields,Sheet sheet)
throws IllegalAccessException, InvocationTargetException {
Map<Field, ExportFieldInfo> fieldInfoMap = exportInfo.getFieldInfoMap();
Cell cell;
Field field;
Row row;
T obj ;
int dataSize = dataList.size() ;
listEnd = listEnd > dataSize ? dataSize : listEnd ;
int fieldListSize = availableFields.size();
int dataHightInPoint = exportInfo.getDataHightInPoint();
for(int i = listStart ; i < listEnd ; i++ , dataRowNum ++){
obj = dataList.get(i);
row = sheet.createRow(dataRowNum );
row.setHeightInPoints(dataHightInPoint);
for(int j = 0 ; j < fieldListSize ; j++){
field = availableFields.get(j);
if(field == null ){
continue;
}
cell= row.createCell(j);
Object returnVal = obj;
List<Method> methods = fieldInfoMap.get(field).getMethodChain();
for(Method method : methods){
if (returnVal == null) {
continue;
}
returnVal = method.invoke(returnVal);
}
setCellValue(cell, fieldInfoMap.get(field), returnVal, obj);
if(dataCellStyleMap != null && dataCellStyleMap.get(field) != null){
cell.setCellStyle(dataCellStyleMap.get(field));
}
}
}
}
示例9: writeValue
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
/**
* @param column
* @param line
* @param value
* @param style
*/
private void writeValue(String column, int line, String value, CellStyle style) {
logger.debug("Writing: [{}] at line [{}] in column [{}]", value, line, column);
final int colIndex = columns.indexOf(column);
final Sheet sheet = workbook.getSheetAt(0);
final Row row = sheet.getRow(line);
Cell cell = row.getCell(colIndex);
if (cell != null) {
row.removeCell(cell);
}
cell = row.createCell(colIndex);
cell.setCellStyle(style);
cell.setCellValue(value);
saveOpenExcelFile();
}
示例10: writeComment
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
/**
* Adds the given information as a new row to the sheet.
* @param id: plant ID number
* @param comment: comment left by visitor
* @param timestamp: time the user left the comment
*/
public void writeComment(String id, String commonName, String cultivar, String gardenLocation, String comment, Date timestamp){
Row row = commentsSheet.createRow((short) commentCount);
Cell cell = row.createCell(0);
cell.setCellValue(id);
cell = row.createCell(1);
cell.setCellValue(commonName);
cell = row.createCell(2);
cell.setCellValue(cultivar);
cell = row.createCell(3);
cell.setCellValue(gardenLocation);
cell = row.createCell(4);
CellStyle style = workbook.createCellStyle();
style.setWrapText(true);
cell.setCellStyle(style);
cell.setCellValue(comment);
cell = row.createCell(5);
cell.setCellValue(timestamp.toString());
commentCount++;
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-4-dorfner-v2,代码行数:34,代码来源:CollectedDataWriter.java
示例11: createColumnHeaders
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
private static List<String> createColumnHeaders(String sheetName,
List<Locale> locales, Sheet sheet, CellStyle styleTitle,
int colIdx, Row titleRow) {
Cell titleCell;
List<String> localeList = new ArrayList<String>();
int localesSize = locales.size();
String cellValue = null;
for (int i = 0; i < localesSize; i++) {
sheet.setColumnWidth(colIdx, 40 * 256);
titleCell = titleRow.createCell(colIdx++);
titleCell.setCellStyle(styleTitle);
if (i < 3
&& !BaseBean.LABEL_SHOP_TRANSLARIONS.equals(sheetName)
&& StandardLanguage.isStandardLanguage(locales.get(i)
.getLanguage())) {
cellValue = locales.get(i).getLanguage()
+ StandardLanguage.COLUMN_HEADING_SUFFIX;
titleCell.setCellValue(cellValue);
localeList.add(cellValue);
} else {
cellValue = locales.get(i).getLanguage();
titleCell.setCellValue(cellValue);
localeList.add(cellValue);
}
}
if (locales.size() == 3
&& !BaseBean.LABEL_SHOP_TRANSLARIONS.equals(sheetName)) {
sheet.setColumnWidth(colIdx, 40 * 256);
titleCell = titleRow.createCell(colIdx++);
titleCell.setCellStyle(styleTitle);
titleCell.setCellValue(ADDLANGUAGE);
}
return localeList;
}
示例12: CreateCellM
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
public static void CreateCellM(Cell c, Row r, Sheet s, CellStyle cs, int colinaI, int colinaF, String valorS, int linhaI, int linhaF) {
c = r.createCell(linhaI);
c.setCellStyle(cs);
c.setCellValue(valorS);
s.addMergedRegion(new CellRangeAddress(colinaI, colinaF, linhaI, linhaF));
for (int e = (linhaI + 1); e <= linhaF; e++) {
c = r.createCell(e);
c.setCellStyle(cs);
}
}
示例13: createSummaryColumns
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
private void createSummaryColumns(Sheet sheet) {
Row headerRow = sheet.createRow(ROW_INDEX_COLUMNS_DESCRIPTIONS);
headerRow.setHeightInPoints(40);
Cell headerCell;
for (int i = 0; i < titlesSummary.length; i++) {
headerCell = headerRow.createCell(i);
headerCell.setCellValue(titlesSummary[i]);
headerCell.setCellStyle(styles.get("header"));
}
}
示例14: createTitle
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
private void createTitle(Sheet sheet, String xl_sheet_title) {
Row titleRow = sheet.createRow(ROW_INDEX_TITLE);
titleRow.setHeightInPoints(45);
Cell titleCell = titleRow.createCell(0);
titleCell.setCellValue(xl_sheet_title);
titleCell.setCellStyle(styles.get("title"));
sheet.addMergedRegion(CellRangeAddress.valueOf("$A$1:$F$1"));
}
示例15: CreateCell
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
public void CreateCell(Cell c, Row r, Sheet s, CellStyle cs, int colinaI, int colinaF, String valorS, int linhaI, int linhaF) {
c = r.createCell(linhaI);
c.setCellStyle(cs);
c.setCellValue(valorS);
s.addMergedRegion(new CellRangeAddress(colinaI, colinaF, linhaI, linhaF));
for (int e = (linhaI + 1); e <= linhaF; e++) {
c = r.createCell(e);
c.setCellStyle(cs);
}
}