本文整理匯總了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());
}