List of usage examples for org.apache.poi.ss.usermodel Workbook createCellStyle
CellStyle createCellStyle();
From source file:poi.xssf.usermodel.examples.CreateUserDefinedDataFormats.java
License:Apache License
public static void main(String[] args) throws Exception { Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook(); Sheet sheet = wb.createSheet("format sheet"); CellStyle style;//from w w w .ja v a2 s . com DataFormat format = wb.createDataFormat(); Row row; Cell cell; short rowNum = 0; short colNum = 0; row = sheet.createRow(rowNum++); cell = row.createCell(colNum); cell.setCellValue(11111.25); style = wb.createCellStyle(); style.setDataFormat(format.getFormat("0.0")); cell.setCellStyle(style); row = sheet.createRow(rowNum++); cell = row.createCell(colNum); cell.setCellValue(11111.25); style = wb.createCellStyle(); style.setDataFormat(format.getFormat("#,##0.0000")); cell.setCellStyle(style); FileOutputStream fileOut = new FileOutputStream("ooxml_dataFormat.xlsx"); wb.write(fileOut); fileOut.close(); }
From source file:poi.xssf.usermodel.examples.FillsAndColors.java
License:Apache License
public static void main(String[] args) throws Exception { Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook(); Sheet sheet = wb.createSheet("new sheet"); // Create a row and put some cells in it. Rows are 0 based. Row row = sheet.createRow((short) 1); // Aqua background CellStyle style = wb.createCellStyle(); style.setFillBackgroundColor(IndexedColors.AQUA.getIndex()); style.setFillPattern(CellStyle.BIG_SPOTS); Cell cell = row.createCell((short) 1); cell.setCellValue(new XSSFRichTextString("X")); cell.setCellStyle(style);/*from www . j a v a 2 s.c o m*/ // Orange "foreground", foreground being the fill foreground not the font color. style = wb.createCellStyle(); style.setFillForegroundColor(IndexedColors.ORANGE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row.createCell((short) 2); cell.setCellValue(new XSSFRichTextString("X")); cell.setCellStyle(style); // Write the output to a file FileOutputStream fileOut = new FileOutputStream("fill_colors.xlsx"); wb.write(fileOut); fileOut.close(); }
From source file:poi.xssf.usermodel.examples.WorkingWithFonts.java
License:Apache License
public static void main(String[] args) throws Exception { Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook(); Sheet sheet = wb.createSheet("Fonts"); Font font0 = wb.createFont(); font0.setColor(IndexedColors.BROWN.getIndex()); CellStyle style0 = wb.createCellStyle(); style0.setFont(font0);/*from ww w .ja va 2 s . co m*/ Font font1 = wb.createFont(); font1.setFontHeightInPoints((short) 14); font1.setFontName("Courier New"); font1.setColor(IndexedColors.RED.getIndex()); CellStyle style1 = wb.createCellStyle(); style1.setFont(font1); Font font2 = wb.createFont(); font2.setFontHeightInPoints((short) 16); font2.setFontName("Arial"); font2.setColor(IndexedColors.GREEN.getIndex()); CellStyle style2 = wb.createCellStyle(); style2.setFont(font2); Font font3 = wb.createFont(); font3.setFontHeightInPoints((short) 18); font3.setFontName("Times New Roman"); font3.setColor(IndexedColors.LAVENDER.getIndex()); CellStyle style3 = wb.createCellStyle(); style3.setFont(font3); Font font4 = wb.createFont(); font4.setFontHeightInPoints((short) 18); font4.setFontName("Wingdings"); font4.setColor(IndexedColors.GOLD.getIndex()); CellStyle style4 = wb.createCellStyle(); style4.setFont(font4); Font font5 = wb.createFont(); font5.setFontName("Symbol"); CellStyle style5 = wb.createCellStyle(); style5.setFont(font5); Cell cell0 = sheet.createRow(0).createCell(1); cell0.setCellValue("Default"); cell0.setCellStyle(style0); Cell cell1 = sheet.createRow(1).createCell(1); cell1.setCellValue("Courier"); cell1.setCellStyle(style1); Cell cell2 = sheet.createRow(2).createCell(1); cell2.setCellValue("Arial"); cell2.setCellStyle(style2); Cell cell3 = sheet.createRow(3).createCell(1); cell3.setCellValue("Times New Roman"); cell3.setCellStyle(style3); Cell cell4 = sheet.createRow(4).createCell(1); cell4.setCellValue("Wingdings"); cell4.setCellStyle(style4); Cell cell5 = sheet.createRow(5).createCell(1); cell5.setCellValue("Symbol"); cell5.setCellStyle(style5); // Write the output to a file FileOutputStream fileOut = new FileOutputStream("xssf-fonts.xlsx"); wb.write(fileOut); fileOut.close(); }
From source file:pt.webdetails.cda.exporter.CXlsExporter.java
License:Open Source License
public void export(final OutputStream out, final TableModel tableModel) throws ExporterException { // <Template file="testTemplate.xls"> // <RowOffset>3</RowOffset> // <ColumnOffset>2</ColumnOffset> // <WriteColumnNames>true</WriteColumnNames> // </Template> Workbook wb; InputStream inputStream = null; MetadataTableModel table = (MetadataTableModel) tableModel; Sheet sheet;/* ww w . java 2 s . c o m*/ int ignoreFirstXRows = 0; int rowOffset = 0; int columnOffset = 0; boolean writeColumns = true; boolean templateFound = false; String csvSeperator = ""; int numberOfHeaderRows = 0; if (templateSettings.keySet().size() > 0) { templateFound = true; try { //inputStream = new ClassPathResource(templateSettings.get("filename")).getInputStream(); inputStream = new FileInputStream(templatesDir + templateSettings.get("filename")); wb = new HSSFWorkbook(inputStream); sheet = wb.getSheetAt(0); if (templateSettings.containsKey("RowOffset")) { rowOffset = Integer.parseInt(templateSettings.get("RowOffset")); } if (templateSettings.containsKey("ColumnOffset")) { columnOffset = Integer.parseInt(templateSettings.get("ColumnOffset")); } if (templateSettings.containsKey("WriteColumnNames")) { writeColumns = Boolean.parseBoolean(templateSettings.get("WriteColumnNames")); } if (templateSettings.containsKey("CsvSeperator")) { csvSeperator = "\\" + templateSettings.get("CsvSeperator").toString(); } if (templateSettings.containsKey("WriteFirstXRowsAsHeader")) { numberOfHeaderRows = Integer.parseInt(templateSettings.get("WriteFirstXRowsAsHeader")); } } catch (Exception e) { throw new ExporterException("Error at loading TemplateFile", e); } } else { wb = new HSSFWorkbook(); sheet = wb.createSheet("Sheet1"); } DataFormat cf = wb.createDataFormat(); euroCellStyle = wb.createCellStyle(); euroCellStyle.setDataFormat(cf.getFormat("#,##0.00 \"\"")); doubleCellStyle = wb.createCellStyle(); doubleCellStyle.setDataFormat(cf.getFormat("0.00")); integerCellStyle = wb.createCellStyle(); integerCellStyle.setDataFormat(cf.getFormat("0")); percentCellStyle = wb.createCellStyle(); percentCellStyle.setDataFormat(cf.getFormat("0.00%")); dateCellStyle = wb.createCellStyle(); dateCellStyle.setDataFormat(cf.getFormat("dd.mm.yyyy")); datemonthCellStyle = wb.createCellStyle(); datemonthCellStyle.setDataFormat(cf.getFormat("mm.yyyy")); dateyearCellStyle = wb.createCellStyle(); dateyearCellStyle.setDataFormat(cf.getFormat("yyyy")); dateAndTimeCellStyle = wb.createCellStyle(); dateAndTimeCellStyle.setDataFormat(cf.getFormat("dd.mm.yyyy hh:mm:ss")); boolean interpretCsv = !csvSeperator.equals(""); if (writeColumns) { CellStyle headerCellStyle = null; if (templateFound) headerCellStyle = sheet.getRow(rowOffset).getCell(columnOffset).getCellStyle(); if (numberOfHeaderRows > 0) { ignoreFirstXRows = numberOfHeaderRows; for (int i = 0; i < numberOfHeaderRows; i++) { String[] seperatedRow = new String[0]; int colCount = table.getColumnCount(); if (interpretCsv) { seperatedRow = table.getValueAt(i, 0).toString().split(csvSeperator, -1); colCount = seperatedRow.length; } Row header = sheet.createRow(rowOffset); for (int col = 0; col < colCount; col++) { Cell cell = header.createCell(col + columnOffset); if (templateFound) cell.setCellStyle(headerCellStyle); if (interpretCsv) { cell.setCellValue(seperatedRow[col]); } else { cell.setCellValue(table.getColumnName(col)); } } rowOffset++; } } else { Row header = sheet.createRow(rowOffset); for (int col = 0; col < table.getColumnCount(); col++) { Cell cell = header.createCell(col + columnOffset); if (templateFound) cell.setCellStyle(headerCellStyle); cell.setCellValue(table.getColumnName(col)); } rowOffset++; } sheet.createFreezePane(0, rowOffset); } for (int r = ignoreFirstXRows; r < table.getRowCount(); r++) { CellStyle rowCellStyle = null; // if(templateFound) // try{ // rowCellStyle = sheet.getRow(rowOffset).getCell(columnOffset).getCellStyle(); // }catch (Exception e){} // // int rows = table.getRowCount(); // // Row r1 = sheet.getRow(rowOffset); // // int cols = r1.getLastCellNum(); // // Cell c1 = r1.getCell(columnOffset); Row row = sheet.getRow(r + rowOffset - ignoreFirstXRows); if (row == null) { row = sheet.createRow(r + rowOffset - ignoreFirstXRows); } int colCount; String[] seperatedRow = new String[0]; if (interpretCsv) { seperatedRow = table.getValueAt(r, 0).toString().split(csvSeperator); colCount = seperatedRow.length; } else { colCount = table.getColumnCount(); } for (int col = 0; col < colCount; col++) { Cell cell = null; if (templateFound) { cell = row.getCell(col + columnOffset); if (cell == null) { cell = row.createCell(col + columnOffset); } try { rowCellStyle = sheet.getRow(rowOffset).getCell(col + columnOffset).getCellStyle(); cell.setCellStyle(rowCellStyle); } catch (Exception e) { } } else { cell = row.createCell(col + columnOffset); } if (!interpretCsv) { try { setConvertedValue(cell, table.getValueAt(r, col), col, table); } catch (Exception e) { setConvertedValue(cell, Cell.CELL_TYPE_ERROR, col, table); } } else { setConvertedValue(cell, seperatedRow[col], col, table); } } } try { wb.write(out); } catch (IOException e) { throw new ExporterException("IO Exception converting to utf-8", e); } finally { if (templateSettings.keySet().size() > 0) { try { inputStream.close(); } catch (Exception e) { throw new ExporterException("Error at closing TemplateFile", e); } } } }
From source file:ro.dabuno.office.integration.BusinessPlan.java
License:Apache License
private static CellStyle createBorderedStyle(Workbook wb) { BorderStyle thin = BorderStyle.THIN; short black = IndexedColors.BLACK.getIndex(); CellStyle style = wb.createCellStyle(); style.setBorderRight(thin);//from ww w.j a v a2s . c om style.setRightBorderColor(black); style.setBorderBottom(thin); style.setBottomBorderColor(black); style.setBorderLeft(thin); style.setLeftBorderColor(black); style.setBorderTop(thin); style.setTopBorderColor(black); return style; }
From source file:ro.dabuno.office.integration.LoadCalculator.java
/** * cell styles used for formatting calendar sheets *///from w w w. j a v a2s .co m private static Map<String, CellStyle> createStyles(Workbook wb) { Map<String, CellStyle> styles = new HashMap<String, CellStyle>(); CellStyle style; Font titleFont = wb.createFont(); titleFont.setFontHeightInPoints((short) 14); titleFont.setFontName("Trebuchet MS"); style = wb.createCellStyle(); style.setFont(titleFont); style.setBorderBottom(BorderStyle.DOTTED); style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex()); styles.put("title", style); Font itemFont = wb.createFont(); itemFont.setFontHeightInPoints((short) 9); itemFont.setFontName("Trebuchet MS"); style = wb.createCellStyle(); style.setAlignment(HorizontalAlignment.LEFT); style.setFont(itemFont); styles.put("item_left", style); style = wb.createCellStyle(); style.setAlignment(HorizontalAlignment.RIGHT); style.setFont(itemFont); styles.put("item_right", style); style = wb.createCellStyle(); style.setAlignment(HorizontalAlignment.RIGHT); style.setFont(itemFont); style.setBorderRight(BorderStyle.DOTTED); style.setRightBorderColor(IndexedColors.GREY_40_PERCENT.getIndex()); style.setBorderBottom(BorderStyle.DOTTED); style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex()); style.setBorderLeft(BorderStyle.DOTTED); style.setLeftBorderColor(IndexedColors.GREY_40_PERCENT.getIndex()); style.setBorderTop(BorderStyle.DOTTED); style.setTopBorderColor(IndexedColors.GREY_40_PERCENT.getIndex()); style.setDataFormat( wb.createDataFormat().getFormat("_($* #,##0.00_);_($* (#,##0.00);_($* \"-\"??_);_(@_)")); styles.put("input_$", style); style = wb.createCellStyle(); style.setAlignment(HorizontalAlignment.RIGHT); style.setFont(itemFont); style.setBorderRight(BorderStyle.DOTTED); style.setRightBorderColor(IndexedColors.GREY_40_PERCENT.getIndex()); style.setBorderBottom(BorderStyle.DOTTED); style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex()); style.setBorderLeft(BorderStyle.DOTTED); style.setLeftBorderColor(IndexedColors.GREY_40_PERCENT.getIndex()); style.setBorderTop(BorderStyle.DOTTED); style.setTopBorderColor(IndexedColors.GREY_40_PERCENT.getIndex()); style.setDataFormat(wb.createDataFormat().getFormat("0.000%")); styles.put("input_%", style); style = wb.createCellStyle(); style.setAlignment(HorizontalAlignment.RIGHT); style.setFont(itemFont); style.setBorderRight(BorderStyle.DOTTED); style.setRightBorderColor(IndexedColors.GREY_40_PERCENT.getIndex()); style.setBorderBottom(BorderStyle.DOTTED); style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex()); style.setBorderLeft(BorderStyle.DOTTED); style.setLeftBorderColor(IndexedColors.GREY_40_PERCENT.getIndex()); style.setBorderTop(BorderStyle.DOTTED); style.setTopBorderColor(IndexedColors.GREY_40_PERCENT.getIndex()); style.setDataFormat(wb.createDataFormat().getFormat("0")); styles.put("input_i", style); style = wb.createCellStyle(); style.setAlignment(HorizontalAlignment.CENTER); style.setFont(itemFont); style.setDataFormat(wb.createDataFormat().getFormat("m/d/yy")); styles.put("input_d", style); style = wb.createCellStyle(); style.setAlignment(HorizontalAlignment.RIGHT); style.setFont(itemFont); style.setBorderRight(BorderStyle.DOTTED); style.setRightBorderColor(IndexedColors.GREY_40_PERCENT.getIndex()); style.setBorderBottom(BorderStyle.DOTTED); style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex()); style.setBorderLeft(BorderStyle.DOTTED); style.setLeftBorderColor(IndexedColors.GREY_40_PERCENT.getIndex()); style.setBorderTop(BorderStyle.DOTTED); style.setTopBorderColor(IndexedColors.GREY_40_PERCENT.getIndex()); style.setDataFormat(wb.createDataFormat().getFormat("$##,##0.00")); style.setBorderBottom(BorderStyle.DOTTED); style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex()); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); styles.put("formula_$", style); style = wb.createCellStyle(); style.setAlignment(HorizontalAlignment.RIGHT); style.setFont(itemFont); style.setBorderRight(BorderStyle.DOTTED); style.setRightBorderColor(IndexedColors.GREY_40_PERCENT.getIndex()); style.setBorderBottom(BorderStyle.DOTTED); style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex()); style.setBorderLeft(BorderStyle.DOTTED); style.setLeftBorderColor(IndexedColors.GREY_40_PERCENT.getIndex()); style.setBorderTop(BorderStyle.DOTTED); style.setTopBorderColor(IndexedColors.GREY_40_PERCENT.getIndex()); style.setDataFormat(wb.createDataFormat().getFormat("0")); style.setBorderBottom(BorderStyle.DOTTED); style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex()); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); styles.put("formula_i", style); return styles; }
From source file:ro.ldir.report.formatter.GarbageExcelFormatter.java
License:Open Source License
public final Workbook convert(Workbook wb) { Sheet sheet = wb.createSheet("Lista Mormane gunoi"); Row row = sheet.createRow(0);/*from w w w. j a va 2 s . co m*/ int k = 0; row.createCell(k).setCellValue("ID"); k++; row.createCell(k).setCellValue("Jude\u0163"); k++; row.createCell(k).setCellValue("Comun\u04d1"); k++; row.createCell(k).setCellValue("Latitudine"); k++; row.createCell(k).setCellValue("Longitudine"); k++; row.createCell(k).setCellValue("Precizie GPS (metri)"); k++; row.createCell(k).setCellValue("Dispersat"); k++; row.createCell(k).setCellValue("Num\u04d1r saci"); k++; row.createCell(k).setCellValue("Marime TrashOut (1=mic;2=medium;3=mare)"); k++; row.createCell(k).setCellValue("Compozitie TrashOut"); k++; row.createCell(k).setCellValue("Plastic"); k++; row.createCell(k).setCellValue("Metal"); k++; row.createCell(k).setCellValue("Sticl\u04d1"); k++; row.createCell(k).setCellValue("Nereciclabil"); k++; row.createCell(k).setCellValue("Greu de transportat"); k++; row.createCell(k).setCellValue("Descriere"); k++; row.createCell(k).setCellValue("Stare"); k++; row.createCell(k).setCellValue("Zon\u04d1 cartare"); k++; row.createCell(k).setCellValue("Numele mormanului"); k++; row.createCell(k).setCellValue("Raza"); k++; row.createCell(k).setCellValue("Numar de voturi"); k++; row.createCell(k).setCellValue("Data introducerii"); k++; row.createCell(k).setCellValue("Nominalizat pentru Votare"); k++; row.createCell(k).setCellValue("Nominalizat pentru Curatare"); k++; for (int i = 0; i < garbages.size(); i++) { k = 0; row = sheet.createRow(i + 1); Garbage garbage = garbages.get(i); row.createCell(k, Cell.CELL_TYPE_NUMERIC).setCellValue(garbage.getGarbageId()); k++; row.createCell(k).setCellValue(garbage.getCounty().getName()); k++; if (garbage.getTown() != null) row.createCell(k).setCellValue(garbage.getTown().getName()); k++; row.createCell(k, Cell.CELL_TYPE_NUMERIC).setCellValue(garbage.getY()); k++; row.createCell(k, Cell.CELL_TYPE_NUMERIC).setCellValue(garbage.getX()); k++; row.createCell(k, Cell.CELL_TYPE_NUMERIC).setCellValue(garbage.getAccuracy()); k++; row.createCell(k, Cell.CELL_TYPE_BOOLEAN).setCellValue(garbage.isDispersed()); k++; row.createCell(k, Cell.CELL_TYPE_NUMERIC).setCellValue(garbage.getBagCount()); k++; row.createCell(k, Cell.CELL_TYPE_NUMERIC).setCellValue(garbage.getTrashOutSize()); k++; if (garbage.getTrashOutTypes() != null) row.createCell(k, Cell.CELL_TYPE_STRING).setCellValue(garbage.getTrashOutTypes()); k++; row.createCell(k, Cell.CELL_TYPE_NUMERIC).setCellValue(garbage.getPercentagePlastic()); k++; row.createCell(k, Cell.CELL_TYPE_NUMERIC).setCellValue(garbage.getPercentageMetal()); k++; row.createCell(k, Cell.CELL_TYPE_NUMERIC).setCellValue(garbage.getPercentageGlass()); k++; row.createCell(k, Cell.CELL_TYPE_NUMERIC).setCellValue(garbage.getPercentageWaste()); k++; row.createCell(k).setCellValue(garbage.getBigComponentsDescription()); k++; if (garbage.getDescription() != null) row.createCell(k, Cell.CELL_TYPE_STRING) .setCellValue(garbage.getDescription().replaceAll("\\r\\n|\\r|\\n", " ")); k++; if (garbage.getStatus() != null) row.createCell(k).setCellValue(garbage.getStatus().getTranslation()); k++; if (garbage.getChartedArea() != null) row.createCell(k).setCellValue(garbage.getChartedArea().getName()); k++; try { if (garbage.getName() != null) row.createCell(k).setCellValue(garbage.getName()); } catch (Exception e) { // TODO: handle exception } k++; try { row.createCell(k, Cell.CELL_TYPE_NUMERIC).setCellValue(garbage.getRadius()); } catch (Exception e1) { // TODO: handle exception } k++; try { if (garbage.getVotes() != null) row.createCell(k, Cell.CELL_TYPE_NUMERIC).setCellValue(garbage.getVoteCount()); } catch (Exception ee) { } k++; try { Cell cell; DataFormat df = wb.createDataFormat(); CellStyle cs = wb.createCellStyle(); cs.setDataFormat(df.getFormat("dd-mm-yyyy")); if (garbage.getRecordDate() != null) { cell = row.createCell(k, Cell.CELL_TYPE_STRING); cell.setCellValue(garbage.getRecordDate()); cell.setCellStyle(cs); } } catch (Exception ee) { } k++; row.createCell(k, Cell.CELL_TYPE_STRING).setCellValue(garbage.isToVote()); k++; row.createCell(k, Cell.CELL_TYPE_STRING).setCellValue(garbage.isToClean()); k++; } return wb; }
From source file:ro.ldir.report.formatter.TeamExcelFormatter.java
License:Open Source License
public final Workbook convert(Workbook wb) { Sheet sheet = wb.createSheet("Liste echipe"); Row row = sheet.createRow(0);/*from w ww . j a v a 2 s. c o m*/ row.createCell(0).setCellValue("ID"); row.createCell(1).setCellValue("Email manager"); row.createCell(2).setCellValue("Nume manager"); row.createCell(3).setCellValue("Comun\u04d1 manager"); row.createCell(4).setCellValue("Jude\u0163 manager"); row.createCell(5).setCellValue("Cod acces"); row.createCell(6).setCellValue("Nume"); row.createCell(7).setCellValue("Num\u04d1r membri"); row.createCell(8).setCellValue("Multi-manager"); row.createCell(9).setCellValue("Nume organiza\u0163ie"); row.createCell(10).setCellValue("Comun\u04d1 organiza\u0163ie"); row.createCell(11).setCellValue("Jude\u0163 organiza\u0163ie"); row.createCell(12).setCellValue("Tip organiza\u0163ie"); row.createCell(13).setCellValue("Nume persoan\u04d1 de contact"); row.createCell(14).setCellValue("Email persoan\u04d1 de contact"); row.createCell(15).setCellValue("Num\u04d1r membri organiza\u0163ie"); row.createCell(16).setCellValue("Num\u04d1r GPS"); row.createCell(17).setCellValue("Transport"); row.createCell(18).setCellValue("Num\u04d1r saci"); row.createCell(19).setCellValue("Num\u04d1r m\u04d1nu\015Fi"); row.createCell(20).setCellValue("Num\u04d1r lope\u0163i"); row.createCell(21).setCellValue("Utilaje"); row.createCell(22).setCellValue("Num\u04d1r mormane alocate"); row.createCell(23).setCellValue("List\u04d1 mormane alocate"); row.createCell(24).setCellValue("Sum\u04d1 volum mormane alocate"); row.createCell(25).setCellValue("Activitati"); row.createCell(26).setCellValue("Data inregistrarii"); int i = 0; CreationHelper createHelper = wb.getCreationHelper(); for (Team team : teams) { if (team.getOrganizationMembers() == null || team.getOrganizationMembers().size() == 0) { i++; row = sheet.createRow(i); teamHeader(row, team); teamFooter(row, team); continue; } for (Organization org : team.getOrganizationMembers()) { i++; row = sheet.createRow(i); teamHeader(row, team); organization(row, org); teamFooter(row, team); } if (team.getTeamManager() != null) { StringBuffer ab = new StringBuffer(); List<User.Activity> activities = team.getTeamManager().getActivities(); if (activities != null && activities.size() > 0) { for (User.Activity activity : activities) if (activity != null) if (activity.getReportName() != null) ab.append(activity.getReportName() + ", "); else ab.append(" " + ", "); if (ab.length() > 1) row.createCell(25).setCellValue(ab.substring(0, ab.length() - 2)); else row.createCell(25).setCellValue(" "); } if (team.getTeamManager().getRecordDate() != null) { CellStyle cellStyle = wb.createCellStyle(); cellStyle.setDataFormat(createHelper.createDataFormat().getFormat("m/d/yy h:mm")); Cell dateCell = row.createCell(26); dateCell.setCellValue(team.getTeamManager().getRecordDate()); dateCell.setCellStyle(cellStyle); } } } return wb; }
From source file:ro.ldir.report.formatter.UserExcelFormatter.java
License:Open Source License
public final Workbook convert(Workbook wb) { Sheet sheet = wb.createSheet("Utilizatori"); CreationHelper createHelper = wb.getCreationHelper(); teams = new ArrayList<Team>(); Row row = sheet.createRow(0);/*from w w w . ja v a 2s .c o m*/ row.createCell(0).setCellValue("Prenume"); row.createCell(1).setCellValue("Nume"); row.createCell(2).setCellValue("Email"); row.createCell(3).setCellValue("Telefon"); row.createCell(4).setCellValue("Rol"); row.createCell(5).setCellValue("Jude\u0163"); row.createCell(6).setCellValue("Oras"); row.createCell(7).setCellValue("Data \u00eenregistr\u04d1rii"); row.createCell(8).setCellValue("ID"); row.createCell(9).setCellValue("Nr. mormane"); row.createCell(10).setCellValue("Nr. zone"); row.createCell(11).setCellValue("Activitate"); for (int i = 0; i < users.size(); i++) { row = sheet.createRow(i + 1); User user = users.get(i); if (user == null) continue; row.createCell(0).setCellValue(user.getFirstName()); row.createCell(1).setCellValue(user.getLastName()); row.createCell(2).setCellValue(user.getEmail()); row.createCell(3).setCellValue(user.getPhone()); row.createCell(4).setCellValue(user.getRole()); row.createCell(5).setCellValue(user.getCounty()); row.createCell(6).setCellValue(user.getTown()); if (user.getRecordDate() != null) { CellStyle cellStyle = wb.createCellStyle(); cellStyle.setDataFormat(createHelper.createDataFormat().getFormat("m/d/yy h:mm")); Cell dateCell = row.createCell(7); dateCell.setCellValue(user.getRecordDate()); dateCell.setCellStyle(cellStyle); } row.createCell(8, Cell.CELL_TYPE_NUMERIC).setCellValue(user.getUserId()); if (user.getGarbages() == null) row.createCell(9, Cell.CELL_TYPE_NUMERIC).setCellValue(0); else row.createCell(9, Cell.CELL_TYPE_NUMERIC).setCellValue(user.getGarbages().size()); if (user.getMemberOf() == null || user.getMemberOf().getChartedAreas() == null) row.createCell(10, Cell.CELL_TYPE_NUMERIC).setCellValue(0); else row.createCell(10, Cell.CELL_TYPE_NUMERIC) .setCellValue(user.getMemberOf().getChartedAreas().size()); StringBuffer ab = new StringBuffer(); List<User.Activity> activities = user.getActivities(); if (activities != null && activities.size() > 0) { for (User.Activity activity : activities) if (activity != null) if (activity.getReportName() != null) ab.append(activity.getReportName() + ", "); else ab.append(" " + ", "); if (ab.length() > 1) row.createCell(11).setCellValue(ab.substring(0, ab.length() - 2)); else row.createCell(11).setCellValue(" "); } List<Team> managedTeams = user.getManagedTeams(); if (managedTeams != null && managedTeams.size() > 0) { for (Team team : managedTeams) teams.add(team); } } TeamExcelFormatter teamWb = new TeamExcelFormatter(teams); wb = teamWb.convert(wb); return wb; }
From source file:rpt.GUI.ProgramStrategist.CyclePlans.CompareDialogController.java
private void writeHeaders(Workbook wb, Row row, Boolean addOldSOP) { Cell cell = row.createCell(0);// w w w.j av a 2s.c om XSSFCellStyle style = (XSSFCellStyle) wb.createCellStyle(); Font headerFont = wb.createFont(); headerFont.setBold(true); style.setFillForegroundColor(new XSSFColor(new java.awt.Color(220, 220, 220))); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); style.setFont(headerFont); cell.setCellStyle(style); cell.setCellValue("Plant"); cell = row.createCell(1); cell.setCellStyle(style); cell.setCellValue("Platform"); cell = row.createCell(2); cell.setCellStyle(style); cell.setCellValue("Vehicle"); cell = row.createCell(3); cell.setCellStyle(style); cell.setCellValue("Propulsion"); cell = row.createCell(4); cell.setCellStyle(style); cell.setCellValue("Denomination"); cell = row.createCell(5); cell.setCellStyle(style); cell.setCellValue("Fuel"); cell = row.createCell(6); cell.setCellStyle(style); cell.setCellValue("Engine Family"); cell = row.createCell(7); cell.setCellStyle(style); cell.setCellValue("Generation"); cell = row.createCell(8); cell.setCellStyle(style); cell.setCellValue("Engine Code"); cell = row.createCell(9); cell.setCellStyle(style); cell.setCellValue("Displacement"); cell = row.createCell(10); cell.setCellStyle(style); cell.setCellValue("Engine power (PS)"); cell = row.createCell(11); cell.setCellStyle(style); cell.setCellValue("Electric motor power (PS)"); cell = row.createCell(12); cell.setCellStyle(style); cell.setCellValue("Torque"); cell = row.createCell(13); cell.setCellStyle(style); cell.setCellValue("Torque overboost"); cell = row.createCell(14); cell.setCellStyle(style); cell.setCellValue("Gearbox Type"); cell = row.createCell(15); cell.setCellStyle(style); cell.setCellValue("Gears"); cell = row.createCell(16); cell.setCellStyle(style); cell.setCellValue("Gearbox"); cell = row.createCell(17); cell.setCellStyle(style); cell.setCellValue("Driveline"); cell = row.createCell(18); cell.setCellStyle(style); cell.setCellValue("Transmission Code"); cell = row.createCell(19); cell.setCellStyle(style); cell.setCellValue("Cert Group"); cell = row.createCell(20); cell.setCellStyle(style); cell.setCellValue("Emission Class"); cell = row.createCell(21); cell.setCellStyle(style); cell.setCellValue("SOP"); cell = row.createCell(22); cell.setCellStyle(style); cell.setCellValue("EOP"); if (addOldSOP) { cell = row.createCell(23); cell.setCellStyle(style); cell.setCellValue("Old SOP"); } if (addOldSOP) { //Same boolean flag cell = row.createCell(24); cell.setCellStyle(style); cell.setCellValue("Old EOP"); } }