List of usage examples for org.apache.poi.xssf.usermodel XSSFSheet createRow
@Override public XSSFRow createRow(int rownum)
From source file:com.saba.CalendarDemo.java
License:Apache License
private static void prepareProductDetailsTableData(Map<String, Object> data, XSSFSheet sheet, Map<String, CellStyle> styles, int awardDetailsRow) { if (data.containsKey(awardHeaders[2]) && null != data.get(awardHeaders[2])) { @SuppressWarnings("unchecked") Map<String, Object[]> productDetailsMap = (Map<String, Object[]>) data.get(awardHeaders[2]); Set<String> keyset = productDetailsMap.keySet(); int rownum = awardDetailsRow + 2; for (String key : keyset) { try { XSSFRow pDetailsRow = sheet.createRow(rownum++); pDetailsRow.setHeightInPoints(12.75f); Object[] objArr = productDetailsMap.get(key); int cellnum = 0; for (Object obj : objArr) { XSSFCell cell = pDetailsRow.createCell(cellnum); cell.setCellStyle(styles.get("item_right")); //find and populate dynamic variable from object populateDynamicObject(cell, obj); //increment the cell size cellnum++;//from w w w. j a v a2 s . co m } } catch (Exception e) { //logger.error("Error while preparing the product Details table in xls :" + e); continue; } } } }
From source file:com.safeway.app.appcert.util.smoketester.TestCaseReader.java
public void writetoExcel(List<TestScriptTemplate> testcases) { XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = workbook.createSheet("Smoke Test Result"); DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); //create header first Row rowhead = sheet.createRow(2); rowhead.createCell(0).setCellValue("Application Code"); rowhead.createCell(1).setCellValue("Test Case #1: Login to application"); rowhead.createCell(2).setCellValue("Test Case #2: Verify Home Page title and element"); rowhead.createCell(3).setCellValue("Test Case #3: Verify next page title and element"); rowhead.createCell(4).setCellValue("Date and Time Log"); rowhead.createCell(5).setCellValue("Test Execution Log"); Iterator i = testcases.iterator(); int rownum = 3; while (i.hasNext()) { TestScriptTemplate testresult = (TestScriptTemplate) i.next(); Row row = sheet.createRow(rownum); rownum++;/* w ww . ja v a2 s. c om*/ Date date = new Date(); row.createCell(0).setCellValue(testresult.getAppCode()); row.createCell(1).setCellValue(testresult.getTc1_resultSummary()); row.createCell(2).setCellValue(testresult.getTc2_resultSummary()); row.createCell(3).setCellValue(testresult.getTc3_resultSummary()); //row.createCell(4).getCellStyle().setWrapText(true); row.createCell(4).setCellValue(dateFormat.format(date)); row.createCell(5).getCellStyle().setWrapText(true); row.createCell(5).setCellValue(testresult.getLogs()); } try { Date date = new Date(); DateFormat dateFormatFile1 = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss"); FileOutputStream out = new FileOutputStream( new File("C:\\Nino\\SmokeTest_" + dateFormatFile1.format(date) + ".xlsx")); workbook.write(out); out.close(); System.out.println("Excel written successfully.."); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.smanempat.controller.ControllerClassification.java
public void convertToExcel(JTable tableResult, File fileToSave) throws FileNotFoundException, IOException { XSSFWorkbook workBook = new XSSFWorkbook(); XSSFSheet sheet = workBook.createSheet(); XSSFRow row;// w w w . j av a2 s . c o m int rowCountData = tableResult.getRowCount(); Map<Integer, Object[]> data = new HashMap<Integer, Object[]>(); data.put(1, new Object[] { "NIS", "NAMA", "JK", "UN", "PT BINDO", "PT MTK", "PT BING", "PT IPA", "MINAT", "JURUSAN" }); for (int i = 0; i < rowCountData; i++) { // System.out.println(tableResult.getValueAt(i, 1)); data.put((i + 2), new Object[] { tableResult.getValueAt(i, 0), tableResult.getValueAt(i, 1), tableResult.getValueAt(i, 2), tableResult.getValueAt(i, 3), tableResult.getValueAt(i, 4), tableResult.getValueAt(i, 5), tableResult.getValueAt(i, 6), tableResult.getValueAt(i, 7), tableResult.getValueAt(i, 8), tableResult.getValueAt(i, 9) }); } //System.out.println("KeySet " + data.keySet()); Set<Integer> keyID = data.keySet(); int rowID = 0; for (Integer key : keyID) { row = sheet.createRow(rowID); Object[] tempData = data.get(key); rowID++; int cellID = 0; for (Object obj : tempData) { Cell cell = row.createCell(cellID); cell.setCellValue(obj.toString()); cellID++; } } FileOutputStream out = new FileOutputStream(fileToSave); workBook.write(out); out.close(); System.out.println(fileToSave + " Berhasil disimpan"); }
From source file:com.solidmaps.webapp.report.utils.ExcelMapCivilGenerator.java
private void addListProducts() { Cell referenceCell = this.findCell(LIST_PRODUCT_KEY).get(0); XSSFSheet sheetMoves = this.getSheet(0); int i = 0;//w w w . j a v a 2 s . c o m XSSFRow row = null; for (InvoiceInventoryMapEntity inventory : listInventory) { row = sheetMoves.createRow(referenceCell.getRowIndex() + i++); this.createCellProduct(sheetMoves, row, 0, inventory.getProduct().getName()); this.createCell(row, 4, inventory.getQtdInventoryPreviusTrimester().toString()); this.createCell(row, 5, inventory.getQtdBuyProduct().toString()); this.createCell(row, 6, inventory.getQtdInventoryPreviusTrimester().add(inventory.getQtdBuyProduct()).toString()); this.createCellUtilization(sheetMoves, row, inventory.getQtdUtilization().toString()); this.createCellSell(sheetMoves, row, inventory.getQtdSellProduct().toString()); this.createCellNextTrimester(sheetMoves, row, inventory.getQtdBuyProduct().subtract(inventory.getQtdSellProduct()).toString()); this.createCell(row, 14, inventory.getTypeQtdProduct()); } this.addBotton(row, sheetMoves); }
From source file:com.solidmaps.webapp.report.utils.ExcelMapCivilGenerator.java
private void addListInvoices(List<InvoiceProductEntity> listInvoice, String keyInvoice, Integer numSheet) { if (listInvoice == null || listInvoice.isEmpty()) { return;//from ww w . j av a 2s .c o m } Cell referenceCell = this.findCell(keyInvoice).get(0); XSSFSheet sheet = this.getSheet(numSheet); int i = 0; XSSFRow rowProviderPhoneCity = null; for (InvoiceProductEntity productInvoice : listInvoice) { XSSFRow row = sheet.createRow(referenceCell.getRowIndex() + i++); this.createCell(row, 0, DateUtils.format(productInvoice.getInvoice().getDateCreate())); this.createCell(row, 1, productInvoice.getInvoice().getNumInvoice()); String qtdtypeQtdInvoice = productInvoice.getQtdProduct().toString() + " " + productInvoice.getTypeQtdProduct(); this.createCell(row, 2, qtdtypeQtdInvoice); this.createCell(row, 3, productInvoice.getProduct().getProductOfficial().getName()); // Fornecedor ProviderEntity provider = productInvoice.getInvoice().getProvider(); String providerName = provider != null ? productInvoice.getInvoice().getProvider().getName() : ""; String providerStreet = provider != null ? productInvoice.getInvoice().getProvider().getStreet() : ""; String providerCep = provider != null ? productInvoice.getInvoice().getProvider().getCep() : ""; String providerCity = provider != null ? productInvoice.getInvoice().getProvider().getCity() : ""; ProviderEntity providerCarrier = productInvoice.getInvoice().getProviderCarrier(); String providerCarrierName = providerCarrier != null ? productInvoice.getInvoice().getProviderCarrier().getName() : ""; String providerCarrierStreet = providerCarrier != null ? productInvoice.getInvoice().getProviderCarrier().getStreet() : ""; String providerCarrierCep = providerCarrier != null ? productInvoice.getInvoice().getProviderCarrier().getCep() : ""; String providerCarrierCity = providerCarrier != null ? productInvoice.getInvoice().getProviderCarrier().getCity() : ""; this.createCell(row, 4, "Razo Social"); this.createCell(row, 5, providerName); this.createCell(row, 7, "Razo Social"); this.createCell(row, 8, providerCarrierName); XSSFRow rowProviderStreet = sheet.createRow(referenceCell.getRowIndex() + i++); this.createCell(rowProviderStreet, 4, "Endereo/Cep"); this.createCell(rowProviderStreet, 5, providerStreet + " " + providerCep); this.createCell(rowProviderStreet, 7, "Endereo/Cep"); this.createCell(rowProviderStreet, 8, providerCarrierStreet + " " + providerCarrierCep); rowProviderPhoneCity = sheet.createRow(referenceCell.getRowIndex() + i++); this.createCell(rowProviderPhoneCity, 4, "Cidade/UF/Fone"); this.createCell(rowProviderPhoneCity, 5, providerCity + "/" + productInvoice.getInvoice().getCompany().getPhoneNumber()); this.createCell(rowProviderPhoneCity, 7, "Cidade/UF/Fone"); this.createCell(rowProviderPhoneCity, 8, providerCarrierCity + "/" + " " + productInvoice.getInvoice().getCompany().getPhoneNumber()); } this.addBotton(rowProviderPhoneCity, sheet); }
From source file:com.solidmaps.webapp.report.utils.ExcelMapCivilGenerator.java
private void addBotton(XSSFRow lastRowReference, XSSFSheet sheet) { int colField = 5; int colValue = 6; int intRef = 4; XSSFRow rowTerms = sheet.createRow(lastRowReference.getRowNum() + intRef++); rowTerms.createCell(0).setCellValue("Ateno: O mapa dever ser entregue em 3 vias em at 10 dias"); rowTerms.createCell(colField).setCellValue("O que declaro a verdade, sob as penas da Lei."); XSSFRow rowCityDate = sheet.createRow(lastRowReference.getRowNum() + intRef++); rowCityDate.createCell(0).setCellValue("aps o trmino de cada trimestre."); rowCityDate.createCell(colField).setCellValue("Cidade/data:"); rowCityDate.createCell(colValue).setCellValue("${date.city} - ${date.format}"); XSSFRow rowEmpty = sheet.createRow(lastRowReference.getRowNum() + intRef++); rowEmpty.createCell(0);//w ww . ja v a 2s . co m XSSFRow rowSignature = sheet.createRow(lastRowReference.getRowNum() + intRef++); rowSignature.createCell(colField).setCellValue("Assinatura:"); rowSignature.createCell(colValue).setCellValue("____________________________________"); XSSFRow rowResponsable = sheet.createRow(lastRowReference.getRowNum() + intRef++); rowResponsable.createCell(colField).setCellValue("Nome:"); rowResponsable.createCell(colValue).setCellValue("${license.responsable.name}"); XSSFRow rowOffice = sheet.createRow(lastRowReference.getRowNum() + intRef++); rowOffice.createCell(colField).setCellValue("Cargo:"); rowOffice.createCell(colValue).setCellValue("${license.responsable.office}"); XSSFRow rowRG = sheet.createRow(lastRowReference.getRowNum() + intRef++); rowRG.createCell(colField).setCellValue("R.G. N:"); rowRG.createCell(colValue).setCellValue("${license.responsable.rg}"); }
From source file:com.springapp.mvc.CreatePivotTable.java
License:Apache License
public static void setCellData(XSSFSheet sheet) { Row row1 = sheet.createRow(0); // Create a cell and put a value in it. Cell cell11 = row1.createCell(0);/*from www . java 2 s. c o m*/ cell11.setCellValue("Names"); Cell cell12 = row1.createCell(1); cell12.setCellValue("#"); Cell cell13 = row1.createCell(2); cell13.setCellValue("%"); Cell cell14 = row1.createCell(3); cell14.setCellValue("Human"); Row row2 = sheet.createRow(1); Cell cell21 = row2.createCell(0); cell21.setCellValue("Jane"); Cell cell22 = row2.createCell(1); cell22.setCellValue(10); Cell cell23 = row2.createCell(2); cell23.setCellValue(100); Cell cell24 = row2.createCell(3); cell24.setCellValue("Yes"); Row row3 = sheet.createRow(2); Cell cell31 = row3.createCell(0); cell31.setCellValue("Tarzan"); Cell cell32 = row3.createCell(1); cell32.setCellValue(5); Cell cell33 = row3.createCell(2); cell33.setCellValue(90); Cell cell34 = row3.createCell(3); cell34.setCellValue("Yes"); Row row4 = sheet.createRow(3); Cell cell41 = row4.createCell(0); cell41.setCellValue("Terk"); Cell cell42 = row4.createCell(1); cell42.setCellValue(10); Cell cell43 = row4.createCell(2); cell43.setCellValue(90); Cell cell44 = row4.createCell(3); cell44.setCellValue("No"); Row row5 = sheet.createRow(4); Cell cell51 = row5.createCell(0); cell51.setCellValue("Terk"); Cell cell52 = row5.createCell(1); cell52.setCellValue(10); Cell cell53 = row5.createCell(2); cell53.setCellValue(90); Cell cell54 = row5.createCell(3); cell54.setCellValue("No"); }
From source file:com.vaadin.addon.spreadsheet.GroupingUtil.java
public static void collapseRow(XSSFSheet sheet, int rowIndex) { XSSFRow row = sheet.getRow(rowIndex); if (row != null) { int startRow = findStartOfRowOutlineGroup(sheet, rowIndex); // Hide all the columns until the end of the group int lastRow = writeHidden(sheet, row, startRow, true); /** start */ if (isRowsInverted(sheet)) { if (sheet.getRow(startRow) != null) { sheet.getRow(startRow).getCTRow().setCollapsed(true); } else if (startRow < 0) { // happens when inverted group starts at 0; Excel does not // write a collapsed prop for this case. } else { XSSFRow newRow = sheet.createRow(startRow); newRow.getCTRow().setCollapsed(true); }//from w w w. j a v a 2 s . c o m } else { if (sheet.getRow(lastRow) != null) { sheet.getRow(lastRow).getCTRow().setCollapsed(true); } else { XSSFRow newRow = sheet.createRow(lastRow); newRow.getCTRow().setCollapsed(true); } } /** end */ } }
From source file:com.vodafone.poms.ii.helpers.ExportManager.java
public void exportActivityForUser() { List<Activity> activities = activityController.getUserItems(); XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = workbook.createSheet("Master Track"); Row row = sheet.createRow(0); for (int i = 0; i < activityHeaders.length; i++) { row.createCell(i).setCellValue(activityHeaders[i]); }/*w w w. j a va 2 s .co m*/ for (int i = 0; i < activities.size(); i++) { row = sheet.createRow(i + 1); row.createCell(0).setCellValue(activities.get(i).getSite().getSitePhysical()); row.createCell(1).setCellValue(activities.get(i).getAsp().getSubcontractorName()); row.createCell(2).setCellValue(activities.get(i).getArea().getAreaName()); row.createCell(3).setCellValue(activities.get(i).getVendorOwner().getOwnerName()); if (activities.get(i).getClaimStatus() != null) { row.createCell(4).setCellValue(activities.get(i).getClaimStatus().getClaimName()); } else { row.createCell(4).setCellValue(""); } if (activities.get(i).getApprovalStatus() != null) { row.createCell(5).setCellValue(activities.get(i).getApprovalStatus().getStatusName()); } else { row.createCell(5).setCellValue(""); } row.createCell(6).setCellValue(activities.get(i).getActivityType().getDomainName()); if (activities.get(i).getPhase() != null) { row.createCell(7).setCellValue(activities.get(i).getPhase().getPhaseName()); } else { row.createCell(7).setCellValue(""); } row.createCell(8).setCellValue(activities.get(i).getActivityDate()); row.createCell(9).setCellValue(activities.get(i).getAcMaterialId()); row.createCell(10).setCellValue(activities.get(i).getAcDescription()); row.createCell(11).setCellValue(activities.get(i).getActivityDetails()); row.createCell(12).setCellValue(activities.get(i).getQty()); row.createCell(13).setCellValue(activities.get(i).getAcVendorPrice()); row.createCell(14).setCellValue(activities.get(i).getTotalPriceVendor()); row.createCell(15).setCellValue(activities.get(i).getTotalPriceVendorTaxes()); row.createCell(16).setCellValue(activities.get(i).getAcSubcontractorPrice()); row.createCell(17).setCellValue(activities.get(i).getTotalPriceAsp()); row.createCell(18).setCellValue(activities.get(i).getTotalUm()); row.createCell(19).setCellValue(activities.get(i).getTotalUmPercent()); row.createCell(20).setCellValue(activities.get(i).getActivityComment()); row.createCell(21).setCellValue((activities.get(i).getAspPoCollection().isEmpty() ? "Uncorrelated" : ((AspPo) activities.get(i).getAspPoCollection().toArray()[0]).getPoNumber())); } FacesContext facesContext = FacesContext.getCurrentInstance(); ExternalContext externalContext = facesContext.getExternalContext(); externalContext.setResponseContentType("application/vnd.ms-excel"); externalContext.setResponseHeader("Content-Disposition", "attachment; filename=\"G-Cairo Region Extra Work.xlsx\""); try { workbook.write(externalContext.getResponseOutputStream()); externalContext.getResponseOutputStream().close(); } catch (IOException ex) { Logger.getLogger(ExportManager.class.getName()).log(Level.SEVERE, null, ex); } facesContext.responseComplete(); JsfUtil.addSuccessMessage("Activity Report is now exported"); }
From source file:com.vodafone.poms.ii.helpers.ExportManager.java
public void exportActivity() { try {/*from ww w . j av a2s. co m*/ List<Activity> activities = activityController.getExportItems(fromDate, toDate); XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = workbook.createSheet("Master Track"); int imgPckId = addImageToWorkbook(workbook, "/home/poms/uploaded_data/pkg.png", Workbook.PICTURE_TYPE_PNG); String imgPckRelId = addImageToSheet(sheet, imgPckId, Workbook.PICTURE_TYPE_PNG); Row row = sheet.createRow(0); for (int i = 0; i < activityHeaders.length; i++) { row.createCell(i).setCellValue(activityHeaders[i]); } for (int i = 0; i < activities.size(); i++) { row = sheet.createRow(i + 1); row.createCell(0).setCellValue(activities.get(i).getSite().getSitePhysical()); row.createCell(1).setCellValue(activities.get(i).getAsp().getSubcontractorName()); row.createCell(2).setCellValue(activities.get(i).getArea().getAreaName()); row.createCell(3).setCellValue(activities.get(i).getVendorOwner().getOwnerName()); if (activities.get(i).getClaimStatus() != null) { row.createCell(4).setCellValue(activities.get(i).getClaimStatus().getClaimName()); } else { row.createCell(4).setCellValue(""); } if (activities.get(i).getApprovalStatus() != null) { row.createCell(5).setCellValue(activities.get(i).getApprovalStatus().getStatusName()); } else { row.createCell(5).setCellValue(""); } row.createCell(6).setCellValue(activities.get(i).getActivityType().getDomainName()); if (activities.get(i).getPhase() != null) { row.createCell(7).setCellValue(activities.get(i).getPhase().getPhaseName()); } else { row.createCell(7).setCellValue(""); } row.createCell(8).setCellValue(activities.get(i).getActivityDate()); row.createCell(9).setCellValue(activities.get(i).getAcMaterialId()); row.createCell(10).setCellValue(activities.get(i).getAcDescription()); row.createCell(11).setCellValue(activities.get(i).getActivityDetails()); row.createCell(12).setCellValue(activities.get(i).getQty()); row.createCell(13).setCellValue(activities.get(i).getAcVendorPrice()); row.createCell(14).setCellValue(activities.get(i).getTotalPriceVendor()); row.createCell(15).setCellValue(activities.get(i).getTotalPriceVendorTaxes()); row.createCell(16).setCellValue(activities.get(i).getAcSubcontractorPrice()); row.createCell(17).setCellValue(activities.get(i).getTotalPriceAsp()); row.createCell(18).setCellValue(activities.get(i).getTotalUm()); row.createCell(19).setCellValue(activities.get(i).getTotalUmPercent()); row.createCell(20).setCellValue(activities.get(i).getActivityComment()); row.createCell(21).setCellValue((activities.get(i).getAspPoCollection().isEmpty() ? "Uncorrelated" : ((AspPo) activities.get(i).getAspPoCollection().toArray()[0]).getPoNumber())); if (activities.get(i).getActivityAttachmentsCollection() != null) { if (activities.get(i).getActivityAttachmentsCollection().size() > 0) { Object[] attachments = activities.get(i).getActivityAttachmentsCollection().toArray(); for (int j = 0; j < attachments.length; j++) { XSSFClientAnchor imgAnchor1 = new XSSFClientAnchor(0, 0, 0, 0, (23 + j), row.getRowNum(), (23 + j + 1), row.getRowNum() + 1); String oleRelId1 = addFile(sheet, ((ActivityAttachments) attachments[j]).getAttachmentLocation(), (i + j + activities.get(i).getActivityId().intValue() + Math.random())); int shapeId1 = addImageToShape(sheet, imgAnchor1, imgPckId); addObjectToShape(sheet, imgAnchor1, shapeId1, oleRelId1, imgPckRelId, "Objekt-Manager-Shellobjekt"); } } } } FacesContext facesContext = FacesContext.getCurrentInstance(); ExternalContext externalContext = facesContext.getExternalContext(); externalContext.setResponseContentType("application/vnd.ms-excel"); externalContext.setResponseHeader("Content-Disposition", "attachment; filename=\"G-Cairo Region Extra Work.xlsx\""); try { workbook.write(externalContext.getResponseOutputStream()); externalContext.getResponseOutputStream().close(); } catch (IOException ex) { Logger.getLogger(ExportManager.class.getName()).log(Level.SEVERE, null, ex); } facesContext.responseComplete(); JsfUtil.addSuccessMessage("Activity Report is now exported"); } catch (InvalidFormatException ex) { Logger.getLogger(ExportManager.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ExportManager.class.getName()).log(Level.SEVERE, null, ex); } }