本文整理汇总了Java中org.apache.poi.ss.usermodel.CellStyle类的典型用法代码示例。如果您正苦于以下问题:Java CellStyle类的具体用法?Java CellStyle怎么用?Java CellStyle使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CellStyle类属于org.apache.poi.ss.usermodel包,在下文中一共展示了CellStyle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createIndentationCellStyle
import org.apache.poi.ss.usermodel.CellStyle; //导入依赖的package包/类
public CellStyle createIndentationCellStyle(Workbook workbook, int s) {
CellStyle dataStyle1 = this.createBorderCellStyle(workbook, true);
Font dataFont = workbook.createFont();
dataFont.setColor((short) 12);
dataFont.setFontHeightInPoints((short) 10);
dataStyle1.setFillPattern(FillPatternType.SOLID_FOREGROUND);
dataStyle1.setFillForegroundColor((short) 11);
dataStyle1.setFont(dataFont);
dataStyle1.setVerticalAlignment(VerticalAlignment.CENTER);
dataStyle1.setAlignment(HorizontalAlignment.LEFT);
dataStyle1.setIndention(Short.valueOf(String.valueOf((s))));
return dataStyle1;
}
示例2: defaultDataCellStyle
import org.apache.poi.ss.usermodel.CellStyle; //导入依赖的package包/类
/**
* Returns the default data cell style. Obtained from:
* http://svn.apache.org/repos/asf/poi
* /trunk/src/examples/src/org/apache/poi/ss/examples/TimesheetDemo.java
*
* @param wb the wb
* @return the cell style
*/
protected CellStyle defaultDataCellStyle(final Workbook wb) {
CellStyle style;
style = wb.createCellStyle();
style.setAlignment(HorizontalAlignment.CENTER);
style.setWrapText(true);
style.setBorderRight(BorderStyle.THIN);
style.setRightBorderColor(IndexedColors.BLACK.getIndex());
style.setBorderLeft(BorderStyle.THIN);
style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
style.setBorderTop(BorderStyle.THIN);
style.setTopBorderColor(IndexedColors.BLACK.getIndex());
style.setBorderBottom(BorderStyle.THIN);
style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
style.setDataFormat(doubleDataFormat);
return style;
}
示例3: makeHeader
import org.apache.poi.ss.usermodel.CellStyle; //导入依赖的package包/类
private void makeHeader ( final List<Field> columns, final HSSFSheet sheet )
{
final Font font = sheet.getWorkbook ().createFont ();
font.setFontName ( "Arial" );
font.setBoldweight ( Font.BOLDWEIGHT_BOLD );
font.setColor ( HSSFColor.WHITE.index );
final CellStyle style = sheet.getWorkbook ().createCellStyle ();
style.setFont ( font );
style.setFillForegroundColor ( HSSFColor.BLACK.index );
style.setFillPattern ( PatternFormatting.SOLID_FOREGROUND );
final HSSFRow row = sheet.createRow ( 0 );
for ( int i = 0; i < columns.size (); i++ )
{
final Field field = columns.get ( i );
final HSSFCell cell = row.createCell ( i );
cell.setCellValue ( field.getHeader () );
cell.setCellStyle ( style );
}
}
示例4: defaultHeaderCellStyle
import org.apache.poi.ss.usermodel.CellStyle; //导入依赖的package包/类
/**
* Returns the default header style. Obtained from:
* http://svn.apache.org/repos/asf/poi
* /trunk/src/examples/src/org/apache/poi/ss/examples/TimesheetDemo.java
*
* @param wb the wb
* @return the cell style
*/
protected CellStyle defaultHeaderCellStyle(final Workbook wb) {
CellStyle style;
final Font monthFont = wb.createFont();
monthFont.setFontHeightInPoints((short) 11);
monthFont.setColor(IndexedColors.WHITE.getIndex());
style = wb.createCellStyle();
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
style.setFont(monthFont);
style.setWrapText(true);
return style;
}
示例5: doCreateCellStyle
import org.apache.poi.ss.usermodel.CellStyle; //导入依赖的package包/类
/** 创建每个CellStyle,并放到map之中
* @param workbook
* @param styleInfo
* @param dataFormat
* @return
*/
public static CellStyle doCreateCellStyle(Workbook workbook,ExportCellStyleInfo styleInfo,String dataFormat) {
if(styleInfo != null ){
CellStyle cellStyle = workbook.createCellStyle();
setStyleValue(ExportCellStyleInfo.class, cellStyle, styleInfo);
if(styleInfo.getFontStyleInfo() != null){
Font fontStyle = workbook.createFont();
setStyleValue(ExportFontStyleInfo.class, fontStyle, styleInfo.getFontStyleInfo());
cellStyle.setFont(fontStyle);
}
if(!StringUtils.isEmpty(dataFormat)){
short format = workbook.createDataFormat().getFormat(dataFormat);
cellStyle.setDataFormat(format);
}
return cellStyle;
}
return null;
}
示例6: getCellStyle
import org.apache.poi.ss.usermodel.CellStyle; //导入依赖的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;
}
示例7: defaultTitleCellStyle
import org.apache.poi.ss.usermodel.CellStyle; //导入依赖的package包/类
/**
* Returns the default title style. Obtained from:
* http://svn.apache.org/repos/asf/poi
* /trunk/src/examples/src/org/apache/poi/ss/examples/TimesheetDemo.java
*
* @param wb the wb
* @return the cell style
*/
protected CellStyle defaultTitleCellStyle(final Workbook wb) {
CellStyle style;
final Font titleFont = wb.createFont();
titleFont.setFontHeightInPoints((short) 18);
titleFont.setBold(true);
style = wb.createCellStyle();
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setFont(titleFont);
return style;
}
示例8: setCellStyleFont
import org.apache.poi.ss.usermodel.CellStyle; //导入依赖的package包/类
public void setCellStyleFont(Workbook workbook, CellStyle style, int i) {
Font font = workbook.createFont();
if (i == 0) {
// 正常
} else if (i == 4) {
// 下划线
font.setUnderline(Font.U_SINGLE);
style.setFont(font);
} else if (i == 2) {
// 倾斜
font.setItalic(true);
style.setFont(font);
} else if (i == 1) {
// 加粗
font.setBold(true);
style.setFont(font);
}
}
示例9: doCreateSheetSingleHeadRow
import org.apache.poi.ss.usermodel.CellStyle; //导入依赖的package包/类
/** 创建不需要合并单元格的表头
* @param fieldInfoMap
* @param headCellStyleMap
* @param row
* @param fieldList
* @param cellNum
*/
private static void doCreateSheetSingleHeadRow(Map<Field, ExportFieldInfo> fieldInfoMap,
Map<Field, CellStyle> headCellStyleMap, Row row, List<SortableField> fieldList, int cellNum) {
Cell cell;
String value;
for(int i = 0 ; i < fieldList.size() ; i++ , cellNum++){
Field field = fieldList.get(i).getField();
value = fieldInfoMap.get(field).getHeadName();
cell = row.createCell(cellNum);
cell.setCellValue(value);
if( headCellStyleMap != null && headCellStyleMap.get(field) != null ){
cell.setCellStyle(headCellStyleMap.get(field));
}
}
}
示例10: setRegionBorder
import org.apache.poi.ss.usermodel.CellStyle; //导入依赖的package包/类
/**
* 获取合并单元格式
*
* @param sheet
* @param row
* @param columnFrom
* @param columnTo
* @return
*/
private static void setRegionBorder(HSSFSheet sheet, int row, int columnFrom, int columnTo) {
CellRangeAddress region = new CellRangeAddress(row, row, columnFrom, columnTo);
sheet.addMergedRegion(region);
final short border = CellStyle.BORDER_THIN;
HSSFWorkbook wb = sheet.getWorkbook();
RegionUtil.setBorderBottom(border, region, sheet, wb);
RegionUtil.setBorderTop(border, region, sheet, wb);
RegionUtil.setBorderLeft(border, region, sheet, wb);
RegionUtil.setBorderRight(border, region, sheet, wb);
RegionUtil.setBottomBorderColor(HSSFColor.BLACK.index, region, sheet, wb);
RegionUtil.setTopBorderColor(HSSFColor.BLACK.index, region, sheet, wb);
RegionUtil.setLeftBorderColor(HSSFColor.BLACK.index, region, sheet, wb);
RegionUtil.setRightBorderColor(HSSFColor.BLACK.index, region, sheet, wb);
}
示例11: formatCellDate
import org.apache.poi.ss.usermodel.CellStyle; //导入依赖的package包/类
private void formatCellDate(Sheet sheet, Cell cell, String format) {
CellStyle style = wb.createCellStyle();
CreationHelper createHelper = wb.getCreationHelper();
style.setDataFormat(createHelper.createDataFormat().getFormat(format));
cell.setCellStyle(style);
}
示例12: mergeRows
import org.apache.poi.ss.usermodel.CellStyle; //导入依赖的package包/类
/**
* 合并行
*/
//TODO 暂时支持两行表头
private void mergeRows(Sheet sheet, CellStyle cellStyle, ExcelMeta excelMeta) {
Row row = null;
Cell cell = null;
String[] lastRowVals = new String[excelMeta.getTitleColumnNum()];
for (int r = 0; r < excelMeta.getTitleRowNum(); r++) {
for (int c = 0; c < excelMeta.getTitleColumnNum(); c++) {
row = sheet.getRow(r);
cell = row.getCell(c);
if (r == 0) {
lastRowVals[c] = cell.getStringCellValue();
} else {
if (StringUtils.equals(lastRowVals[c], cell.getStringCellValue())) {
cell.setCellValue("");
sheet.addMergedRegion(new CellRangeAddress(0, r, c, c));
Cell nowCell = sheet.getRow(0).getCell(c);
nowCell.setCellStyle(cellStyle);
}
}
}
}
}
示例13: getCellStyle
import org.apache.poi.ss.usermodel.CellStyle; //导入依赖的package包/类
/**
* 获取模板指定位置上的已转为本工作薄的单元格样式
*
* 目前看,只用于2003的版本(*.xls),2007的版本是可以直接 setCellStyle() 方法设置字体的。
*
* @author ZhengWei(HY)
* @createDate 2017-03-18
* @version v1.0
*
* @param i_RTemplate 模板对象
* @param i_IDX 单元格样式在模板中的索引位置
* @return
*/
public synchronized CellStyle getCellStyle(RTemplate i_RTemplate ,int i_IDX)
{
CellStyle v_DataCellStyle = this.cellStyles.getRow(i_RTemplate ,String.valueOf(i_IDX));
if ( v_DataCellStyle == null )
{
v_DataCellStyle = this.workbook.createCellStyle();
CellStyle v_TemplateCellStyle = i_RTemplate.getTemplateSheet().getWorkbook().getCellStyleAt(i_IDX);
ExcelHelp.copyCellStyle(v_TemplateCellStyle ,v_DataCellStyle);
v_DataCellStyle.setFont(this.getFont(i_RTemplate ,v_TemplateCellStyle.getFontIndex()));
this.cellStyles.putRow(i_RTemplate ,String.valueOf(i_IDX) ,v_DataCellStyle);
}
return v_DataCellStyle;
}
示例14: doCreateStyleMap
import org.apache.poi.ss.usermodel.CellStyle; //导入依赖的package包/类
/** 实际创建CellStyle Map
* @param workbook
* @param exportInfo
* @param isHead
* @return
*/
private static Map<Field, CellStyle> doCreateStyleMap(Workbook workbook, ExportInfo exportInfo,boolean isHead) {
Map<ExportCellStyleInfo, CellStyle> tempCacheMap = new HashMap<ExportCellStyleInfo, CellStyle>();
Map<Field, CellStyle> styleMap = new HashMap<Field, CellStyle>();
CellStyle style;
for(Map.Entry<Field,ExportFieldInfo> entry : exportInfo.getFieldInfoMap().entrySet()){
ExportCellStyleInfo styleInfo ;
if(isHead){
styleInfo = entry.getValue().getHeadStyle();
}else{
styleInfo = entry.getValue().getDataStyle();
}
if(!StringUtils.isEmpty(entry.getValue().getDataFormat())){
//当存在格式化时,即使是来自通用的样式,但是格式不一样,所以需要new专属格式的样式
//由于格式化属于专属,因此也不需要放到临时缓存map之中
style = doCreateCellStyle(workbook,styleInfo,entry.getValue().getDataFormat());
}else{
style = tempCacheMap.get(styleInfo);
if(style == null){
style = doCreateCellStyle(workbook,styleInfo,null);
tempCacheMap.put(styleInfo, style);
}
}
if(style != null ){
styleMap.put(entry.getKey(),style);
}
}
tempCacheMap.clear();
return styleMap.isEmpty() ? null : styleMap;
}
示例15: createFirstRow
import org.apache.poi.ss.usermodel.CellStyle; //导入依赖的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);
}