List of usage examples for org.apache.poi.xssf.usermodel XSSFWorkbook createFont
@Override
public XSSFFont createFont()
From source file:mvjce.internal_sheet.java
public static void internal_details(XSSFWorkbook workbook) { XSSFSheet spreadsheet = workbook.createSheet("test_excel_internal"); XSSFRow row = spreadsheet.createRow((short) 0); XSSFCell cell = (XSSFCell) row.createCell((short) 0); cell.setCellValue("MVJ College of Bangalore- 560067"); //MEARGING CELLS spreadsheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 19)); XSSFFont font = workbook.createFont(); font.setFontName("Arial"); font.setBold(true);// w ww . ja va2 s .c om XSSFCellStyle style = workbook.createCellStyle(); style.setAlignment(XSSFCellStyle.ALIGN_CENTER); style.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER); style.setWrapText(true); style.setFont(font); cell.setCellStyle(style); Excel_operations.set_subcode(); row = spreadsheet.createRow((short) 1); cell = (XSSFCell) row.createCell((short) 0); cell.setCellValue("Department of " + dept_name); spreadsheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 19)); cell.setCellStyle(style); row = spreadsheet.createRow(3); row.setHeight((short) 600); cell = (XSSFCell) row.createCell((short) 1); cell.setCellValue("Semester: \n" + sem_string + sec); cell.setCellStyle(style); row = spreadsheet.createRow(4); String[] text = new String[3]; text[0] = "SI.No"; text[1] = "USN"; text[2] = "STUDENT NAME"; for (int i = 0; i < 3; i++) { cell = (XSSFCell) row.createCell((short) i); cell.setCellValue(text[i]); cell.setCellStyle(style); spreadsheet.addMergedRegion(new CellRangeAddress(4, 5, i, i)); } XSSFRow row2 = spreadsheet.createRow((short) 5); for (int i = 0, j = 3; j <= 23; j += 4) { cell = row.createCell((short) j); cell.setCellValue(sub[i]); i++; cell.setCellStyle(style); cell = row2.createCell(j); cell.setCellValue("T1"); cell.setCellStyle(style); cell = row2.createCell(j + 1); cell.setCellValue("T2"); cell.setCellStyle(style); cell = row2.createCell(j + 2); cell.setCellValue("T3"); cell.setCellStyle(style); cell = row2.createCell(j + 3); cell.setCellValue("Avg"); cell.setCellStyle(style); spreadsheet.addMergedRegion(new CellRangeAddress(4, 4, j, j + 3)); Excel_operations.insert_internals(workbook, spreadsheet); } }
From source file:mvjce.Writesheet.java
public static void writesheet() { XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet spreadsheet = workbook.createSheet(sem_string + sec); XSSFRow row = spreadsheet.createRow((short) 0); XSSFCell cell = (XSSFCell) row.createCell((short) 0); cell.setCellValue("MVJ College of Bangalore- 560067"); //MEARGING CELLS spreadsheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 19)); XSSFFont font = workbook.createFont(); font.setFontName("Arial"); font.setBold(true);/* w ww . j a v a2 s .c om*/ XSSFCellStyle style = workbook.createCellStyle(); style.setAlignment(XSSFCellStyle.ALIGN_CENTER); style.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER); style.setWrapText(true); style.setFont(font); cell.setCellStyle(style); Excel_operations.set_subcode(); for (int i = 0; i < 8; i++) { internal_sheet.sub[i] = sub[i]; } internal_sheet.dept_name = dept_name; internal_sheet.sec = sec; internal_sheet.sem_string = sem_string; internal_sheet.internal_details(workbook); row = spreadsheet.createRow((short) 1); cell = (XSSFCell) row.createCell((short) 0); cell.setCellValue("Department of " + dept_name); spreadsheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 19)); cell.setCellStyle(style); row = spreadsheet.createRow(4); row.setHeight((short) 600); cell = (XSSFCell) row.createCell((short) 1); cell.setCellValue("Semester: \n" + sem_string + sec); cell.setCellStyle(style); row = spreadsheet.createRow(5); String[] text = new String[3]; text[0] = "SI.No"; text[1] = "USN"; text[2] = "STUDENT\nNAME"; for (int i = 0; i < 3; i++) { cell = (XSSFCell) row.createCell((short) i); cell.setCellValue(text[i]); cell.setCellStyle(style); spreadsheet.addMergedRegion(new CellRangeAddress(5, 7, i, i)); } int j = 0; XSSFRow row1 = spreadsheet.createRow((short) 6); row1.setHeight((short) 1000); XSSFRow row2 = spreadsheet.createRow((short) 7); row2.setHeight((short) 1000); for (int i = 3; i < 18; i++) { cell = row1.createCell((short) i); cell.setCellValue("Total no. of classes"); cell.setCellStyle(style); cell = row2.createCell((short) i); cell.setCellValue("No.of Classes attended"); cell.setCellStyle(style); cell = row2.createCell((short) i + 1); cell.setCellValue("%"); cell.setCellStyle(style); cell = row.createCell((short) i); cell.setCellValue(sub[j]); j++; cell.setCellStyle(style); spreadsheet.addMergedRegion(new CellRangeAddress(5, 5, i, i + 1)); i++; } cell = row1.createCell((short) 19); cell.setCellValue("%"); cell.setCellStyle(style); cell = row.createCell((short) 19); cell.setCellValue("AVG"); cell.setCellStyle(style); spreadsheet.addMergedRegion(new CellRangeAddress(5, 5, 19, 19)); Excel_operations.fill_exceldata(workbook, spreadsheet); try { FileOutputStream out = new FileOutputStream(new File("test_excel.xlsx")); workbook.write(out); out.close(); } catch (Exception e) { Database.print_error("Excel_output_stream"); } System.out.println("typesofcells.xlsx written successfully"); }
From source file:nc.noumea.mairie.appock.util.StockSpreadsheetExporter.java
License:Open Source License
private static int createTitle(XSSFWorkbook workbook, XSSFSheet worksheet, Service service) { XSSFCellStyle titleStyle = workbook.createCellStyle(); titleStyle.setAlignment(HorizontalAlignment.CENTER); titleStyle.setVerticalAlignment(VerticalAlignment.CENTER); XSSFFont txtFont = workbook.createFont(); txtFont.setFontName("calibri"); txtFont.setFontHeightInPoints((short) 11); txtFont.setBold(true);//ww w . j a v a 2s. c om titleStyle.setFont(txtFont); XSSFRow row = worksheet.createRow(0); XSSFCell cell = row.createCell(0); cell.setCellValue( "Inventaire " + service.getDirection().getLibelleCourt() + " - " + service.getLibelleCourt()); cell.setCellStyle(titleStyle); worksheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 5)); return 2; }
From source file:nc.noumea.mairie.appock.util.StockSpreadsheetExporter.java
License:Open Source License
private static int generateHeader(XSSFSheet worksheet, XSSFWorkbook workbook, int rowNum) { // Now add/* ww w. j ava 2 s . com*/ XSSFRow row = worksheet.createRow(rowNum); XSSFCell cell; XSSFCellStyle headerStyle = workbook.createCellStyle(); headerStyle.setFillForegroundColor(IndexedColors.LIGHT_BLUE.index); headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); headerStyle.setBorderBottom(BorderStyle.MEDIUM); headerStyle.setBorderLeft(BorderStyle.MEDIUM); headerStyle.setBorderRight(BorderStyle.MEDIUM); headerStyle.setBorderTop(BorderStyle.MEDIUM); headerStyle.setAlignment(HorizontalAlignment.CENTER); headerStyle.setVerticalAlignment(VerticalAlignment.CENTER); XSSFFont txtFont = workbook.createFont(); txtFont.setFontName("calibri"); txtFont.setFontHeightInPoints((short) 9); txtFont.setBold(true); headerStyle.setFont(txtFont); cell = row.createCell(0); cell.setCellValue("Photo"); cell.setCellStyle(headerStyle); worksheet.setColumnWidth(0, ConvertImageUnits.pixel2WidthUnits(COLUMN_WIDTH_PX));//4387 cell = row.createCell(1); cell.setCellValue("Rfrence"); cell.setCellStyle(headerStyle); cell = row.createCell(2); cell.setCellValue("Libell"); cell.setCellStyle(headerStyle); cell = row.createCell(3); cell.setCellValue("Stock\n Appock"); cell.setCellStyle(headerStyle); cell.getCellStyle().setWrapText(true); cell = row.createCell(4); cell.setCellValue("Stock\n rel"); cell.setCellStyle(headerStyle); cell.getCellStyle().setWrapText(true); row.setHeight((short) 600); return rowNum + 1; }
From source file:nc.noumea.mairie.appock.util.StockSpreadsheetExporter.java
License:Open Source License
private static void createRow(XSSFSheet worksheet, XSSFWorkbook workbook, ArticleStock article, CatalogueService catalogueService, int rowNumber) throws IOException { int col = 0;/* w w w.j a va 2 s. c o m*/ XSSFCellStyle cellStyle = workbook.createCellStyle(); cellStyle.setBorderBottom(BorderStyle.THIN); cellStyle.setBorderLeft(BorderStyle.THIN); cellStyle.setBorderRight(BorderStyle.THIN); cellStyle.setVerticalAlignment(VerticalAlignment.CENTER); XSSFCellStyle cellImageStyle = workbook.createCellStyle(); cellImageStyle.setBorderBottom(BorderStyle.THIN); cellImageStyle.setBorderLeft(BorderStyle.THIN); cellImageStyle.setBorderRight(BorderStyle.THIN); cellImageStyle.setVerticalAlignment(VerticalAlignment.CENTER); cellImageStyle.setAlignment(HorizontalAlignment.CENTER); if (rowNumber != 1) { cellStyle.setBorderTop(BorderStyle.THIN); } XSSFFont txtFont = workbook.createFont(); txtFont.setFontName("calibri"); txtFont.setFontHeightInPoints((short) 9); txtFont.setBold(false); cellStyle.setFont(txtFont); XSSFRow row = worksheet.createRow(rowNumber); row.setHeight((short) ROW_HEIGHT_TWIPS);//80px 1600 // Photo File image = null; try { image = catalogueService.getFilePieceJointe(article.getArticleCatalogue().getPhotoArticleCatalogue()); } catch (IllegalArgumentException e) { log.warn("No image to display for article " + article.getArticleCatalogue().getLibelle()); } XSSFCell cell = row.createCell(col); cell.setCellStyle(cellImageStyle); if (image != null) addImage(workbook, worksheet, image, rowNumber); col = col + 1; // Rfrence cell = row.createCell(col); cell.setCellStyle(cellStyle); col = col + 1; cell.setCellValue(article.getReferenceArticleStock()); // Libell cell = row.createCell(col); cell.setCellStyle(cellStyle); col = col + 1; cell.setCellValue(article.getArticleCatalogue().getLibelle()); // Appock Stock cell = row.createCell(col); cell.setCellStyle(cellStyle); col = col + 1; cell.setCellValue(article.getQuantiteStock()); cell.setCellType(CellType.NUMERIC); // Stock reel cell = row.createCell(col); cell.setCellStyle(cellStyle); cell.setCellType(CellType.NUMERIC); }
From source file:net.mcnewfamily.rmcnew.model.excel.FontEssence.java
License:Open Source License
public XSSFFont toXSSFFont(XSSFWorkbook workbook) { XSSFFont xssfFont = null;/*w w w . ja va2 s . c o m*/ if (workbook != null) { xssfFont = workbook.createFont(); xssfFont.setCharSet(FontCharset.DEFAULT); xssfFont.setFamily(this.fontFamily); xssfFont.setBold(this.bold); if (this.bold) { xssfFont.setBoldweight(Font.BOLDWEIGHT_BOLD); } else { xssfFont.setBoldweight(Font.BOLDWEIGHT_NORMAL); } xssfFont.setItalic(this.italic); if (this.underline) { xssfFont.setUnderline(FontUnderline.SINGLE); } xssfFont.setStrikeout(this.strikeout); xssfFont.setColor(this.color); xssfFont.setFontHeightInPoints(this.fontHeightInPoints); } else { throw new IllegalArgumentException("Cannot create XSSFFont in a null XSSFWorkbook!"); } return xssfFont; }
From source file:offishell.excel.Excel.java
License:MIT License
/** * <p>/* w w w . j a v a 2s.c om*/ * Create {@link Excel} wrapper. * </p> * * @param path * @param book */ private Excel(Path path, XSSFWorkbook book) { this.path = path; this.book = book; this.excel = Locator.file(path); this.sheet = book.getSheetAt(0); this.baseStyle = book.createCellStyle(); this.dateStyle = book.createCellStyle(); CreationHelper helper = book.getCreationHelper(); DataFormat dateFormat = helper.createDataFormat(); Font font = book.createFont(); font.setFontName(" Medium"); font.setFontHeightInPoints((short) 10); baseStyle.setFont(font); baseStyle.setAlignment(HorizontalAlignment.CENTER); baseStyle.setVerticalAlignment(VerticalAlignment.CENTER); baseStyle.setShrinkToFit(true); baseStyle.setWrapText(true); dateStyle.cloneStyleFrom(baseStyle); dateStyle.setDataFormat(dateFormat.getFormat("yyyy/mm/dd")); }
From source file:org.alfresco.bm.report.XLSXReporter.java
License:Open Source License
/** * Creates a new line with values in the sheet. * /*from ww w. j a va 2 s . c o m*/ * @param workbook * (XSSFWorkbook, required) workbook to create the row in * @param sheetRow * (XSSFSheetRow, required) sheet to create the data row in * @param sheetName * (String, required) name of the sheet * @param values * (String [], optional) if null or empty no work will be done, else the values written to the next line * @param bold * (boolean) true: the values will be set in bold font face, else normal * * @since 2.0.10 */ private void createSheetRow(XSSFWorkbook workbook, XSSFSheetRow sheetRow, String sheetName, List<String> values, boolean bold) { if (null != values && values.size() > 0) { // check if sheet exists and create if not if (null == sheetRow.sheet) { sheetRow.sheet = workbook.createSheet(sheetName); } // create cell style XSSFCellStyle cellStyle = workbook.createCellStyle(); cellStyle.setAlignment(HorizontalAlignment.CENTER); if (bold) { // Create bold font Font fontBold = workbook.createFont(); fontBold.setBoldweight(Font.BOLDWEIGHT_BOLD); cellStyle.setFont(fontBold); } // create row XSSFRow row = sheetRow.sheet.createRow(sheetRow.rowCount++); // set values for (int i = 0; i < values.size(); i++) { row.getCell(i).setCellValue(values.get(i)); row.getCell(i).setCellStyle(cellStyle); } } }
From source file:org.alfresco.bm.report.XLSXReporter.java
License:Open Source License
/** * Create a 'Summary' sheet containing the table of averages *//*from w ww . j a v a2 s .c o m*/ private void createSummarySheet(XSSFWorkbook workbook) throws IOException, NotFoundException { DBObject testRunObj = getTestService().getTestRunMetadata(test, run); // Create the sheet XSSFSheet sheet = workbook.createSheet("Summary"); // Create the fonts we need Font fontBold = workbook.createFont(); fontBold.setBoldweight(Font.BOLDWEIGHT_BOLD); // Create the styles we need XSSFCellStyle summaryDataStyle = sheet.getWorkbook().createCellStyle(); summaryDataStyle.setAlignment(HorizontalAlignment.RIGHT); XSSFCellStyle headerStyle = sheet.getWorkbook().createCellStyle(); headerStyle.setAlignment(HorizontalAlignment.RIGHT); headerStyle.setFont(fontBold); XSSFRow row = null; int rowCount = 0; row = sheet.createRow(rowCount++); { row.getCell(0).setCellValue("Name:"); row.getCell(0).setCellStyle(headerStyle); row.getCell(1).setCellValue(title); row.getCell(1).setCellStyle(summaryDataStyle); } row = sheet.createRow(rowCount++); { String description = (String) testRunObj.get(FIELD_DESCRIPTION); description = description == null ? "" : description; row.getCell(0).setCellValue("Description:"); row.getCell(0).setCellStyle(headerStyle); row.getCell(1).setCellValue(description); row.getCell(1).setCellStyle(summaryDataStyle); } row = sheet.createRow(rowCount++); { row.getCell(0).setCellValue("Progress (%):"); row.getCell(0).setCellStyle(headerStyle); Double progress = (Double) testRunObj.get(FIELD_PROGRESS); progress = progress == null ? 0.0 : progress; row.getCell(1).setCellValue(progress * 100); row.getCell(1).setCellType(XSSFCell.CELL_TYPE_NUMERIC); row.getCell(1).setCellStyle(summaryDataStyle); } row = sheet.createRow(rowCount++); { row.getCell(0).setCellValue("State:"); row.getCell(0).setCellStyle(headerStyle); String state = (String) testRunObj.get(FIELD_STATE); if (state != null) { row.getCell(1).setCellValue(state); row.getCell(1).setCellStyle(summaryDataStyle); } } row = sheet.createRow(rowCount++); { row.getCell(0).setCellValue("Started:"); row.getCell(0).setCellStyle(headerStyle); Long time = (Long) testRunObj.get(FIELD_STARTED); if (time > 0) { row.getCell(1).setCellValue(FastDateFormat .getDateTimeInstance(FastDateFormat.MEDIUM, FastDateFormat.MEDIUM).format(time)); row.getCell(1).setCellStyle(summaryDataStyle); } } row = sheet.createRow(rowCount++); { row.getCell(0).setCellValue("Finished:"); row.getCell(0).setCellStyle(headerStyle); Long time = (Long) testRunObj.get(FIELD_COMPLETED); if (time > 0) { row.getCell(1).setCellValue(FastDateFormat .getDateTimeInstance(FastDateFormat.MEDIUM, FastDateFormat.MEDIUM).format(time)); row.getCell(1).setCellStyle(summaryDataStyle); } } row = sheet.createRow(rowCount++); { row.getCell(0).setCellValue("Duration:"); row.getCell(0).setCellStyle(headerStyle); Long time = (Long) testRunObj.get(FIELD_DURATION); if (time > 0) { row.getCell(1).setCellValue(DurationFormatUtils.formatDurationHMS(time)); row.getCell(1).setCellStyle(summaryDataStyle); } } rowCount++; rowCount++; // Create a header row row = sheet.createRow(rowCount++); // Header row String[] headers = new String[] { "Event Name", "Total Count", "Success Count", "Failure Count", "Success Rate (%)", "Min (ms)", "Max (ms)", "Arithmetic Mean (ms)", "Standard Deviation (ms)" }; int columnCount = 0; for (String header : headers) { XSSFCell cell = row.getCell(columnCount++); cell.setCellStyle(headerStyle); cell.setCellValue(header); } // Grab results and output them columnCount = 0; TreeMap<String, ResultSummary> summaries = collateResults(true); for (Map.Entry<String, ResultSummary> entry : summaries.entrySet()) { // Reset column count columnCount = 0; row = sheet.createRow(rowCount++); String eventName = entry.getKey(); ResultSummary summary = entry.getValue(); SummaryStatistics statsSuccess = summary.getStats(true); SummaryStatistics statsFail = summary.getStats(false); // Event Name row.getCell(columnCount++).setCellValue(eventName); // Total Count row.getCell(columnCount++).setCellValue(summary.getTotalResults()); // Success Count row.getCell(columnCount++).setCellValue(statsSuccess.getN()); // Failure Count row.getCell(columnCount++).setCellValue(statsFail.getN()); // Success Rate (%) row.getCell(columnCount++).setCellValue(summary.getSuccessPercentage()); // Min (ms) row.getCell(columnCount++).setCellValue((long) statsSuccess.getMin()); // Max (ms) row.getCell(columnCount++).setCellValue((long) statsSuccess.getMax()); // Arithmetic Mean (ms) row.getCell(columnCount++).setCellValue((long) statsSuccess.getMean()); // Standard Deviation (ms) row.getCell(columnCount++).setCellValue((long) statsSuccess.getStandardDeviation()); } // Auto-size the columns for (int i = 0; i < 10; i++) { sheet.autoSizeColumn(i); } sheet.setColumnWidth(1, 5120); // Printing PrintSetup ps = sheet.getPrintSetup(); sheet.setAutobreaks(true); ps.setFitWidth((short) 1); ps.setLandscape(true); // Header and footer sheet.getHeader().setCenter(title); }
From source file:org.alfresco.bm.report.XLSXReporter.java
License:Open Source License
private void createPropertiesSheet(XSSFWorkbook workbook) throws IOException, NotFoundException { DBObject testRunObj;//from w ww . j av a2 s .c o m try { testRunObj = services.getTestDAO().getTestRun(test, run, true); } catch (ObjectNotFoundException e) { logger.error("Test run not found!", e); return; } // Ensure we don't leak passwords testRunObj = AbstractRestResource.maskValues(testRunObj); BasicDBList propertiesList = (BasicDBList) testRunObj.get(FIELD_PROPERTIES); if (propertiesList == null) { logger.error("Properties not found!"); return; } // Order the properties, nicely TreeMap<String, DBObject> properties = new TreeMap<String, DBObject>(); for (Object propertyObj : propertiesList) { DBObject property = (DBObject) propertyObj; String key = (String) property.get(FIELD_NAME); properties.put(key, property); } XSSFSheet sheet = workbook.createSheet("Properties"); // Create the fonts we need Font fontBold = workbook.createFont(); fontBold.setBoldweight(Font.BOLDWEIGHT_BOLD); // Create the styles we need XSSFCellStyle propertyStyle = sheet.getWorkbook().createCellStyle(); propertyStyle.setAlignment(HorizontalAlignment.RIGHT); propertyStyle.setWrapText(true); XSSFCellStyle headerStyle = sheet.getWorkbook().createCellStyle(); headerStyle.setAlignment(HorizontalAlignment.RIGHT); headerStyle.setFont(fontBold); XSSFRow row = null; int rowCount = 0; XSSFCell cell = null; int cellCount = 0; row = sheet.createRow(rowCount++); cell = row.createCell(cellCount++); { cell.setCellValue("Property"); cell.setCellStyle(headerStyle); } cell = row.createCell(cellCount++); { cell.setCellValue("Value"); cell.setCellStyle(headerStyle); } cell = row.createCell(cellCount++); { cell.setCellValue("Origin"); cell.setCellStyle(headerStyle); } cellCount = 0; // Iterate all the properties for the test run for (Map.Entry<String, DBObject> entry : properties.entrySet()) { DBObject property = entry.getValue(); String key = (String) property.get(FIELD_NAME); String value = (String) property.get(FIELD_VALUE); String origin = (String) property.get(FIELD_ORIGIN); row = sheet.createRow(rowCount++); cell = row.createCell(cellCount++); { cell.setCellValue(key); cell.setCellStyle(propertyStyle); } cell = row.createCell(cellCount++); { cell.setCellValue(value); cell.setCellStyle(propertyStyle); } cell = row.createCell(cellCount++); { cell.setCellValue(origin); cell.setCellStyle(propertyStyle); } // Back to first column cellCount = 0; } // Size the columns sheet.autoSizeColumn(0); sheet.setColumnWidth(1, 15360); sheet.autoSizeColumn(2); // Printing PrintSetup ps = sheet.getPrintSetup(); sheet.setAutobreaks(true); ps.setFitWidth((short) 1); ps.setLandscape(true); // Header and footer sheet.getHeader().setCenter(title); }