Java Code Examples for org.apache.poi.hssf.usermodel.HSSFCellStyle#setFont()
The following examples show how to use
org.apache.poi.hssf.usermodel.HSSFCellStyle#setFont() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: POIUtils.java From ermasterr with Apache License 2.0 | 7 votes |
public static HSSFCellStyle copyCellStyle(final HSSFWorkbook workbook, final HSSFCellStyle style) { final HSSFCellStyle newCellStyle = workbook.createCellStyle(); newCellStyle.setAlignment(style.getAlignment()); newCellStyle.setBorderBottom(style.getBorderBottom()); newCellStyle.setBorderLeft(style.getBorderLeft()); newCellStyle.setBorderRight(style.getBorderRight()); newCellStyle.setBorderTop(style.getBorderTop()); newCellStyle.setBottomBorderColor(style.getBottomBorderColor()); newCellStyle.setDataFormat(style.getDataFormat()); newCellStyle.setFillBackgroundColor(style.getFillBackgroundColor()); newCellStyle.setFillForegroundColor(style.getFillForegroundColor()); newCellStyle.setFillPattern(style.getFillPattern()); newCellStyle.setHidden(style.getHidden()); newCellStyle.setIndention(style.getIndention()); newCellStyle.setLeftBorderColor(style.getLeftBorderColor()); newCellStyle.setLocked(style.getLocked()); newCellStyle.setRightBorderColor(style.getRightBorderColor()); newCellStyle.setRotation(style.getRotation()); newCellStyle.setTopBorderColor(style.getTopBorderColor()); newCellStyle.setVerticalAlignment(style.getVerticalAlignment()); newCellStyle.setWrapText(style.getWrapText()); final HSSFFont font = workbook.getFontAt(style.getFontIndex()); newCellStyle.setFont(font); return newCellStyle; }
Example 2
Source File: TitleStyleBuilder.java From bdf3 with Apache License 2.0 | 6 votes |
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.setBoldweight(Font.BOLDWEIGHT_BOLD); titleFont.setFontHeightInPoints((short) fontSize); HSSFCellStyle titleStyle = (HSSFCellStyle) createBorderCellStyle(workbook, true); titleStyle.setFont(titleFont); titleStyle.setFillPattern(CellStyle.SOLID_FOREGROUND); titleStyle.setFillForegroundColor((short) 10); titleStyle.setAlignment(CellStyle.ALIGN_CENTER); titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); return titleStyle; }
Example 3
Source File: ExcelExportUtil.java From jeewx with Apache License 2.0 | 5 votes |
/** * 表明的Style * @param workbook * @return */ public static HSSFCellStyle getHeaderStyle(HSSFWorkbook workbook, ExcelTitle entity) { HSSFCellStyle titleStyle = workbook.createCellStyle(); Font font = workbook.createFont(); font.setFontHeightInPoints((short) 24); titleStyle.setFont(font); titleStyle.setFillForegroundColor(entity.getColor()); titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); titleStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); return titleStyle; }
Example 4
Source File: ExportUtil.java From jumbune with GNU Lesser General Public License v3.0 | 5 votes |
/** * Sets header style * @param worksheet the worksheet * @param fontName font name * @param fontColor font color * @param fontBoldweight font weight */ public static void setHeaderStyle(Worksheet worksheet, String fontName, short fontColor, short fontBoldweight) { HSSFWorkbook workbook = worksheet.getWorkbook(); HSSFFont font = workbook.createFont(); font.setFontName(fontName); font.setColor(fontColor); font.setBoldweight(fontBoldweight); HSSFCellStyle cellStyle = workbook.createCellStyle(); cellStyle.setFont(font); worksheet.setCellStyle(cellStyle); }
Example 5
Source File: InvestmentSummaryController.java From primefaces-blueprints with The Unlicense | 5 votes |
public void postProcessXLS(Object document) { HSSFWorkbook wb = (HSSFWorkbook) document; HSSFSheet sheet = wb.getSheetAt(0); HSSFRow header = sheet.getRow(0); HSSFCellStyle cellStyle = wb.createCellStyle(); cellStyle.setFillForegroundColor(HSSFColor.GREEN.index); cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); for(int i=0; i < header.getPhysicalNumberOfCells();i++) { HSSFCell cell = header.getCell(i); cell.setCellStyle(cellStyle); } Row row=sheet.createRow((short)sheet.getLastRowNum()+3); Cell cellDisclaimer = row.createCell(0); HSSFFont customFont= wb.createFont(); customFont.setFontHeightInPoints((short)10); customFont.setFontName("Arial"); customFont.setColor(IndexedColors.BLACK.getIndex()); customFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); customFont.setItalic(true); cellDisclaimer.setCellValue("Disclaimer"); HSSFCellStyle cellStyleDisclaimer = wb.createCellStyle(); cellStyleDisclaimer.setFont(customFont); cellDisclaimer.setCellStyle(cellStyleDisclaimer); Row row1=sheet.createRow(sheet.getLastRowNum()+2); Cell cellDisclaimerContent1 = row1.createCell(0); cellDisclaimerContent1.setCellValue("The information contained in this website is for information purposes only, and does not constitute, nor is it intended to constitute, the provision of financial product advice."); Row row2=sheet.createRow(sheet.getLastRowNum()+1); Cell cellDisclaimerContent2 = row2.createCell(0); cellDisclaimerContent2.setCellValue("This website is intended to track the investor account summary information,investments and transaction in a partcular period of time. "); }
Example 6
Source File: AccountSummaryController.java From primefaces-blueprints with The Unlicense | 5 votes |
public void postProcessXLS(Object document) { HSSFWorkbook wb = (HSSFWorkbook) document; HSSFSheet sheet = wb.getSheetAt(0); HSSFRow header = sheet.getRow(0); HSSFCellStyle cellStyle = wb.createCellStyle(); cellStyle.setFillForegroundColor(HSSFColor.GREEN.index); cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); for(int i=0; i < header.getPhysicalNumberOfCells();i++) { HSSFCell cell = header.getCell(i); cell.setCellStyle(cellStyle); } Row row=sheet.createRow((short)sheet.getLastRowNum()+3); Cell cellDisclaimer = row.createCell(0); HSSFFont customFont= wb.createFont(); customFont.setFontHeightInPoints((short)10); customFont.setFontName("Arial"); customFont.setColor(IndexedColors.BLACK.getIndex()); customFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); customFont.setItalic(true); cellDisclaimer.setCellValue("Disclaimer"); HSSFCellStyle cellStyleDisclaimer = wb.createCellStyle(); cellStyleDisclaimer.setFont(customFont); cellDisclaimer.setCellStyle(cellStyleDisclaimer); Row row1=sheet.createRow(sheet.getLastRowNum()+2); Cell cellDisclaimerContent1 = row1.createCell(0); cellDisclaimerContent1.setCellValue("The information contained in this website is for information purposes only, and does not constitute, nor is it intended to constitute, the provision of financial product advice."); Row row2=sheet.createRow(sheet.getLastRowNum()+1); Cell cellDisclaimerContent2 = row2.createCell(0); cellDisclaimerContent2.setCellValue("This website is intended to track the investor account summary information,investments and transaction in a partcular period of time. "); }
Example 7
Source File: TransactionSummaryController.java From primefaces-blueprints with The Unlicense | 5 votes |
public void postProcessXLS(Object document) { HSSFWorkbook wb = (HSSFWorkbook) document; HSSFSheet sheet = wb.getSheetAt(0); HSSFRow header = sheet.getRow(0); HSSFCellStyle cellStyle = wb.createCellStyle(); cellStyle.setFillForegroundColor(HSSFColor.GREEN.index); cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); for (int i = 0; i < header.getPhysicalNumberOfCells(); i++) { HSSFCell cell = header.getCell(i); cell.setCellStyle(cellStyle); } Row row = sheet.createRow((short) sheet.getLastRowNum() + 3); Cell cellDisclaimer = row.createCell(0); HSSFFont customFont = wb.createFont(); customFont.setFontHeightInPoints((short) 10); customFont.setFontName("Arial"); customFont.setColor(IndexedColors.BLACK.getIndex()); customFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); customFont.setItalic(true); cellDisclaimer.setCellValue("Disclaimer"); HSSFCellStyle cellStyleDisclaimer = wb.createCellStyle(); cellStyleDisclaimer.setFont(customFont); cellDisclaimer.setCellStyle(cellStyleDisclaimer); Row row1 = sheet.createRow(sheet.getLastRowNum() + 2); Cell cellDisclaimerContent1 = row1.createCell(0); cellDisclaimerContent1 .setCellValue("The information contained in this website is for information purposes only, and does not constitute, nor is it intended to constitute, the provision of financial product advice."); Row row2 = sheet.createRow(sheet.getLastRowNum() + 1); Cell cellDisclaimerContent2 = row2.createCell(0); cellDisclaimerContent2 .setCellValue("This website is intended to track the investor account summary information,investments and transaction in a partcular period of time. "); }
Example 8
Source File: XslStyleHelper.java From yarg with Apache License 2.0 | 5 votes |
public static void cloneFont(HSSFCellStyle source, HSSFCellStyle target) { // Handle matching things if we cross workbooks InternalWorkbook sourceWorkbook = getWorkbookFromStyle(source); InternalWorkbook targetWorkbook = getWorkbookFromStyle(target); if (targetWorkbook != sourceWorkbook) { // Finally we need to clone the font, and update the format record for this FontRecord fr = targetWorkbook.createNewFont(); fr.cloneStyleFrom(sourceWorkbook.getFontRecordAt(source.getFontIndex())); HSSFFont font = newInstance(HSSFFont.class, new Class[]{int.class, FontRecord.class}, (short)targetWorkbook.getFontIndex(fr), fr); target.setFont(font); } }
Example 9
Source File: POIUtils.java From ermaster-b with Apache License 2.0 | 5 votes |
public static HSSFCellStyle copyCellStyle(HSSFWorkbook workbook, HSSFCellStyle style) { HSSFCellStyle newCellStyle = workbook.createCellStyle(); newCellStyle.setAlignment(style.getAlignment()); newCellStyle.setBorderBottom(style.getBorderBottom()); newCellStyle.setBorderLeft(style.getBorderLeft()); newCellStyle.setBorderRight(style.getBorderRight()); newCellStyle.setBorderTop(style.getBorderTop()); newCellStyle.setBottomBorderColor(style.getBottomBorderColor()); newCellStyle.setDataFormat(style.getDataFormat()); newCellStyle.setFillBackgroundColor(style.getFillBackgroundColor()); newCellStyle.setFillForegroundColor(style.getFillForegroundColor()); newCellStyle.setFillPattern(style.getFillPattern()); newCellStyle.setHidden(style.getHidden()); newCellStyle.setIndention(style.getIndention()); newCellStyle.setLeftBorderColor(style.getLeftBorderColor()); newCellStyle.setLocked(style.getLocked()); newCellStyle.setRightBorderColor(style.getRightBorderColor()); newCellStyle.setRotation(style.getRotation()); newCellStyle.setTopBorderColor(style.getTopBorderColor()); newCellStyle.setVerticalAlignment(style.getVerticalAlignment()); newCellStyle.setWrapText(style.getWrapText()); HSSFFont font = workbook.getFontAt(style.getFontIndex()); newCellStyle.setFont(font); return newCellStyle; }
Example 10
Source File: PoiExport.java From hrms with Apache License 2.0 | 4 votes |
public InputStream exportExcel(String fileName, String[] headTitle, List<String> list) throws IOException { Workbook wb = new HSSFWorkbook(); //FileOutputStream fileOut = new FileOutputStream(fileName); HSSFCellStyle style = (HSSFCellStyle) wb.createCellStyle(); // 设置这些样式 style.setFillForegroundColor(HSSFColor.SKY_BLUE.index); style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); style.setBorderBottom(HSSFCellStyle.BORDER_THIN); style.setBorderLeft(HSSFCellStyle.BORDER_THIN); style.setBorderRight(HSSFCellStyle.BORDER_THIN); style.setBorderTop(HSSFCellStyle.BORDER_THIN); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 生成一个字体 HSSFFont font = (HSSFFont) wb.createFont(); font.setColor(HSSFColor.VIOLET.index); font.setFontHeightInPoints((short) 12); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); // 把字体应用到当前的样式 style.setFont(font); // 创建工作簿 Sheet sheet = wb.createSheet("sheet1"); // sheet.setDefaultColumnWidth((short)15); // 创建头部 Row row = sheet.createRow((short) 0); for (int i = 0; i < headTitle.length; i++) { row.createCell(i).setCellValue(headTitle[i]); } // 填充数据 for (int i = 0; i < list.size(); i++) { Row r = sheet.createRow((short) (i + 1)); String[] strArray = list.get(i).split(","); for (int j = 0; j < headTitle.length; j++) { r.createCell(j).setCellValue(strArray[j]); if (strArray[j].length()>3) { sheet.setColumnWidth((short)j, 5000); } } } ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { wb.write(baos); } catch (IOException e) { e.printStackTrace(); } byte[] ba = baos.toByteArray(); ByteArrayInputStream excelStream = new ByteArrayInputStream(ba); return excelStream; }
Example 11
Source File: CourseLoadOverviewBean.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 4 votes |
public StyledExcelSpreadsheet getInconsistencySpreadsheet() { final StyledExcelSpreadsheet spreadsheet = new StyledExcelSpreadsheet(BundleUtil.getString(Bundle.ACADEMIC, "label.course.load.inconsistency.filename") + "_" + executionSemester.getExecutionYear().getYear().replace('/', '_') + "_" + executionSemester.getSemester()); CellStyle normalStyle = spreadsheet.getExcelStyle().getValueStyle(); normalStyle.setAlignment(HorizontalAlignment.CENTER); HSSFWorkbook wb = spreadsheet.getWorkbook(); HSSFFont font = wb.createFont(); font.setColor(HSSFColor.BLACK.index); font.setFontHeightInPoints((short) 8); HSSFCellStyle redStyle = wb.createCellStyle(); redStyle.setFont(font); redStyle.setAlignment(HorizontalAlignment.CENTER); redStyle.setFillForegroundColor(HSSFColor.ORANGE.index); redStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); HSSFCellStyle yellowStyle = wb.createCellStyle(); yellowStyle.setFont(font); yellowStyle.setAlignment(HorizontalAlignment.CENTER); yellowStyle.setFillForegroundColor(HSSFColor.YELLOW.index); yellowStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); spreadsheet.newHeaderRow(); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.department")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.degree")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.executionCourse")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.shift")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.shiftType")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.load.competenceCourse")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.load.curricularCourse")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.load.executionCourse")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.load.lessonInstances")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.load.lesson.count")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.load.lessonInstances.count")); for (final ExecutionCourse executionCourse : executionSemester.getAssociatedExecutionCoursesSet()) { for (final CourseLoad courseLoad : executionCourse.getCourseLoadsSet()) { for (final Shift shift : courseLoad.getShiftsSet()) { spreadsheet.newRow(); spreadsheet.addCell(getDepartmentString(executionCourse)); spreadsheet.addCell(executionCourse.getDegreePresentationString()); spreadsheet.addCell(executionCourse.getName()); spreadsheet.addCell(shift.getNome()); spreadsheet.addCell(courseLoad.getType().getFullNameTipoAula()); final BigDecimal competenceCourseLoad = new BigDecimal(getCompetenceCourseLoad(courseLoad)).setScale(2, RoundingMode.HALF_EVEN); final BigDecimal curricularCourseLoad = new BigDecimal(getCurricularCourseLoad(courseLoad)).setScale(2, RoundingMode.HALF_EVEN); final BigDecimal executionLoad = courseLoad.getTotalQuantity().setScale(2, RoundingMode.HALF_EVEN); final BigDecimal shiftCourseLoad = getShiftCourseLoad(shift).setScale(2, RoundingMode.HALF_EVEN); if (competenceCourseLoad.signum() < 0) { spreadsheet.addCell(getCompetenceCourseLoadStrings(courseLoad), redStyle); } else { spreadsheet.addCell(competenceCourseLoad); } if (!competenceCourseLoad.equals(curricularCourseLoad) || curricularCourseLoad.signum() < 0) { spreadsheet.addCell(getCurricularCourseLoadString(courseLoad), redStyle); } else { spreadsheet.addCell(curricularCourseLoad); } if (!executionLoad.equals(curricularCourseLoad)) { spreadsheet.addCell(executionLoad, redStyle); } else { spreadsheet.addCell(executionLoad); } if (!shiftCourseLoad.equals(executionLoad)) { if (isLargeDifference(shiftCourseLoad, executionLoad, competenceCourseLoad.divide(new BigDecimal(14), 2, RoundingMode.HALF_EVEN))) { spreadsheet.addCell(shiftCourseLoad, redStyle); } else { spreadsheet.addCell(shiftCourseLoad, yellowStyle); } } else { spreadsheet.addCell(shiftCourseLoad); } spreadsheet.addCell(shift.getAssociatedLessonsSet().size()); spreadsheet.addCell(getLessonInstanceCount(shift)); } } } final HSSFSheet sheet = wb.getSheetAt(0); sheet.createFreezePane(0, 1, 0, 1); sheet.autoSizeColumn(1, true); sheet.autoSizeColumn(2, true); sheet.autoSizeColumn(3, true); sheet.autoSizeColumn(4, true); sheet.autoSizeColumn(5, true); sheet.autoSizeColumn(6, true); sheet.autoSizeColumn(7, true); sheet.autoSizeColumn(8, true); sheet.autoSizeColumn(9, true); return spreadsheet; }