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

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

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

CellStyle.setAlignment介绍

[英]set the type of horizontal alignment for the cell
[中]设置单元格的水平对齐类型

代码示例

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

/**
 * 设置cell文本对齐样式
 * 
 * @param cellStyle {@link CellStyle}
 * @param halign 横向位置
 * @param valign 纵向位置
 * @return {@link CellStyle}
 */
public static CellStyle setAlign(CellStyle cellStyle, HorizontalAlignment halign, VerticalAlignment valign) {
  cellStyle.setAlignment(halign);
  cellStyle.setVerticalAlignment(valign);
  return cellStyle;
}

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

/**
 * 设置cell文本对齐样式
 * 
 * @param cellStyle {@link CellStyle}
 * @param halign 横向位置
 * @param valign 纵向位置
 * @return {@link CellStyle}
 */
public static CellStyle setAlign(CellStyle cellStyle, HorizontalAlignment halign, VerticalAlignment valign) {
  cellStyle.setAlignment(halign);
  cellStyle.setVerticalAlignment(valign);
  return cellStyle;
}

代码示例来源:origin: primefaces/primefaces

protected void applyOptions(Workbook wb, DataTable table, Sheet sheet, ExporterOptions options) {
  facetStyle = wb.createCellStyle();
  facetStyle.setAlignment(HorizontalAlignment.CENTER);
  facetStyle.setVerticalAlignment(VerticalAlignment.CENTER);
  facetStyle.setWrapText(true);
  applyFacetOptions(wb, options, facetStyle);
  cellStyle = wb.createCellStyle();
  cellStyle.setAlignment(HorizontalAlignment.LEFT);
  applyCellOptions(wb, options, cellStyle);
  PrintSetup printSetup = sheet.getPrintSetup();
  printSetup.setLandscape(true);
  printSetup.setPaperSize(PrintSetup.A4_PAPERSIZE);
  sheet.setPrintGridlines(true);
}

代码示例来源:origin: stackoverflow.com

Workbook wb = new XSSFWorkbook("myWorkbook.xlsx");
 Row row=sheet.getRow(0);
 CellStyle style=null;
 XSSFFont defaultFont= wb.createFont();
 defaultFont.setFontHeightInPoints((short)10);
 defaultFont.setFontName("Arial");
 defaultFont.setColor(IndexedColors.BLACK.getIndex());
 defaultFont.setBold(false);
 defaultFont.setItalic(false);
 XSSFFont font= wb.createFont();
 font.setFontHeightInPoints((short)10);
 font.setFontName("Arial");
 font.setColor(IndexedColors.WHITE.getIndex());
 font.setBold(true);
 font.setItalic(false);
 style=row.getRowStyle();
 style.setFillBackgroundColor(IndexedColors.DARK_BLUE.getIndex());
 style.setFillPattern(CellStyle.SOLID_FOREGROUND);
 style.setAlignment(CellStyle.ALIGN_CENTER);
 style.setFont(font);

代码示例来源:origin: alibaba/easyexcel

/**
 *
 * @param workbook
 * @return
 */
public static CellStyle buildDefaultCellStyle(Workbook workbook) {
  CellStyle newCellStyle = workbook.createCellStyle();
  Font font = workbook.createFont();
  font.setFontName("宋体");
  font.setFontHeightInPoints((short)14);
  font.setBold(true);
  newCellStyle.setFont(font);
  newCellStyle.setWrapText(true);
  newCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
  newCellStyle.setAlignment(HorizontalAlignment.CENTER);
  newCellStyle.setLocked(true);
  newCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
  newCellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
  newCellStyle.setBorderBottom(BorderStyle.THIN);
  newCellStyle.setBorderLeft(BorderStyle.THIN);
  return newCellStyle;
}

代码示例来源:origin: wuyouzhuguli/FEBS-Shiro

@Override
public CellStyle headCellStyle(SXSSFWorkbook wb) {
  CellStyle cellStyle = wb.createCellStyle();
  Font font = wb.createFont();
  cellStyle.setFillForegroundColor((short) 12);
  cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);// 填充模式
  cellStyle.setBorderTop(CellStyle.BORDER_THIN);// 上边框为细边框
  cellStyle.setBorderRight(CellStyle.BORDER_THIN);// 右边框为细边框
  cellStyle.setBorderBottom(CellStyle.BORDER_THIN);// 下边框为细边框
  cellStyle.setBorderLeft(CellStyle.BORDER_THIN);// 左边框为细边框
  cellStyle.setAlignment(CellStyle.ALIGN_LEFT);// 对齐
  cellStyle.setFillForegroundColor(HSSFColor.GREEN.index);
  cellStyle.setFillBackgroundColor(HSSFColor.GREEN.index);
  font.setBoldweight(Font.BOLDWEIGHT_NORMAL);
  // font.setFontHeightInPoints((short) 12);// 字体大小
  font.setColor(HSSFColor.WHITE.index);
  // 应用标题字体到标题样式
  cellStyle.setFont(font);
  return cellStyle;
}

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

/**
 * Sets the format properties of the given style based on the given map.
 *
 * @param style cell style
 * @param workbook parent workbook
 * @param properties map of format properties (String -> Object)
 * @see #getFormatProperties(CellStyle)
 */
private static void setFormatProperties(CellStyle style, Workbook workbook, Map<String, Object> properties) {
  style.setAlignment(getHorizontalAlignment(properties, ALIGNMENT));
  style.setVerticalAlignment(getVerticalAlignment(properties, VERTICAL_ALIGNMENT));
  style.setBorderBottom(getBorderStyle(properties, BORDER_BOTTOM));
  style.setBorderLeft(getBorderStyle(properties, BORDER_LEFT));
  style.setBorderRight(getBorderStyle(properties, BORDER_RIGHT));
  style.setBorderTop(getBorderStyle(properties, BORDER_TOP));
  style.setBottomBorderColor(getShort(properties, BOTTOM_BORDER_COLOR));
  style.setDataFormat(getShort(properties, DATA_FORMAT));
  style.setFillPattern(getFillPattern(properties, FILL_PATTERN));
  style.setFillForegroundColor(getShort(properties, FILL_FOREGROUND_COLOR));
  style.setFillBackgroundColor(getShort(properties, FILL_BACKGROUND_COLOR));
  style.setFont(workbook.getFontAt(getInt(properties, FONT)));
  style.setHidden(getBoolean(properties, HIDDEN));
  style.setIndention(getShort(properties, INDENTION));
  style.setLeftBorderColor(getShort(properties, LEFT_BORDER_COLOR));
  style.setLocked(getBoolean(properties, LOCKED));
  style.setRightBorderColor(getShort(properties, RIGHT_BORDER_COLOR));
  style.setRotation(getShort(properties, ROTATION));
  style.setTopBorderColor(getShort(properties, TOP_BORDER_COLOR));
  style.setWrapText(getBoolean(properties, WRAP_TEXT));
}

代码示例来源:origin: stackoverflow.com

private static Map<String, CellStyle> styles;

private static Map<String, CellStyle> createStyles(Workbook wb){
    Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
    DataFormat df = wb.createDataFormat();

    CellStyle style;
    Font headerFont = wb.createFont();
    headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    headerFont.setFontHeightInPoints((short) 12);
    style = createBorderedStyle(wb);
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setFont(headerFont);
    styles.put("style1", style);

    style = createBorderedStyle(wb);
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setFont(headerFont);
    style.setDataFormat(df.getFormat("d-mmm"));
    styles.put("date_style", style);
    ...
    return styles;
  }

代码示例来源:origin: stackoverflow.com

XSSFWorkbook wb = new XSSFWorkbook();
CellStyle borderStyle = wb.createCellStyle();
borderStyle.setBorderBottom(CellStyle.BORDER_THIN);
borderStyle.setBorderLeft(CellStyle.BORDER_THIN);
borderStyle.setBorderRight(CellStyle.BORDER_THIN);
borderStyle.setBorderTop(CellStyle.BORDER_THIN);
borderStyle.setAlignment(CellStyle.ALIGN_CENTER);
Sheet sheet = wb.createSheet("Test Sheet");
Row row = sheet.createRow(1);
for (int i = 1; i <= 5; ++i) {
  Cell cell = row.createCell(i);
  cell.setCellStyle(borderStyle);
  if (i == 1) {
    cell.setCellValue("Centred Text");
  } 
}
sheet.addMergedRegion(new CellRangeAddress(1, 1, 1, 5));

代码示例来源:origin: stackoverflow.com

CellStyle cellStyle = workSheet.getWorkbook().createCellStyle();
cellStyle.setAlignment(CellStyle.ALIGN_CENTER);
cellStyle.setWrapText(true);

for (int i=0; i <= records.size(); i++) {
// Create a new row
Row row = workSheet.createRow((short) i);
Cell cell001 = row.createCell(columnIndex);
cell001.setCellValue("some value");
cell001.setCellStyle(cellStyle);
}

代码示例来源:origin: stackoverflow.com

CellStyle rightAligned = workbook.createCellStyle();
rightAligned.setAlignment(CellStyle.ALIGN_RIGHT);

Cell richTextCell = row.createCell(0);
RichTextString richTextString = creationHelper.createRichTextString("So rich!");
richTextCell.setCellValue(richTextString);
richTextCell.setCellStyle(rightAligned);

Cell numberCell = row.createCell(1);
numberCell.setCellValue(12.34);
numberCell.setCellStyle(rightAligned);

代码示例来源:origin: org.spdx/spdx-tools

public static CellStyle createCenterStyle(Workbook wb) {
  CellStyle centerStyle = wb.createCellStyle();
  centerStyle.setWrapText(false);
  centerStyle.setAlignment(HorizontalAlignment.CENTER);
  return centerStyle;
}

代码示例来源:origin: org.jeecg/easypoi-base

@Override
public CellStyle stringSeptailStyle(Workbook workbook, boolean isWarp) {
  CellStyle style = workbook.createCellStyle();
  style.setAlignment(CellStyle.ALIGN_CENTER);
  style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
  style.setDataFormat(STRING_FORMAT);
  if (isWarp) {
    style.setWrapText(true);
  }
  return style;
}

代码示例来源:origin: zhangdaiscott/jeasypoi

@Override
public CellStyle stringSeptailStyle(Workbook workbook, boolean isWarp) {
  CellStyle style = workbook.createCellStyle();
  style.setAlignment(CellStyle.ALIGN_CENTER);
  style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
  style.setDataFormat(STRING_FORMAT);
  if (isWarp) {
    style.setWrapText(true);
  }
  return style;
}

代码示例来源:origin: cn.afterturn/easypoi-base

@Override
public CellStyle stringNoneStyle(Workbook workbook, boolean isWarp) {
  CellStyle style = workbook.createCellStyle();
  style.setAlignment(HorizontalAlignment.CENTER);
  style.setVerticalAlignment(VerticalAlignment.CENTER);
  style.setDataFormat(STRING_FORMAT);
  if (isWarp) {
    style.setWrapText(true);
  }
  return style;
}

代码示例来源:origin: xiaolanglang/easypoi

@Override
public CellStyle getHeaderStyle(short color) {
  CellStyle titleStyle = workbook.createCellStyle();
  Font font = workbook.createFont();
  font.setFontHeightInPoints((short) 12);
  titleStyle.setFont(font);
  titleStyle.setAlignment(CellStyle.ALIGN_CENTER);
  titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
  return titleStyle;
}

代码示例来源:origin: cn.afterturn/easypoi-base

@Override
public CellStyle getHeaderStyle(short headerColor) {
  CellStyle titleStyle = workbook.createCellStyle();
  Font font = workbook.createFont();
  font.setFontHeightInPoints((short) 24);
  titleStyle.setFont(font);
  titleStyle.setFillForegroundColor(headerColor);
  titleStyle.setAlignment(HorizontalAlignment.CENTER);
  titleStyle.setVerticalAlignment(VerticalAlignment.CENTER);
  return titleStyle;
}

代码示例来源:origin: zhangdaiscott/jeasypoi

@Override
public CellStyle getHeaderStyle(short headerColor) {
  CellStyle titleStyle = workbook.createCellStyle();
  Font font = workbook.createFont();
  font.setFontHeightInPoints((short) 24);
  titleStyle.setFont(font);
  titleStyle.setFillForegroundColor(headerColor);
  titleStyle.setAlignment(CellStyle.ALIGN_CENTER);
  titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
  return titleStyle;
}

代码示例来源:origin: org.jeecg/easypoi-base

@Override
public CellStyle getTitleStyle(short color) {
  CellStyle titleStyle = workbook.createCellStyle();
  titleStyle.setBorderLeft((short) 1); // 左边框
  titleStyle.setBorderRight((short) 1); // 右边框
  titleStyle.setBorderBottom((short) 1);
  titleStyle.setBorderTop((short) 1);
  titleStyle.setAlignment(CellStyle.ALIGN_CENTER);
  titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
  titleStyle.setWrapText(true);
  return titleStyle;
}

代码示例来源:origin: cn.afterturn/easypoi-base

@Override
public CellStyle getTitleStyle(short color) {
  CellStyle titleStyle = workbook.createCellStyle();
  titleStyle.setBorderLeft(BorderStyle.THIN);
  titleStyle.setBorderRight(BorderStyle.THIN);
  titleStyle.setBorderBottom(BorderStyle.THIN);
  titleStyle.setBorderTop(BorderStyle.THIN);
  titleStyle.setAlignment(HorizontalAlignment.CENTER);
  titleStyle.setVerticalAlignment(VerticalAlignment.CENTER);
  titleStyle.setWrapText(true);
  return titleStyle;
}

相关文章

微信公众号

最新文章

更多