本文整理汇总了Java中org.apache.poi.hssf.usermodel.HSSFWorkbook.createFont方法的典型用法代码示例。如果您正苦于以下问题:Java HSSFWorkbook.createFont方法的具体用法?Java HSSFWorkbook.createFont怎么用?Java HSSFWorkbook.createFont使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.hssf.usermodel.HSSFWorkbook
的用法示例。
在下文中一共展示了HSSFWorkbook.createFont方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createHSSFCellStyle
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的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;
}
示例2: copyFont
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类
public static HSSFFont copyFont(final HSSFWorkbook workbook, final HSSFFont font) {
final HSSFFont newFont = workbook.createFont();
// newFont.setBoldweight(font.getBoldweight());
// newFont.setCharSet(font.getCharSet());
// newFont.setColor(font.getColor());
// newFont.setFontHeight(font.getFontHeight());
// newFont.setFontHeightInPoints(font.getFontHeightInPoints());
// newFont.setFontName(font.getFontName());
// newFont.setItalic(font.getItalic());
// newFont.setStrikeout(font.getStrikeout());
// newFont.setTypeOffset(font.getTypeOffset());
// newFont.setUnderline(font.getUnderline());
return newFont;
}
示例3: createCellStyleForColumnHeading
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的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;
}
示例4: copyFont
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类
public static HSSFFont copyFont(HSSFWorkbook workbook, HSSFFont font) {
HSSFFont newFont = workbook.createFont();
// newFont.setBoldweight(font.getBoldweight());
// newFont.setCharSet(font.getCharSet());
// newFont.setColor(font.getColor());
// newFont.setFontHeight(font.getFontHeight());
// newFont.setFontHeightInPoints(font.getFontHeightInPoints());
// newFont.setFontName(font.getFontName());
// newFont.setItalic(font.getItalic());
// newFont.setStrikeout(font.getStrikeout());
// newFont.setTypeOffset(font.getTypeOffset());
// newFont.setUnderline(font.getUnderline());
return newFont;
}
示例5: buildExcelDocument
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类
@Override
protected void buildExcelDocument(Map<String, Object> model,
HSSFWorkbook workbook, HttpServletRequest request, HttpServletResponse response)
throws Exception {
// get data model which is passed by the Spring container
List<RatingCountBean> listOfRating = (List<RatingCountBean>) model.get("listOfRatingCount");
// create a new Excel sheet
HSSFSheet sheet = workbook.createSheet("Feedback Report");
sheet.setDefaultColumnWidth(30);
// create style for header cells
CellStyle style = workbook.createCellStyle();
Font font = workbook.createFont();
font.setFontName("Arial");
style.setFillForegroundColor(HSSFColor.BLUE.index);
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
font.setColor(HSSFColor.WHITE.index);
style.setFont(font);
// create header row
HSSFRow header = sheet.createRow(0);
header.createCell(0).setCellValue("Question Number");
header.getCell(0).setCellStyle(style);
header.createCell(1).setCellValue("Question");
header.getCell(1).setCellStyle(style);
header.createCell(2).setCellValue("Very Poor");
header.getCell(2).setCellStyle(style);
header.createCell(3).setCellValue("Poor");
header.getCell(3).setCellStyle(style);
header.createCell(4).setCellValue("Good");
header.getCell(4).setCellStyle(style);
header.createCell(5).setCellValue("Best");
header.getCell(5).setCellStyle(style);
header.createCell(6).setCellValue("Excellent");
header.getCell(6).setCellStyle(style);
// create data rows
int rowCount = 1;
for (RatingCountBean rating : listOfRating) {
HSSFRow aRow = sheet.createRow(rowCount++);
aRow.createCell(0).setCellValue(rating.getQuestionId());
aRow.createCell(1).setCellValue(rating.getQuestionText());
aRow.createCell(2).setCellValue(rating.getRating_one_total_count());
aRow.createCell(3).setCellValue(rating.getRating_two_total_count());
aRow.createCell(4).setCellValue(rating.getRating_three_total_count());
aRow.createCell(5).setCellValue(rating.getRating_four_total_count());
aRow.createCell(6).setCellValue(rating.getRating_five_total_count());
}
}
示例6: createHeader
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类
private void createHeader(
HSSFWorkbook wb,
HSSFSheet sheet,
List<TascaDadaDto> informeCamps) {
HSSFFont bold;
bold = wb.createFont();
bold.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
bold.setColor(HSSFColor.WHITE.index);
HSSFCellStyle headerStyle;
headerStyle = wb.createCellStyle();
headerStyle.setFillPattern(HSSFCellStyle.FINE_DOTS);
headerStyle.setFillBackgroundColor(HSSFColor.GREY_80_PERCENT.index);
headerStyle.setFont(bold);
int rowNum = 0;
int colNum = 0;
// Capçalera
HSSFRow xlsRow = sheet.createRow(rowNum++);
HSSFCell cell;
cell = xlsRow.createCell(colNum++);
cell.setCellValue(new HSSFRichTextString(StringUtils.capitalize("Expedient")));
cell.setCellStyle(headerStyle);
for (TascaDadaDto camp : informeCamps) {
sheet.autoSizeColumn(colNum);
cell = xlsRow.createCell(colNum++);
cell.setCellValue(new HSSFRichTextString(StringUtils.capitalize(camp.getCampEtiqueta())));
cell.setCellStyle(headerStyle);
}
}
示例7: buildExcelDocument
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类
@Override
protected void buildExcelDocument(Map<String, Object> model,
HSSFWorkbook workbook, HttpServletRequest request, HttpServletResponse response)
throws Exception {
// get data model which is passed by the Spring container
@SuppressWarnings("unchecked")
List<HrmsLogin> users = (List<HrmsLogin>) model.get("allUsers");
// create a new Excel sheet
HSSFSheet sheet = workbook.createSheet("User List");
sheet.setDefaultColumnWidth(30);
// create style for header cells
CellStyle style = workbook.createCellStyle();
Font font = workbook.createFont();
font.setFontName("Arial");
style.setFillForegroundColor(HSSFColor.BLUE.index);
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
font.setColor(HSSFColor.WHITE.index);
style.setFont(font);
// create header row
HSSFRow header = sheet.createRow(0);
header.createCell(0).setCellValue("Employee ID");
header.getCell(0).setCellStyle(style);
header.createCell(1).setCellValue("Username");
header.getCell(1).setCellStyle(style);
header.createCell(2).setCellValue("Password");
header.getCell(2).setCellStyle(style);
header.createCell(3).setCellValue("Role");
header.getCell(3).setCellStyle(style);
// create data rows
int rowCount = 1;
for (HrmsLogin account : users) {
HSSFRow aRow = sheet.createRow(rowCount++);
aRow.createCell(0).setCellValue(account.getHrmsEmployeeDetails().getEmpId());
aRow.createCell(1).setCellValue(account.getUsername());
aRow.createCell(2).setCellValue(account.getPassword());
aRow.createCell(3).setCellValue(account.getRole());
}
}
示例8: setBold
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类
private static void setBold(HSSFWorkbook workbook, HSSFCell cell) {
HSSFCellStyle boldStyle = workbook.createCellStyle();
HSSFFont boldFont = workbook.createFont();
boldFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
boldStyle.setFont(boldFont);
cell.setCellStyle(boldStyle);
}
示例9: createCellStyleForComRepNotSetUp
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类
public static HSSFCellStyle createCellStyleForComRepNotSetUp(HSSFWorkbook workBook) {
HSSFCellStyle cellStyle = workBook.createCellStyle();
HSSFFont fontObj = workBook.createFont();
cellStyle.setAlignment(HorizontalAlignment.CENTER);
fontObj.setFontName("Calibri");
fontObj.setFontHeightInPoints(Short.valueOf("12").shortValue());
fontObj.setBold(true);
fontObj.setColor((short) 10);
cellStyle.setFont(fontObj);
return cellStyle;
}
示例10: createCellStyleForComRepSetUp
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类
public static HSSFCellStyle createCellStyleForComRepSetUp(HSSFWorkbook workBook) {
HSSFCellStyle cellStyle = workBook.createCellStyle();
HSSFFont fontObj = workBook.createFont();
cellStyle.setAlignment(HorizontalAlignment.CENTER);
fontObj.setFontName("Calibri");
fontObj.setFontHeightInPoints(Short.valueOf("12").shortValue());
fontObj.setBold(true);
fontObj.setColor((short) 17);
cellStyle.setFont(fontObj);
return cellStyle;
}
示例11: createHSSFCellStyles
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类
private Map<String, CellStyle> createHSSFCellStyles(Workbook wb, int[] contextBgColor, int[] contextFontColor, int contextFontSize, int contextFontAlign, int[] headerBgColor,
int[] headerFontColor, int headerFontSize, int headerAlign) {
Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
HSSFWorkbook workbook = (HSSFWorkbook) wb;
HSSFPalette palette = workbook.getCustomPalette();
palette.setColorAtIndex((short) 11, (byte) contextBgColor[0], (byte) contextBgColor[1], (byte) contextBgColor[2]);
palette.setColorAtIndex((short) 12, (byte) contextFontColor[0], (byte) contextFontColor[1], (byte) contextFontColor[2]);
palette.setColorAtIndex((short) 13, (byte) headerBgColor[0], (byte) headerBgColor[1], (byte) headerBgColor[2]);
palette.setColorAtIndex((short) 14, (byte) headerFontColor[0], (byte) headerFontColor[1], (byte) headerFontColor[2]);
HSSFFont headerFont = workbook.createFont();
headerFont.setCharSet(HSSFFont.DEFAULT_CHARSET);
headerFont.setFontName("宋体");
headerFont.setColor((short) 14);
headerFont.setBold(true);
headerFont.setFontHeightInPoints((short) headerFontSize);
CellStyle headerStyle = this.createBorderCellStyle(workbook, true);
headerStyle.setFont(headerFont);
headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
headerStyle.setFillForegroundColor((short) 13);
this.setCellStyleAligment(headerStyle, headerAlign);
headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
styles.put(GridStyleType.headerStyle.name(), headerStyle);
HSSFFont dataFont = workbook.createFont();
dataFont.setColor((short) 12);
dataFont.setFontHeightInPoints((short) contextFontSize);
dataFont.setCharSet(HSSFFont.DEFAULT_CHARSET);
dataFont.setFontName("宋体");
CellStyle dataAlignLeftStyle = this.createBorderCellStyle(workbook, true);
dataAlignLeftStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
dataAlignLeftStyle.setFillForegroundColor((short) 11);
dataAlignLeftStyle.setFont(dataFont);
dataAlignLeftStyle.setVerticalAlignment(VerticalAlignment.CENTER);
dataAlignLeftStyle.setWrapText(true);
dataAlignLeftStyle.setAlignment(HorizontalAlignment.LEFT);
styles.put(GridStyleType.dataAlignLeftStyle.name(), dataAlignLeftStyle);
CellStyle dataAlignCenterStyle = this.createBorderCellStyle(workbook, true);
dataAlignCenterStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
dataAlignCenterStyle.setFillForegroundColor((short) 11);
dataAlignCenterStyle.setFont(dataFont);
dataAlignCenterStyle.setVerticalAlignment(VerticalAlignment.CENTER);
dataAlignCenterStyle.setWrapText(true);
dataAlignCenterStyle.setAlignment(HorizontalAlignment.CENTER);
styles.put(GridStyleType.dataAlignCenterStyle.name(), dataAlignCenterStyle);
CellStyle dataAlignRightStyle = this.createBorderCellStyle(workbook, true);
dataAlignRightStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
dataAlignRightStyle.setFillForegroundColor((short) 11);
dataAlignRightStyle.setFont(dataFont);
dataAlignRightStyle.setVerticalAlignment(VerticalAlignment.CENTER);
dataAlignRightStyle.setWrapText(true);
dataAlignRightStyle.setAlignment(HorizontalAlignment.RIGHT);
styles.put(GridStyleType.dataAlignRightStyle.name(), dataAlignRightStyle);
CellStyle dateStyle = this.createBorderCellStyle(workbook, true);
CreationHelper helper = workbook.getCreationHelper();
dateStyle.setDataFormat(helper.createDataFormat().getFormat("m/d/yy h:mm"));
dateStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
dateStyle.setFillForegroundColor((short) 11);
dateStyle.setFont(dataFont);
dateStyle.setVerticalAlignment(VerticalAlignment.CENTER);
this.setCellStyleAligment(dateStyle, contextFontAlign);
styles.put(GridStyleType.dateStyle.name(), dateStyle);
return styles;
}
示例12: exportMotionExcel
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类
/**
* 为退款经办下载表
*
* @param outfile
* @param list
* @param name
* 表名
* @param s为每一格的宽度
* @throws IOException
*/
public FileTransfer exportMotionExcel(List<String[]> list, String filename,
String name, String[] s) throws Exception {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet();
HSSFCellStyle cs = wb.createCellStyle();
// 设置表头的格式
HSSFCellStyle cs1 = wb.createCellStyle();
HSSFFont f1 = wb.createFont();
f1.setFontHeightInPoints((short) 20);// 字体大小
cs1.setFont(f1);
cs1.setAlignment(HSSFCellStyle.ALIGN_CENTER);
// 设置表中的格�?
cs.setBorderBottom(HSSFCellStyle.BORDER_THIN);
cs.setBorderLeft(HSSFCellStyle.BORDER_THIN);
cs.setBorderRight(HSSFCellStyle.BORDER_THIN);
cs.setBorderTop(HSSFCellStyle.BORDER_THIN);
cs.setAlignment(HSSFCellStyle.ALIGN_CENTER);
cs.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
cs.setWrapText(true);// 自动换行
// 将页面设�为横向打印模�?
HSSFPrintSetup hps = sheet.getPrintSetup();
hps.setLandscape(true); // 将页面设置为横向打印模式
hps.setPaperSize(HSSFPrintSetup.A4_PAPERSIZE);// 为A4纸的大小
int columnCount = list.get(0).length;
// 表头那一列的的宽�?
sheet.setColumnWidth((short) 0, (short) 10000);
// 合并单元�?
// sheet.addMergedRegion(new Region((short) 0, (short) 0, (short) 0,
// (short) (columnCount-1)));
// 根据String[] s来设定每一格的宽度
for (int i = 0; i < columnCount; i++) {
sheet.setColumnWidth((short) i, (Short.parseShort(s[i])));
}
// 表名
HSSFRow row1 = sheet.createRow(0);
HSSFCell cell = row1.createCell(0);
cell.setCellValue(name);
cell.setCellStyle(cs1);
row1.setHeight((short) 800);
sheet.addMergedRegion(new Region((short) 0, (short) 0, (short) 0,
(short) (columnCount - 1)));
HSSFRow rows = null;
for (int i = 0; i < list.size(); i++) {
rows = sheet.createRow(i + 1);
String cellDate[] = list.get(i);
HSSFCell cells = null;
for (int j = 0; j < cellDate.length; j++) {
cells = rows.createCell((short) (j));
cells.setCellValue(cellDate[j]);
cells.setCellStyle(cs);
}
if (i == 0) {
rows.setHeight((short) 600);// 标题行宽�?
}
}
wb.write(buffer);
return new FileTransfer(filename, "application/x-xls", buffer
.toByteArray());
}