List of usage examples for org.apache.poi.ss.usermodel Cell setCellStyle
void setCellStyle(CellStyle style);
Set the style for the cell.
From source file:com.jshuabo.reportcenter.server.service.automoblie.impl.DefaultBranchLineCarInfoServiceImpl.java
License:Open Source License
@Override public void importToExcel(Map<String, Object> exprotMap, HttpServletResponse response, HttpServletRequest request, String[] title, String excelName) { User user = SecurityContextHolder.getCurrentUser(); if (StringUtils.isEmpty(exprotMap.get("subStation"))) { exprotMap.put("subStation", user.getId()); }//from ww w. jav a 2 s . c o m Map<String, Object> pageData = carInfoMapper.exprotPageData(exprotMap); SXSSFWorkbook workbook = new SXSSFWorkbook(1000); // keep 100 rows in memory, exceeding rows int flag = 1; // int rowCount = 150000; // ?sheet long count = (Long) pageData.get("COUNT"); long pageSize = rowCount; // ?? long page = 1; if (rowCount < count) { if (count % pageSize == 0) { } else { page = count / pageSize + 1; } // } Sheet sh = workbook.createSheet(excelName + System.currentTimeMillis()); Row row = sh.createRow((short) 0); // Cell cell = null; CellStyle[] cs = POIUtils.cellStyle(workbook); POIUtils.createHeard(sh, row, cell, cs, title); for (int i = 1; i <= page; i++) { long offset = (i - 1) * pageSize; long rows = pageSize; exprotMap.put("offset", Long.valueOf(offset)); exprotMap.put("rows", Long.valueOf(rows)); // ?? List<BranchLineCarInfo> autoRecordDataList = carInfoMapper.exprot2Excel(exprotMap); if (autoRecordDataList.isEmpty()) continue; for (int rownum = 0; rownum < autoRecordDataList.size(); rownum++) { BranchLineCarInfo branchLineCarInfo = autoRecordDataList.get(rownum); String subStation = branchLineCarInfo.getExtendProp3(); String licenseDate = DateFormatUtils.format(branchLineCarInfo.getLicenseDate(), DateFormatUtils.ymd); String inspectionDate = DateFormatUtils.format(branchLineCarInfo.getInspectionDate(), DateFormatUtils.ymd); String insuranceDate = DateFormatUtils.format(branchLineCarInfo.getTlInsuranceDate(), DateFormatUtils.ymd); String changeDate = DateFormatUtils.format(branchLineCarInfo.getChangeDate(), DateFormatUtils.ymd); String strongInsDate = DateFormatUtils.format(branchLineCarInfo.getStrongInsdate(), DateFormatUtils.ymd); String agreeDate = DateFormatUtils.format(branchLineCarInfo.getAgreeDate(), DateFormatUtils.ymd); // ? ?sheet if (flag > pageSize) { flag = 1; sh = workbook.createSheet(excelName + System.currentTimeMillis()); row = sh.createRow((short) 0); POIUtils.createHeard(sh, row, cell, cs, title); } row = sh.createRow(flag); for (int cellnum = 0; cellnum < title.length; cellnum++) { cell = row.createCell(0); cell.setCellValue(subStation); cell.setCellStyle(cs[1]); cell = row.createCell(1); cell.setCellValue(branchLineCarInfo.getDeputyCard()); cell.setCellStyle(cs[1]); cell = row.createCell(2); cell.setCellValue(branchLineCarInfo.getCarKind()); cell.setCellStyle(cs[1]); cell = row.createCell(3); cell.setCellValue(branchLineCarInfo.getLicenseNo()); cell.setCellStyle(cs[1]); cell = row.createCell(4); cell.setCellValue(branchLineCarInfo.getLicense()); cell.setCellStyle(cs[1]); cell = row.createCell(5); cell.setCellValue(licenseDate); cell.setCellStyle(cs[1]); cell = row.createCell(6); cell.setCellValue(branchLineCarInfo.getLicenseName()); cell.setCellStyle(cs[1]); cell = row.createCell(7); cell.setCellValue(inspectionDate); cell.setCellStyle(cs[1]); cell = row.createCell(8); cell.setCellValue(branchLineCarInfo.getName()); cell.setCellStyle(cs[1]); cell = row.createCell(9); cell.setCellValue(branchLineCarInfo.getIdCard()); cell.setCellStyle(cs[1]); cell = row.createCell(10); cell.setCellValue(String.valueOf(branchLineCarInfo.getFtReceive())); cell.setCellStyle(cs[1]); cell = row.createCell(11); cell.setCellValue(changeDate); cell.setCellStyle(cs[1]); cell = row.createCell(12); cell.setCellValue(branchLineCarInfo.getTelephone()); cell.setCellStyle(cs[1]); cell = row.createCell(13); cell.setCellValue(strongInsDate); cell.setCellStyle(cs[1]); cell = row.createCell(14); cell.setCellValue(StringUtils.isEmpty(branchLineCarInfo.getTlInsurance()) ? 0D : branchLineCarInfo.getTlInsurance()); cell.setCellStyle(cs[1]); cell = row.createCell(15); cell.setCellValue(insuranceDate); cell.setCellStyle(cs[1]); cell = row.createCell(16); cell.setCellValue(branchLineCarInfo.getPoliceProve()); cell.setCellStyle(cs[1]); cell = row.createCell(17); cell.setCellValue(branchLineCarInfo.getHouseholdCopy()); cell.setCellStyle(cs[1]); cell = row.createCell(18); cell.setCellValue(branchLineCarInfo.getIdcardCopy()); cell.setCellStyle(cs[1]); cell = row.createCell(19); cell.setCellValue(branchLineCarInfo.getLicenseCopy()); cell.setCellStyle(cs[1]); cell = row.createCell(20); cell.setCellValue(branchLineCarInfo.getGuaranRespon()); cell.setCellStyle(cs[1]); cell = row.createCell(21); cell.setCellValue(branchLineCarInfo.getGuaranIncome()); cell.setCellStyle(cs[1]); cell = row.createCell(22); cell.setCellValue(branchLineCarInfo.getGuaranhouseCopy()); cell.setCellStyle(cs[1]); cell = row.createCell(23); cell.setCellValue(branchLineCarInfo.getGuaranidCopy()); cell.setCellStyle(cs[1]); cell = row.createCell(24); cell.setCellValue(branchLineCarInfo.getDrilicenseCopy()); cell.setCellStyle(cs[1]); cell = row.createCell(25); cell.setCellValue(branchLineCarInfo.getStronginsCopy()); cell.setCellStyle(cs[1]); cell = row.createCell(26); cell.setCellValue(branchLineCarInfo.getCommerinsuCopy()); cell.setCellStyle(cs[1]); cell = row.createCell(27); cell.setCellValue(branchLineCarInfo.getCertificate()); cell.setCellStyle(cs[1]); cell = row.createCell(28); cell.setCellValue(agreeDate); cell.setCellStyle(cs[1]); cell = row.createCell(29); cell.setCellValue(branchLineCarInfo.getRentalAgreement()); cell.setCellStyle(cs[1]); cell = row.createCell(30); cell.setCellValue(branchLineCarInfo.getStronginsPrompt()); cell.setCellStyle(cs[1]); cell = row.createCell(31); cell.setCellValue(branchLineCarInfo.getTlinsurancePrompt()); cell.setCellStyle(cs[1]); cell = row.createCell(32); cell.setCellValue(branchLineCarInfo.getInspectionPrompt()); cell.setCellStyle(cs[1]); cell = row.createCell(33); cell.setCellValue(branchLineCarInfo.getChangePrompt()); cell.setCellStyle(cs[1]); cell = row.createCell(34); cell.setCellValue(branchLineCarInfo.getStatus()); cell.setCellStyle(cs[1]); } flag++; } } POIUtils.exprot(workbook, response, excelName); }
From source file:com.jshuabo.reportcenter.server.service.automoblie.impl.DefaultBranchLineDrawoutRecordServiceImpl.java
@Override public void importToExcel(Map<String, Object> exprotMap, HttpServletResponse response, HttpServletRequest request, String[] title, String excelName) { User user = SecurityContextHolder.getCurrentUser(); if (StringUtils.isEmpty(exprotMap.get("subStation"))) { exprotMap.put("subStation", user.getId()); }//from w w w. j a v a 2s . co m Map<String, Object> pageData = drawoutRecordDataMapper.exprotPageData(exprotMap); SXSSFWorkbook workbook = new SXSSFWorkbook(1000); // keep 100 rows in memory, exceeding rows int flag = 1; // int rowCount = 150000; // ?sheet long count = (Long) pageData.get("COUNT"); long pageSize = rowCount; // ?? long page = 1; if (rowCount < count) { if (count % pageSize == 0) { } else { page = count / pageSize + 1; } // } Sheet sh = workbook.createSheet(excelName + System.currentTimeMillis()); Row row = sh.createRow((short) 0); // Cell cell = null; CellStyle[] cs = POIUtils.cellStyle(workbook); POIUtils.createHeard(sh, row, cell, cs, title); for (int i = 1; i <= page; i++) { long offset = (i - 1) * pageSize; long rows = pageSize; exprotMap.put("offset", Long.valueOf(offset)); exprotMap.put("rows", Long.valueOf(rows)); // ?? List<BranchLineDrawoutRecord> drawoutRecordDataList = drawoutRecordDataMapper.exprot2Excel(exprotMap); if (drawoutRecordDataList.isEmpty()) continue; for (int rownum = 0; rownum < drawoutRecordDataList.size(); rownum++) { BranchLineDrawoutRecord bdr = drawoutRecordDataList.get(rownum); String data = DateFormatUtils.format(bdr.getDate(), DateFormatUtils.ymd); String subStation = bdr.getExtendProp3(); // ? ?sheet if (flag > pageSize) { flag = 1; sh = workbook.createSheet(excelName + System.currentTimeMillis()); row = sh.createRow((short) 0); POIUtils.createHeard(sh, row, cell, cs, title); } row = sh.createRow(flag); for (int cellnum = 0; cellnum < title.length; cellnum++) { cell = row.createCell(0); cell.setCellValue(subStation); cell.setCellStyle(cs[1]); cell = row.createCell(1); cell.setCellValue(data); cell.setCellStyle(cs[1]); cell = row.createCell(2); cell.setCellValue(bdr.getLicenseNo()); cell.setCellStyle(cs[1]); cell = row.createCell(3); cell.setCellValue(bdr.getDriver()); cell.setCellStyle(cs[1]); cell = row.createCell(4); cell.setCellValue(bdr.getLine()); cell.setCellStyle(cs[1]); cell = row.createCell(5); cell.setCellValue(bdr.getGpsNo()); cell.setCellStyle(cs[1]); cell = row.createCell(6); cell.setCellValue(bdr.getStartTime()); cell.setCellStyle(cs[1]); cell = row.createCell(7); cell.setCellValue(bdr.getStartMileage()); cell.setCellStyle(cs[1]); cell = row.createCell(8); cell.setCellValue(bdr.getStopTime()); cell.setCellStyle(cs[1]); cell = row.createCell(9); cell.setCellValue(bdr.getStopMileage()); cell.setCellStyle(cs[1]); cell = row.createCell(10); cell.setCellValue(bdr.getMileage()); cell.setCellStyle(cs[1]); cell = row.createCell(11); String temp = bdr.getExtendProp2(); cell.setCellValue(StringUtils.isEmpty(temp) ? 0D : Double.valueOf(temp)); cell.setCellStyle(cs[1]); cell = row.createCell(12); cell.setCellValue(bdr.getTicketQuantity()); cell.setCellStyle(cs[1]); cell = row.createCell(13); cell.setCellValue(bdr.getHallQuantity()); cell.setCellStyle(cs[1]); cell = row.createCell(14); cell.setCellValue(bdr.getPieQuantity()); cell.setCellStyle(cs[1]); cell = row.createCell(15); cell.setCellValue(bdr.getPcsQuantity()); cell.setCellStyle(cs[1]); cell = row.createCell(16); cell.setCellValue(bdr.getFuelPrice()); cell.setCellStyle(cs[1]); cell = row.createCell(17); cell.setCellValue(bdr.getFuelCosts()); cell.setCellStyle(cs[1]); cell = row.createCell(18); cell.setCellValue(bdr.getDay()); cell.setCellStyle(cs[1]); cell = row.createCell(19); cell.setCellValue(bdr.getRentalFee()); cell.setCellStyle(cs[1]); cell = row.createCell(20); cell.setCellValue(bdr.getParkingFee()); cell.setCellStyle(cs[1]); cell = row.createCell(21); cell.setCellValue(bdr.getAward()); cell.setCellStyle(cs[1]); cell = row.createCell(22); cell.setCellValue(bdr.getIsReim()); cell.setCellStyle(cs[1]); cell = row.createCell(23); cell.setCellValue(bdr.getNoDelivery()); cell.setCellStyle(cs[1]); cell = row.createCell(24); cell.setCellValue(bdr.getRefusal()); cell.setCellStyle(cs[1]); cell = row.createCell(25); cell.setCellValue(bdr.getVoteSign()); cell.setCellStyle(cs[1]); cell = row.createCell(26); cell.setCellValue(bdr.getRemarks()); cell.setCellStyle(cs[1]); cell = row.createCell(27); cell.setCellValue(bdr.getExtendProp1()); cell.setCellStyle(cs[1]); } flag++; } } POIUtils.exprot(workbook, response, excelName); }
From source file:com.jslsolucoes.tagria.lib.grid.exporter.impl.ExcelExporter.java
License:Apache License
private void header(Sheet sheet, Workbook workbook) { Row sheetRow = sheet.createRow(0);/*from ww w .j a v a 2 s . com*/ int cell = 0; for (Header header : table.getHeaders()) { Cell sheetCel = sheetRow.createCell(cell); sheetCel.setCellValue(header.getContent()); CellStyle cellStyle = workbook.createCellStyle(); if ("center".equals(header.getAlign())) cellStyle.setAlignment(CellStyle.ALIGN_CENTER); else if ("left".equals(header.getAlign())) cellStyle.setAlignment(CellStyle.ALIGN_LEFT); else if ("right".equals(header.getAlign())) cellStyle.setAlignment(CellStyle.ALIGN_RIGHT); sheetCel.setCellStyle(cellStyle); cell++; } }
From source file:com.jslsolucoes.tagria.lib.grid.exporter.impl.ExcelExporter.java
License:Apache License
private void body(Sheet sheet, Workbook workbook) { int line = 1; for (com.jslsolucoes.tagria.lib.grid.exporter.model.Row row : table.getRows()) { Row sheetRow = sheet.createRow(line); int cell = 0; for (Column column : row.getColumns()) { Cell sheetCel = sheetRow.createCell(cell); sheetCel.setCellValue(column.getContent()); CellStyle cellStyle = workbook.createCellStyle(); if ("center".equals(column.getAlign())) cellStyle.setAlignment(CellStyle.ALIGN_CENTER); else if ("left".equals(column.getAlign())) cellStyle.setAlignment(CellStyle.ALIGN_LEFT); else if ("right".equals(column.getAlign())) cellStyle.setAlignment(CellStyle.ALIGN_RIGHT); sheetCel.setCellStyle(cellStyle); cell++;/*from w ww . j a v a2s . c om*/ } line++; } }
From source file:com.kafeidev.test.BusinessPlan.java
License:Apache License
@Test public static void main(String[] args) throws Exception { Workbook wb;/*from w w w . java2 s . co m*/ if (args.length > 0 && args[0].equals("-xls")) wb = new HSSFWorkbook(); else wb = new XSSFWorkbook(); Map<String, CellStyle> styles = createStyles(wb); Sheet sheet = wb.createSheet("Business Plan"); //turn off gridlines sheet.setDisplayGridlines(false); sheet.setPrintGridlines(false); sheet.setFitToPage(true); sheet.setHorizontallyCenter(true); PrintSetup printSetup = sheet.getPrintSetup(); printSetup.setLandscape(true); //the following three statements are required only for HSSF sheet.setAutobreaks(true); printSetup.setFitHeight((short) 1); printSetup.setFitWidth((short) 1); //the header row: centered text in 48pt font Row headerRow = sheet.createRow(0); headerRow.setHeightInPoints(12.75f); for (int i = 0; i < titles.length; i++) { Cell cell = headerRow.createCell(i); cell.setCellValue(titles[i]); cell.setCellStyle(styles.get("header")); } //columns for 11 weeks starting from 9-Nov Calendar calendar = Calendar.getInstance(); int year = calendar.get(Calendar.YEAR); // { // String inputDate = "2010-Nov-04 01:32:27"; // Date date = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss", new Locale("en,EN")).parse(inputDate); // String str= new SimpleDateFormat("dd.MMM.yyyy HH:mm:ss").format(date); // System.out.println("data:"+str); // // } calendar.setTime(fmt.parse("19-Nov")); calendar.set(Calendar.YEAR, year); for (int i = 0; i < 11; i++) { Cell cell = headerRow.createCell(titles.length + i); cell.setCellValue(calendar); cell.setCellStyle(styles.get("header_date")); calendar.roll(Calendar.WEEK_OF_YEAR, true); } //freeze the first row sheet.createFreezePane(0, 1); Row row; Cell cell; int rownum = 1; for (int i = 0; i < data.length; i++, rownum++) { row = sheet.createRow(rownum); if (data[i] == null) continue; for (int j = 0; j < data[i].length; j++) { cell = row.createCell(j); String styleName; boolean isHeader = i == 0 || data[i - 1] == null; switch (j) { case 0: if (isHeader) { styleName = "cell_b"; cell.setCellValue(Double.parseDouble(data[i][j])); } else { styleName = "cell_normal"; cell.setCellValue(data[i][j]); } break; case 1: if (isHeader) { styleName = i == 0 ? "cell_h" : "cell_bb"; } else { styleName = "cell_indented"; } cell.setCellValue(data[i][j]); break; case 2: styleName = isHeader ? "cell_b" : "cell_normal"; cell.setCellValue(data[i][j]); break; case 3: styleName = isHeader ? "cell_b_centered" : "cell_normal_centered"; cell.setCellValue(Integer.parseInt(data[i][j])); break; case 4: { calendar.setTime(fmt.parse(data[i][j])); calendar.set(Calendar.YEAR, year); cell.setCellValue(calendar); styleName = isHeader ? "cell_b_date" : "cell_normal_date"; break; } case 5: { int r = rownum + 1; String fmla = "IF(AND(D" + r + ",E" + r + "),E" + r + "+D" + r + ",\"\")"; cell.setCellFormula(fmla); styleName = isHeader ? "cell_bg" : "cell_g"; break; } default: styleName = data[i][j] != null ? "cell_blue" : "cell_normal"; } cell.setCellStyle(styles.get(styleName)); } } //group rows for each phase, row numbers are 0-based sheet.groupRow(4, 6); sheet.groupRow(9, 13); sheet.groupRow(16, 18); //set column widths, the width is measured in units of 1/256th of a character width sheet.setColumnWidth(0, 256 * 6); sheet.setColumnWidth(1, 256 * 33); sheet.setColumnWidth(2, 256 * 20); sheet.setZoom(3, 4); // Write the output to a file String file = "businessplan.xls"; if (wb instanceof XSSFWorkbook) file += "x"; FileOutputStream out = new FileOutputStream(file); wb.write(out); out.close(); }
From source file:com.kybelksties.excel.ExcelSheetTableModel.java
License:Open Source License
/** * Insert a row at a given index.//from w w w . ja v a 2s . c om * * @param createAtIndex row-number of the cell at which to create a new row * @param sourceRow the row to insert */ public void insertRowAt(int createAtIndex, Row sourceRow) { Row newRow = getRow(createAtIndex); if (newRow != null) { // shift all rows >= createAtIndex up by one getSheet().shiftRows(createAtIndex, getSheet().getLastRowNum(), 1); } else { newRow = getSheet().createRow(createAtIndex); } // Loop through source columns to add to new row for (int i = 0; i < sourceRow.getLastCellNum(); i++) { // Grab a copy of the old/new cell Cell oldCell = sourceRow.getCell(i); Cell newCell = newRow.createCell(i); // If the old cell is null jump to next cell if (oldCell == null) { continue; } // Copy style from old cell and apply to new cell CellStyle newCellStyle = workbook.createCellStyle(); newCellStyle.cloneStyleFrom(oldCell.getCellStyle()); newCell.setCellStyle(newCellStyle); // If there is a cell comment, copy if (oldCell.getCellComment() != null) { newCell.setCellComment(oldCell.getCellComment()); } // If there is a cell hyperlink, copy if (oldCell.getHyperlink() != null) { newCell.setHyperlink(oldCell.getHyperlink()); } // Set the cell data type newCell.setCellType(oldCell.getCellType()); // Set the cell data value switch (oldCell.getCellType()) { case Cell.CELL_TYPE_BLANK: newCell.setCellValue(oldCell.getStringCellValue()); break; case Cell.CELL_TYPE_BOOLEAN: newCell.setCellValue(oldCell.getBooleanCellValue()); break; case Cell.CELL_TYPE_ERROR: newCell.setCellErrorValue(oldCell.getErrorCellValue()); break; case Cell.CELL_TYPE_FORMULA: newCell.setCellFormula(oldCell.getCellFormula()); break; case Cell.CELL_TYPE_NUMERIC: newCell.setCellValue(oldCell.getNumericCellValue()); break; case Cell.CELL_TYPE_STRING: newCell.setCellValue(oldCell.getRichStringCellValue()); break; } } // If there are are any merged regions in the source row, copy to new row for (int i = 0; i < getSheet().getNumMergedRegions(); i++) { CellRangeAddress cellRangeAddress = getSheet().getMergedRegion(i); if (cellRangeAddress.getFirstRow() == sourceRow.getRowNum()) { CellRangeAddress newCellRangeAddress = new CellRangeAddress(newRow.getRowNum(), (newRow.getRowNum() + (cellRangeAddress.getLastRow() - cellRangeAddress.getFirstRow())), cellRangeAddress.getFirstColumn(), cellRangeAddress.getLastColumn()); getSheet().addMergedRegion(newCellRangeAddress); } } }
From source file:com.l3.info.magenda.emplois_du_temps.Jour.java
void writeInSheet(Workbook workbook, Sheet sheet, int x_sem, int y_sem) { Row[] row = new Row[1 + this.getNbrLigne()]; row[0] = sheet.createRow(y_sem);//from ww w . j a v a2s .co m for (int i = 1; i < 1 + this.getNbrLigne(); i++) { row[i] = sheet.createRow(y_sem + i); row[i].setHeight(Workbook.PixelsToTwips(64)); } int x = x_sem, y = 0; Cell cell = row[y].createCell(x); cell.setCellValue(this.nom_jour); cell.setCellStyle(workbook.getCellStyle("nom_du_jour")); x++; for (int i = START_HOUR_OF_DAY; i <= END_HOUR_OF_DAY; i++) { cell = row[y].createCell(x); cell.setCellValue(i + "h"); cell.setCellStyle(workbook.getCellStyle("case_gauche_jour")); cell = row[y].createCell(x + 1); cell.setCellStyle(workbook.getCellStyle("case_droite_jour")); x += 2; } for (int i = 1; i <= this.getNbrLigne(); i++) { x = x_sem + 1; for (int j = (END_HOUR_OF_DAY - START_HOUR_OF_DAY + 1); j > 0; j--) { cell = row[i].createCell(x); cell.setCellStyle(workbook.getCellStyle("case_gauche_jour")); cell = row[i].createCell(x + 1); cell.setCellStyle(workbook.getCellStyle("case_droite_jour")); x += 2; } } x = x_sem; y = y_sem; for (int i = 1; i <= this.getNbrLigne(); i++) { cell = row[i].createCell(x); cell.setCellStyle(workbook.getCellStyle("nom_du_jour")); } sheet.addMergedRegion(new CellRangeAddress(y + 1, y + getNbrLigne(), x, x)); x = x_sem + 1; y = y_sem + 1; for (Horaire h : horaire_du_jour) { cell = row[1 + h.getLigne()].createCell((x + h.getColonne())); cell.setCellValue(h.toString()); cell.setCellStyle(workbook.getCellStyle("Style_" + h.getExamen().getDiplome())); for (int i = 1; i < h.getPlage_horraire(); i++) { cell = row[1 + h.getLigne()].createCell((x + h.getColonne() + i)); cell.setCellStyle(workbook.getCellStyle("Style_" + h.getExamen().getDiplome())); } if (h.getPlage_horraire() > 1) { sheet.addMergedRegion(new CellRangeAddress(y + h.getLigne(), (y + h.getLigne()), (x + h.getColonne()), (int) (x + h.getColonne() + h.getPlage_horraire() - 1))); } } }
From source file:com.l3.info.magenda.emplois_du_temps.Semaine.java
void writeInSheet(Workbook workbook, int week_of_year) { XSSFWorkbook xssfWorkbook = workbook.getWorkbook(); Sheet sheet = xssfWorkbook.createSheet("Sem. " + week_of_year); Row row = sheet.createRow((short) 0); row.setHeight(Workbook.PixelsToTwips(64)); Cell cell = row.createCell((short) 0); // first row (0-based) - last row (0-based) - first column (0-based) -last column (0-based) sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, (20 - 7) * 2 + 2)); // Cree une nouvelle police Font font = xssfWorkbook.createFont(); font.setFontHeightInPoints((short) 18); font.setFontName("Arial"); // Fonts are set into a style so create a new one to use. XSSFCellStyle style = xssfWorkbook.createCellStyle(); style.setAlignment(HorizontalAlignment.CENTER); style.setFont(font);// w w w . j av a 2 s .c o m // Create a cell and put a value in it. cell.setCellValue("Semaine " + this.num_semaine); cell.setCellStyle(style); sheet.setDefaultRowHeight((short) 500); int x = 0, y = 2; for (Jour day : days_of_week) { day.writeInSheet(workbook, sheet, x, y); y += 2 + day.getNbrLigne(); } }
From source file:com.liferay.dynamic.data.lists.internal.exporter.DDLXLSExporter.java
License:Open Source License
protected void createDataRow(int rowIndex, Sheet sheet, DateTimeFormatter dateTimeFormatter, String author, String status, Date statusDate, CellStyle style, Map<String, DDMFormField> ddmFormFields, Map<String, DDMFormFieldRenderedValue> values) { Row row = sheet.createRow(rowIndex); int cellIndex = 0; Cell cell = null; for (Map.Entry<String, DDMFormField> entry : ddmFormFields.entrySet()) { cell = row.createCell(cellIndex++, CellType.STRING); cell.setCellStyle(style); if (values.containsKey(entry.getKey())) { DDMFormFieldRenderedValue ddmFormFieldRenderedValue = values.get(entry.getKey()); cell.setCellValue(GetterUtil.getString(ddmFormFieldRenderedValue.getValue())); } else {/*from ww w . j a v a 2 s. c o m*/ cell.setCellValue(StringPool.BLANK); } } cell = row.createCell(cellIndex++, CellType.STRING); cell.setCellStyle(style); cell.setCellValue(status); cell = row.createCell(cellIndex++, CellType.STRING); cell.setCellStyle(style); cell.setCellValue(formatDate(statusDate, dateTimeFormatter)); cell = row.createCell(cellIndex++, CellType.STRING); cell.setCellStyle(style); cell.setCellValue(author); }
From source file:com.liferay.dynamic.data.lists.internal.exporter.DDLXLSExporter.java
License:Open Source License
protected void createHeaderRow(Collection<DDMFormField> ddmFormFields, Sheet sheet, Workbook workbook) { Row row = sheet.createRow(0);/*ww w . j ava 2 s.co m*/ CellStyle cellStyle = createCellStyle(workbook, true, "Courier New", (short) 14); int cellIndex = 0; Cell cell = null; Locale locale = getLocale(); for (DDMFormField ddmFormField : ddmFormFields) { LocalizedValue label = ddmFormField.getLabel(); cell = row.createCell(cellIndex++, CellType.STRING); cell.setCellStyle(cellStyle); cell.setCellValue(label.getString(locale)); } cell = row.createCell(cellIndex++, CellType.STRING); cell.setCellStyle(cellStyle); cell.setCellValue(LanguageUtil.get(locale, "status")); cell = row.createCell(cellIndex++, CellType.STRING); cell.setCellStyle(cellStyle); cell.setCellValue(LanguageUtil.get(locale, "modified-date")); cell = row.createCell(cellIndex++, CellType.STRING); cell.setCellStyle(cellStyle); cell.setCellValue(LanguageUtil.get(locale, "author")); }