本文整理汇总了Java中org.apache.poi.hssf.usermodel.HSSFCellStyle.setAlignment方法的典型用法代码示例。如果您正苦于以下问题:Java HSSFCellStyle.setAlignment方法的具体用法?Java HSSFCellStyle.setAlignment怎么用?Java HSSFCellStyle.setAlignment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.hssf.usermodel.HSSFCellStyle
的用法示例。
在下文中一共展示了HSSFCellStyle.setAlignment方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCellStyle
import org.apache.poi.hssf.usermodel.HSSFCellStyle; //导入方法依赖的package包/类
/**
* 获取单元格式样式
*
* @param wb
* @param color
* @return
*/
private static HSSFCellStyle getCellStyle(HSSFWorkbook wb, int color) {
if (STYLE_MAP.get(color) != null) {
return STYLE_MAP.get(color);
}
HSSFCellStyle style = wb.createCellStyle();
if (color != -1) {
style.setFillForegroundColor(Short.valueOf(color + ""));
style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
style.setAlignment(CellStyle.ALIGN_CENTER);
}
style.setBorderBottom(CellStyle.BORDER_THIN);
style.setBorderLeft(CellStyle.BORDER_THIN);
style.setBorderRight(CellStyle.BORDER_THIN);
style.setBorderTop(CellStyle.BORDER_THIN);
style.setBottomBorderColor(HSSFColor.BLACK.index);
style.setLeftBorderColor(HSSFColor.BLACK.index);
style.setRightBorderColor(HSSFColor.BLACK.index);
style.setTopBorderColor(HSSFColor.BLACK.index);
STYLE_MAP.put(color, style);
return style;
}
示例2: createHSSFCellStyle
import org.apache.poi.hssf.usermodel.HSSFCellStyle; //导入方法依赖的package包/类
private HSSFCellStyle createHSSFCellStyle(Workbook wb, int[] bgColor, int[] fontColor, int fontSize) {
HSSFWorkbook workbook = (HSSFWorkbook) wb;
HSSFPalette palette = workbook.getCustomPalette();
palette.setColorAtIndex((short) 9, (byte) fontColor[0], (byte) fontColor[1], (byte) fontColor[2]);
palette.setColorAtIndex((short) 10, (byte) bgColor[0], (byte) bgColor[1], (byte) bgColor[2]);
HSSFFont titleFont = workbook.createFont();
titleFont.setCharSet(HSSFFont.DEFAULT_CHARSET);
titleFont.setFontName("宋体");
titleFont.setColor((short) 9);
titleFont.setBold(true);
titleFont.setFontHeightInPoints((short) fontSize);
HSSFCellStyle titleStyle = (HSSFCellStyle) createBorderCellStyle(workbook, true);
titleStyle.setFont(titleFont);
titleStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
titleStyle.setFillForegroundColor((short) 10);
titleStyle.setAlignment(HorizontalAlignment.CENTER);
titleStyle.setVerticalAlignment(VerticalAlignment.CENTER);
return titleStyle;
}
示例3: createColumnHeaders
import org.apache.poi.hssf.usermodel.HSSFCellStyle; //导入方法依赖的package包/类
/**
*/
protected void createColumnHeaders() {
final HSSFRow headersRow = this.sheet.createRow(0);
final HSSFFont font = this.workbook.createFont();
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
final HSSFCellStyle style = this.workbook.createCellStyle();
style.setFont(font);
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
int counter = 1;
for (int i = 0; i < this.model.getColumnCount(); i++) {
final HSSFCell cell = headersRow.createCell(counter++);
// cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(this.model.getColumnName(i));
cell.setCellStyle(style);
}
}
示例4: createRow
import org.apache.poi.hssf.usermodel.HSSFCellStyle; //导入方法依赖的package包/类
/**
*
* @param rowIndex
* int
*/
protected void createRow(final int rowIndex) {
final HSSFRow row = this.sheet.createRow(rowIndex + 1); // since the
// rows in
// excel starts from 1
// not 0
final HSSFCellStyle style = this.workbook.createCellStyle();
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
int counter = 1;
for (int i = 0; i < this.model.getColumnCount(); i++) {
final HSSFCell cell = row.createCell(counter++);
// cell.setEncoding(HSSFCell.ENCODING_UTF_16);
final Object value = this.model.getValueAt(rowIndex, i);
setValue(cell, value);
cell.setCellStyle(style);
}
}
示例5: createHeader
import org.apache.poi.hssf.usermodel.HSSFCellStyle; //导入方法依赖的package包/类
public static boolean createHeader(HSSFWorkbook workbook, HSSFSheet sheet,String[] header) throws Exception{
boolean flag = false;
try {
HSSFCellStyle cellStyle = workbook.createCellStyle();
cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
HSSFRow head_row = sheet.createRow(0); // 创建行
// 操作head
for (short h = 0; h < header.length; h++) {
createcsv(head_row, h, header[h], cellStyle);
}
flag = true;
} catch (Exception e) {
logger.error(sheet.getSheetName() + " : 抬头标题创建失败");
throw e;
}
return flag;
}
示例6: writeCondtions
import org.apache.poi.hssf.usermodel.HSSFCellStyle; //导入方法依赖的package包/类
/**
* 表头条件
* @param sheet
* @param t
* @param cellCount
* @return
*/
void writeCondtions(HSSFSheet sheet){
T t = getConditions();
if (t!=null) {
HSSFRow row = sheet.createRow(getRowNumber());
row.setHeight((short) 500);
CellRangeAddress cra = new CellRangeAddress(getRowNumber(), getRowNumber(), 0, getColumnJson().size());
sheet.addMergedRegion(cra);
HSSFCell cell = row.createCell(0);
HSSFCellStyle style = cell.getCellStyle();
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setWrapText(true);
cell.setCellStyle(style);
setCellValue(cell, formatCondition(t));
addRowNumber();
}
}
示例7: createCellStyleForColumnHeading
import org.apache.poi.hssf.usermodel.HSSFCellStyle; //导入方法依赖的package包/类
public static HSSFCellStyle createCellStyleForColumnHeading(HSSFWorkbook workBook) {
HSSFCellStyle cellStyle = workBook.createCellStyle();
HSSFFont fontObj = workBook.createFont();
cellStyle.setBorderBottom(BorderStyle.THIN);
cellStyle.setBorderTop(BorderStyle.THIN);
cellStyle.setBorderLeft(BorderStyle.THIN);
cellStyle.setBorderRight(BorderStyle.THIN);
cellStyle.setWrapText(true);
cellStyle.setAlignment(HorizontalAlignment.CENTER);
cellStyle.setFillBackgroundColor(Short.valueOf("22").shortValue());
cellStyle.setFillPattern(FillPatternType.BIG_SPOTS);
cellStyle.setFillForegroundColor(Short.valueOf("22").shortValue());
cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
fontObj.setFontName("Calibri");
fontObj.setFontHeightInPoints(Short.valueOf("12").shortValue());
fontObj.setBold(true);
fontObj.setColor(Short.valueOf("8").shortValue());
cellStyle.setFont(fontObj);
return cellStyle;
}
示例8: createSecondTitleStyle
import org.apache.poi.hssf.usermodel.HSSFCellStyle; //导入方法依赖的package包/类
private HSSFCellStyle createSecondTitleStyle(HSSFWorkbook wb){
HSSFCellStyle style = wb.createCellStyle();
style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
style.setBorderBottom(HSSFCellStyle.BORDER_NONE);
style.setBorderLeft(HSSFCellStyle.BORDER_NONE);
style.setBorderRight(HSSFCellStyle.BORDER_NONE);
style.setBorderTop(HSSFCellStyle.BORDER_NONE);
style.setWrapText(true);
HSSFFont font = wb.createFont();
//font.setFontHeightInPoints((short)20);
font.setFontName("����");
style.setFont(font);
return style;
}
示例9: generateContStyle
import org.apache.poi.hssf.usermodel.HSSFCellStyle; //导入方法依赖的package包/类
/**
* @Description: 生成excel表格 单元格内容的样式
* @param workbook
* @return
*
* @History
* 1. 2014-12-19 linwb 创建方法
*/
private HSSFCellStyle generateContStyle(HSSFWorkbook workbook) {
HSSFCellStyle cellStyle = workbook.createCellStyle();
cellStyle.setFillForegroundColor(contCellBackgroundColor);
cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
cellStyle.setBorderBottom(contBorderBottom);
cellStyle.setBorderLeft(contBorderLeft);
cellStyle.setBorderRight(contBorderRight);
cellStyle.setBorderTop(contBorderTop);
cellStyle.setAlignment(contCellTextAlign);
cellStyle.setVerticalAlignment(contCellVehicleAlign);
// 生成字体
HSSFFont font = workbook.createFont();
font.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
// 把字体应用到当前的样式
cellStyle.setFont(font);
return cellStyle;
}
示例10: estiloCabecalho
import org.apache.poi.hssf.usermodel.HSSFCellStyle; //导入方法依赖的package包/类
/**
* Estilo de cabecalho.
* @param wb
* @return retorna o estilo da celula.
* @author Ekler Paulino de Mattos.
*/
private HSSFCellStyle estiloCabecalho(HSSFWorkbook wb){
HSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THICK);
cellStyle.setBorderRight(HSSFCellStyle.BORDER_THICK);
cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THICK);
cellStyle.setBorderTop(HSSFCellStyle.BORDER_THICK);
cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND );
// cellStyle.setFillForegroundColor(HSSFColor.GREY_40_PERCENT.index);
cellStyle.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index);
cellStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
HSSFFont font = cellStyle.getFont(wb);
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
font.setColor(HSSFFont.COLOR_NORMAL);
font.setFontName(HSSFFont.FONT_ARIAL);
cellStyle.setFont(font);
return cellStyle;
}
示例11: estiloDadosConsultado
import org.apache.poi.hssf.usermodel.HSSFCellStyle; //导入方法依赖的package包/类
/**
* Estilo dos campos dos dados.
* @param wb
* @return retorna o estilo da celula.
* @author Ekler Paulino de Mattos.
*/
private HSSFCellStyle estiloDadosConsultado(HSSFWorkbook wb){
HSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
cellStyle.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
cellStyle.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);
cellStyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
// plano de fundo - para que funcione deve se
// definido antes um padrao de preenchimento.
cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND );
//cellStyle.setFillForegroundColor(HSSFColor.AQUA.index);
cellStyle.setFillForegroundColor(HSSFColor.WHITE.index);
cellStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
HSSFFont font = cellStyle.getFont(wb);
font.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
font.setColor(HSSFFont.COLOR_NORMAL);
font.setFontName(HSSFFont.FONT_ARIAL);
cellStyle.setFont(font);
return cellStyle;
}
示例12: estiloDadosRetorno
import org.apache.poi.hssf.usermodel.HSSFCellStyle; //导入方法依赖的package包/类
/**
* Estilo dos campos dos dados.
* @param wb
* @return retorna o estilo da celula.
* @author Ekler Paulino de Mattos.
*/
private HSSFCellStyle estiloDadosRetorno(HSSFWorkbook wb){
HSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
cellStyle.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
cellStyle.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);
cellStyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
// plano de fundo - para que funcione deve se
// definido antes um padrao de preenchimento.
cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND );
//cellStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
cellStyle.setFillForegroundColor(HSSFColor.PALE_BLUE.index);
cellStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
HSSFFont font = cellStyle.getFont(wb);
font.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
font.setColor(HSSFFont.COLOR_NORMAL);
font.setFontName(HSSFFont.FONT_ARIAL);
cellStyle.setFont(font);
return cellStyle;
}
示例13: writeCaption
import org.apache.poi.hssf.usermodel.HSSFCellStyle; //导入方法依赖的package包/类
/**
* @see org.displaytag.render.TableWriterTemplate#writeCaption(org.displaytag.model.TableModel)
*/
@Override
protected void writeCaption(TableModel model) throws Exception
{
HSSFCellStyle style = this.wb.createCellStyle();
HSSFFont bold = this.wb.createFont();
bold.setBoldweight(Font.BOLDWEIGHT_BOLD);
bold.setFontHeightInPoints((short) 14);
style.setFont(bold);
style.setAlignment(CellStyle.ALIGN_CENTER);
this.colNum = 0;
this.currentRow = this.sheet.createRow(this.sheetRowNum++);
this.currentCell = this.currentRow.createCell(this.colNum);
this.currentCell.setCellStyle(style);
String caption = model.getCaption();
this.currentCell.setCellValue(new HSSFRichTextString(caption));
this.rowSpanTable(model);
}
示例14: exportXLSLine
import org.apache.poi.hssf.usermodel.HSSFCellStyle; //导入方法依赖的package包/类
@Override
protected void exportXLSLine(final HSSFSheet sheet, final HSSFCellStyle cellStyle, final List<Object> cells,
final int offset) {
final HSSFRow row = sheet.createRow(sheet.getLastRowNum() + offset);
cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
int count = 0;
for (final Object cellValue : cells) {
if (++count == 3) {
cellStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
} else {
cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
}
addColumn(cellStyle, row, cellValue);
}
}
示例15: setHeaderStyle
import org.apache.poi.hssf.usermodel.HSSFCellStyle; //导入方法依赖的package包/类
private void setHeaderStyle(HSSFWorkbook wb) {
HSSFCellStyle style = wb.createCellStyle();
HSSFFont font = wb.createFont();
font.setColor(HSSFColor.BLACK.index);
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
font.setFontHeightInPoints((short) 8);
style.setFont(font);
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
style.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
style.setBorderRight(HSSFCellStyle.BORDER_THIN);
style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
style.setBorderTop(HSSFCellStyle.BORDER_THIN);
style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
style.setWrapText(true);
headerStyle = style;
}