List of usage examples for org.apache.poi.ss.usermodel Row getCell
Cell getCell(int cellnum);
From source file:com.accenture.ts.dao.TesteCaseTSDAO.java
public boolean updateTsSheet(String pathSheet, String nameSheet, TesteCaseTSBean testCase) throws FileNotFoundException, IOException { boolean sucess = false; destinationSheet = new File(pathSheet); destinationSheet.mkdirs();/*from www. j a v a2 s . com*/ destinationSheet = new File(pathSheet + "\\" + nameSheet); sourceStheet = new File(sheetDefault); copySheet(sourceStheet, destinationSheet); FileInputStream fileSheet = new FileInputStream(destinationSheet); XSSFWorkbook workbook = new XSSFWorkbook(fileSheet); XSSFSheet sheetTS = workbook.getSheetAt(0); XSSFDataFormat format = workbook.createDataFormat(); XSSFCellStyle estilo = workbook.createCellStyle(); // String formatData = "aaaa-mm-dd\"T12:00:00-03:00\""; int linha = 1; Row row = sheetTS.getRow(linha); Cell descriptionPlan = row.getCell(0); Cell prj = row.getCell(1); Cell fase = row.getCell(2); Cell testPhase = row.getCell(3); Cell testScriptName = row.getCell(4); Cell testScriptDescription = row.getCell(5); Cell stepNo = row.getCell(6); Cell stepDescription = row.getCell(7); Cell expectedResults = row.getCell(8); Cell product = row.getCell(9); Cell dataPlanejada = row.getCell(10); Cell complexidade = row.getCell(11); Cell automatizado = row.getCell(12); descriptionPlan.setCellValue(testCase.getTestPlan()); prj.setCellValue(testCase.getSTIPRJ()); fase.setCellValue(testCase.getFASE()); testPhase.setCellValue(testCase.getTestPhase()); // estilo.setDataFormat(format.getFormat(formatData)); // estilo.setFillBackgroundColor(HSSFColor.GREEN.index); row = sheetTS.getRow(linha); prj = row.getCell(1); fase = row.getCell(2); testPhase = row.getCell(3); testScriptName = row.getCell(4); testScriptDescription = row.getCell(5); stepNo = row.getCell(6); stepDescription = row.getCell(7); expectedResults = row.getCell(8); product = row.getCell(9); dataPlanejada = row.getCell(10); complexidade = row.getCell(11); automatizado = row.getCell(12); testScriptName.setCellValue(testCase.getTestScriptName()); testScriptDescription.setCellValue(testCase.getTestScriptDescription()); stepNo.setCellValue(testCase.getSTEP_NUMERO()); stepDescription.setCellValue(testCase.getStepDescription()); expectedResults.setCellValue(testCase.getExpectedResults()); product.setCellValue(testCase.getProduct()); estilo = (XSSFCellStyle) dataPlanejada.getCellStyle(); dataPlanejada.setCellValue(testCase.getDataPlanejada()); dataPlanejada.setCellStyle(estilo); complexidade.setCellValue(testCase.getComplexidade()); automatizado.setCellValue(testCase.isAutomatizado()); linha = linha + 2; FileOutputStream fileOut = new FileOutputStream(destinationSheet); workbook.write(fileOut); fileOut.close(); fileSheet.close(); sucess = true; return sucess; }
From source file:com.accenture.ts.dao.TesteCaseTSDAO.java
public List<TesteCaseTSBean> readSheet(String pathSheetFull) throws FileNotFoundException, IOException { List<TesteCaseTSBean> listTS = new ArrayList<TesteCaseTSBean>(); FileInputStream fileSheet = new FileInputStream(new File(pathSheetFull)); XSSFWorkbook workbook = new XSSFWorkbook(fileSheet); XSSFSheet sheetTS = workbook.getSheetAt(0); int linha = 1; Row row = sheetTS.getRow(linha); Cell descriptionPlan = row.getCell(0); Cell prj = row.getCell(1);//from w w w . j ava2 s . c o m Cell fase = row.getCell(2); Cell testPhase = row.getCell(3); Cell testScriptName = row.getCell(4); Cell testScriptDescription = row.getCell(5); Cell stepNo = row.getCell(6); Cell stepDescription = row.getCell(7); Cell expectedResults = row.getCell(8); Cell product = row.getCell(9); Cell dataPlanejada = row.getCell(10); Cell complexidade = row.getCell(11); Cell automatizado = row.getCell(12); String descPlan = null; String project = null; String phase = null; if (!testScriptName.equals("")) { descPlan = descriptionPlan.getStringCellValue(); project = prj.getStringCellValue(); phase = testPhase.getStringCellValue(); } while (!testScriptName.getStringCellValue().equals("") && testScriptName != null) { testCase = new TesteCaseTSBean(); testCase.setTestScriptName(testScriptName.getStringCellValue()); testCase.setTestScriptDescription(testScriptDescription.getStringCellValue()); testCase.setStepDescription(stepDescription.getStringCellValue()); testCase.setExpectedResults(expectedResults.getStringCellValue()); testCase.setProduct(product.getStringCellValue()); // testCase.setDataPlanejada(dataPlanejada.getDateCellValue()); testCase.setFase(fase.getStringCellValue()); testCase.setTestPlan(descPlan); testCase.setSTIPRJ(project); testCase.setTestPhase(phase); testCase.setComplexidade(complexidade.getStringCellValue()); testCase.setAutomatizado(automatizado.getBooleanCellValue()); listTS.add(testCase); linha = linha + 2; row = sheetTS.getRow(linha); descriptionPlan = row.getCell(0); prj = row.getCell(1); fase = row.getCell(2); testPhase = row.getCell(3); testScriptName = row.getCell(4); testScriptDescription = row.getCell(5); stepNo = row.getCell(6); stepDescription = row.getCell(7); expectedResults = row.getCell(8); product = row.getCell(9); dataPlanejada = row.getCell(10); complexidade = row.getCell(11); } return listTS; }
From source file:com.accounting.accountMBean.DifferentAccReports.java
public void postProcessXLSAgeingReport(Object document) { ndc = new NepaliDateConverter(); String startDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate4"); String endDateReading = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate5"); HSSFWorkbook wb = (HSSFWorkbook) document; HSSFCellStyle headerCellStyle = wb.createCellStyle(); HSSFCellStyle headerCellStyle1 = wb.createCellStyle(); HSSFCellStyle headerCellStyle2 = wb.createCellStyle(); Font headerFont = wb.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); headerFont.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle.setFont(headerFont); headerCellStyle.setAlignment(CellStyle.ALIGN_CENTER); Font headerFont1 = wb.createFont(); headerFont1.setBoldweight(Font.U_SINGLE_ACCOUNTING); headerFont1.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle1.setFont(headerFont); headerCellStyle1.setAlignment(CellStyle.ALIGN_RIGHT); HSSFSheet sheet = wb.getSheetAt(0);//from w ww. j av a 2 s . com int noOfColumns = sheet.getRow(0).getLastCellNum(); Font headerFont3 = wb.createFont(); headerFont3.setBoldweight(Font.U_SINGLE); headerFont3.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle2.setFont(headerFont1); headerCellStyle2.setAlignment(CellStyle.ALIGN_RIGHT); for (int i = 0; i < noOfColumns; i++) { sheet.autoSizeColumn(i); } sheet.shiftRows(0, sheet.getLastRowNum(), 4); HSSFRow firstRow = sheet.createRow(1); firstRow.createCell(0).setCellValue(PageName); firstRow.getCell(0).setCellStyle(headerCellStyle); HSSFRow secondRow = sheet.createRow(0); secondRow.createCell(0).setCellValue(getLoggedInOffice().getName()); secondRow.getCell(0).setCellStyle(headerCellStyle); HSSFRow thirdRow = sheet.createRow(3); String generatedDate = ndc.convertToNepaliDate(new Date()); SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss a"); String time = sdf.format(new Date()); thirdRow.createCell(0) .setCellValue("Generated on:" + generatedDate + " " + time + " by:" + getLoggedInUser().getName()); thirdRow.getCell(0).setCellStyle(headerCellStyle2); HSSFRow fourthRow = sheet.createRow(2); fourthRow.createCell(0).setCellValue("From: " + startDateString + " To: " + endDateReading); fourthRow.getCell(0).setCellStyle(headerCellStyle); sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 6)); sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 6)); sheet.addMergedRegion(new CellRangeAddress(2, 2, 0, 6)); sheet.addMergedRegion(new CellRangeAddress(3, 3, 0, 6)); for (Row row : sheet) { if (row.getRowNum() > 4) { String cost = row.getCell(4).getStringCellValue(); if (cost != null && !cost.isEmpty()) { row.getCell(4).setCellType(HSSFCell.CELL_TYPE_BLANK); row.getCell(4).setCellType(HSSFCell.CELL_TYPE_NUMERIC); row.getCell(4).setCellValue(Double.parseDouble(cost.replace(",", ""))); } } } }
From source file:com.accounting.inventory.InventorySalesMBean.java
public void postProcessXLSSalesBetDate(Object document) { String startDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate4"); String endDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate5"); HSSFWorkbook wb = (HSSFWorkbook) document; HSSFCellStyle headerCellStyle = wb.createCellStyle(); HSSFCellStyle headerCellStyle1 = wb.createCellStyle(); HSSFCellStyle headerCellStyle2 = wb.createCellStyle(); Font headerFont = wb.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); headerFont.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle.setFont(headerFont); headerCellStyle.setAlignment(CellStyle.ALIGN_CENTER); Font headerFont1 = wb.createFont(); headerFont1.setBoldweight(Font.U_SINGLE_ACCOUNTING); headerFont1.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle1.setFont(headerFont); headerCellStyle1.setAlignment(CellStyle.ALIGN_RIGHT); HSSFSheet sheet = wb.getSheetAt(0);/*from w w w . j a va 2 s. c om*/ int noOfColumns = sheet.getRow(0).getLastCellNum(); Font headerFont3 = wb.createFont(); headerFont3.setBoldweight(Font.U_SINGLE); headerFont3.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle2.setFont(headerFont1); headerCellStyle2.setAlignment(CellStyle.ALIGN_RIGHT); for (int i = 0; i < noOfColumns; i++) { sheet.autoSizeColumn(i); } sheet.shiftRows(0, sheet.getLastRowNum(), 4); HSSFRow firstRow = sheet.createRow(1); firstRow.createCell(0).setCellValue("SALES INVOICE REPORT"); firstRow.getCell(0).setCellStyle(headerCellStyle); HSSFRow secondRow = sheet.createRow(0); secondRow.createCell(0).setCellValue(getLoggedInOffice().getName()); secondRow.getCell(0).setCellStyle(headerCellStyle); HSSFRow thirdRow = sheet.createRow(3); String date = ndc.convertToNepaliDate(new Date()); SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss a"); String time = sdf.format(new Date()); thirdRow.createCell(0) .setCellValue("Generated on:" + date + " " + time + " by:" + getLoggedInUser().getName()); thirdRow.getCell(0).setCellStyle(headerCellStyle2); HSSFRow fourthRow = sheet.createRow(2); fourthRow.createCell(0).setCellValue("FROM: " + startDateString + " TO: " + endDateString); fourthRow.getCell(0).setCellStyle(headerCellStyle); sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 6)); sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 6)); sheet.addMergedRegion(new CellRangeAddress(2, 2, 0, 6)); sheet.addMergedRegion(new CellRangeAddress(3, 3, 0, 6)); for (Row row : sheet) { if (row.getRowNum() > 4) { for (int i = 4; i < 7; i++) { String cost1 = row.getCell(i).getStringCellValue(); if (!cost1.isEmpty()) { row.getCell(i).setCellType(HSSFCell.CELL_TYPE_BLANK); row.getCell(i).setCellType(HSSFCell.CELL_TYPE_NUMERIC); row.getCell(i).setCellValue(Double.valueOf(cost1)); } } } } }
From source file:com.accounting.inventory.InventorySalesMBean.java
public void postProcessXLS(Object document) { String startDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate4"); String endDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate5"); HSSFWorkbook wb = (HSSFWorkbook) document; HSSFCellStyle headerCellStyle = wb.createCellStyle(); HSSFCellStyle headerCellStyle1 = wb.createCellStyle(); HSSFCellStyle headerCellStyle2 = wb.createCellStyle(); Font headerFont = wb.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); headerFont.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle.setFont(headerFont); headerCellStyle.setAlignment(CellStyle.ALIGN_CENTER); Font headerFont1 = wb.createFont(); headerFont1.setBoldweight(Font.U_SINGLE_ACCOUNTING); headerFont1.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle1.setFont(headerFont); headerCellStyle1.setAlignment(CellStyle.ALIGN_RIGHT); HSSFSheet sheet = wb.getSheetAt(0);//from w w w . j a va2s . com int noOfColumns = sheet.getRow(0).getLastCellNum(); Font headerFont3 = wb.createFont(); headerFont3.setBoldweight(Font.U_SINGLE); headerFont3.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle2.setFont(headerFont1); headerCellStyle2.setAlignment(CellStyle.ALIGN_RIGHT); for (int i = 0; i < noOfColumns; i++) { sheet.autoSizeColumn(i); } sheet.shiftRows(0, sheet.getLastRowNum(), 4); HSSFRow firstRow = sheet.createRow(1); firstRow.createCell(0).setCellValue("SALES REPORT"); firstRow.getCell(0).setCellStyle(headerCellStyle); HSSFRow secondRow = sheet.createRow(0); secondRow.createCell(0).setCellValue(getLoggedInOffice().getName()); secondRow.getCell(0).setCellStyle(headerCellStyle); HSSFRow thirdRow = sheet.createRow(3); String date = ndc.convertToNepaliDate(new Date()); SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss a"); String time = sdf.format(new Date()); thirdRow.createCell(0) .setCellValue("Generated on:" + date + " " + time + " by:" + getLoggedInUser().getName()); thirdRow.getCell(0).setCellStyle(headerCellStyle2); if (!displayAll) { if (stage == 1) { HSSFRow fourthRow = sheet.createRow(2); fourthRow.createCell(0).setCellValue("FROM: " + startDateString + " TO: " + endDateString); fourthRow.getCell(0).setCellStyle(headerCellStyle); } } sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 6)); sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 6)); sheet.addMergedRegion(new CellRangeAddress(2, 2, 0, 6)); sheet.addMergedRegion(new CellRangeAddress(3, 3, 0, 6)); HSSFRow lastRow; double totalSold = 0; for (Row row : sheet) { if (row.getRowNum() > 4) { String cost = row.getCell(3).getStringCellValue(); if (cost != null && !cost.isEmpty()) { row.getCell(3).setCellType(HSSFCell.CELL_TYPE_BLANK); row.getCell(3).setCellType(HSSFCell.CELL_TYPE_NUMERIC); row.getCell(3).setCellValue(Double.valueOf(cost)); totalSold += Double.parseDouble(cost.replace(",", "")); } } } for (Row row : sheet) { if (row.getRowNum() > 4) { for (int i = 4; i < 5; i++) { String cost1 = row.getCell(i).getStringCellValue(); row.getCell(i).setCellType(HSSFCell.CELL_TYPE_BLANK); row.getCell(i).setCellType(HSSFCell.CELL_TYPE_NUMERIC); row.getCell(i).setCellValue(Double.valueOf(cost1)); // totalSold += Double.valueOf(row.getCell(3).getStringCellValue()); } } } lastRow = sheet.createRow(sheet.getLastRowNum() + 1); HSSFCell totalSumTextCell = lastRow.createCell(2); totalSumTextCell.setCellValue("Total Sales Amount: "); HSSFCell totalUnitsCell = lastRow.createCell(3); totalUnitsCell.setCellValue(totalSold); }
From source file:com.accounting.inventory.InventorySalesMBean.java
public void postProcessXLSSalesReturn(Object document) { String startDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate4"); String endDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate5"); HSSFWorkbook wb = (HSSFWorkbook) document; HSSFCellStyle headerCellStyle = wb.createCellStyle(); HSSFCellStyle headerCellStyle1 = wb.createCellStyle(); HSSFCellStyle headerCellStyle2 = wb.createCellStyle(); Font headerFont = wb.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); headerFont.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle.setFont(headerFont); headerCellStyle.setAlignment(CellStyle.ALIGN_CENTER); Font headerFont1 = wb.createFont(); headerFont1.setBoldweight(Font.U_SINGLE_ACCOUNTING); headerFont1.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle1.setFont(headerFont); headerCellStyle1.setAlignment(CellStyle.ALIGN_RIGHT); HSSFSheet sheet = wb.getSheetAt(0);/* w w w . jav a2 s. com*/ int noOfColumns = sheet.getRow(0).getLastCellNum(); Font headerFont3 = wb.createFont(); headerFont3.setBoldweight(Font.U_SINGLE); headerFont3.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle2.setFont(headerFont1); headerCellStyle2.setAlignment(CellStyle.ALIGN_RIGHT); for (int i = 0; i < noOfColumns; i++) { sheet.autoSizeColumn(i); } sheet.shiftRows(0, sheet.getLastRowNum(), 4); HSSFRow firstRow = sheet.createRow(1); firstRow.createCell(0).setCellValue("SALES RETURN REPORT"); firstRow.getCell(0).setCellStyle(headerCellStyle); HSSFRow secondRow = sheet.createRow(0); secondRow.createCell(0).setCellValue(getLoggedInOffice().getName()); secondRow.getCell(0).setCellStyle(headerCellStyle); HSSFRow thirdRow = sheet.createRow(3); String date = ndc.convertToNepaliDate(new Date()); SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss a"); String time = sdf.format(new Date()); thirdRow.createCell(0) .setCellValue("Generated on:" + date + " " + time + " by:" + getLoggedInUser().getName()); thirdRow.getCell(0).setCellStyle(headerCellStyle2); if (stage == 1) { HSSFRow fourthRow = sheet.createRow(2); fourthRow.createCell(0).setCellValue("FROM: " + startDateString + " TO: " + endDateString); fourthRow.getCell(0).setCellStyle(headerCellStyle); } sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 4)); sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 4)); sheet.addMergedRegion(new CellRangeAddress(2, 2, 0, 4)); sheet.addMergedRegion(new CellRangeAddress(3, 3, 0, 4)); HSSFRow lastRow; double totalSold = 0; for (Row row : sheet) { if (row.getRowNum() > 4) { String cost = row.getCell(4).getStringCellValue(); row.getCell(4).setCellType(HSSFCell.CELL_TYPE_BLANK); row.getCell(4).setCellType(HSSFCell.CELL_TYPE_NUMERIC); row.getCell(4).setCellValue(Double.valueOf(cost)); totalSold += Double.valueOf(cost); } } lastRow = sheet.createRow(sheet.getLastRowNum() + 1); HSSFCell totalSumTextCell = lastRow.createCell(3); totalSumTextCell.setCellValue("Total : "); HSSFCell totalUnitsCell = lastRow.createCell(4); totalUnitsCell.setCellValue(totalSold); }
From source file:com.accounting.office.PayRollManagedBean.java
public void simplePostProcessXLSEmployeeReport(Object document) { String startDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate4"); String endDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate5"); HSSFWorkbook wb = (HSSFWorkbook) document; HSSFCellStyle headerCellStyle = wb.createCellStyle(); HSSFCellStyle headerCellStyle1 = wb.createCellStyle(); HSSFCellStyle headerCellStyle2 = wb.createCellStyle(); Font headerFont = wb.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); headerFont.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle.setFont(headerFont); headerCellStyle.setAlignment(CellStyle.ALIGN_CENTER); Font headerFont1 = wb.createFont(); headerFont1.setBoldweight(Font.U_SINGLE_ACCOUNTING); headerFont1.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle1.setFont(headerFont); headerCellStyle1.setAlignment(CellStyle.ALIGN_RIGHT); Font headerFont3 = wb.createFont(); headerFont3.setBoldweight(Font.U_SINGLE); headerFont3.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle2.setFont(headerFont1); headerCellStyle2.setAlignment(CellStyle.ALIGN_RIGHT); HSSFSheet sheet = wb.getSheetAt(0);//from ww w. ja v a 2 s . c o m int noOfColumns = sheet.getRow(0).getLastCellNum(); for (int i = 0; i < noOfColumns; i++) { sheet.autoSizeColumn(i); } sheet.shiftRows(0, sheet.getLastRowNum(), 3); HSSFRow firstRow = sheet.createRow(1); firstRow.createCell(0).setCellValue("Salary Posting Report"); firstRow.getCell(0).setCellStyle(headerCellStyle); HSSFRow secondRow = sheet.createRow(0); secondRow.createCell(0).setCellValue(getLoggedInOffice().getName()); secondRow.getCell(0).setCellStyle(headerCellStyle); HSSFRow thirdRow = sheet.createRow(2); String date = ndc.convertToNepaliDate(new Date()); SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss a"); String time = sdf.format(new Date()); thirdRow.createCell(0) .setCellValue("Generated on:" + date + " " + time + " by:" + getLoggedInUser().getName()); thirdRow.getCell(0).setCellStyle(headerCellStyle2); sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 5)); sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 5)); sheet.addMergedRegion(new CellRangeAddress(2, 2, 0, 5)); for (Row row : sheet) { if (row.getRowNum() > 3) { for (int i = 2; i < 6; i++) { String cost = row.getCell(i).getStringCellValue(); if (cost != null && !cost.isEmpty()) { row.getCell(i).setCellType(HSSFCell.CELL_TYPE_BLANK); row.getCell(i).setCellType(HSSFCell.CELL_TYPE_NUMERIC); row.getCell(i).setCellValue(Double.parseDouble(cost.replace(",", ""))); } } } } }
From source file:com.accounting.reportMBean.ReportCommonBean.java
public void simplePostProcessXLS(Object document) { String startDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate4"); String endDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate1"); HSSFWorkbook wb = (HSSFWorkbook) document; HSSFCellStyle headerCellStyle = wb.createCellStyle(); HSSFCellStyle headerCellStyle1 = wb.createCellStyle(); HSSFCellStyle headerCellStyle2 = wb.createCellStyle(); Font headerFont = wb.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); headerFont.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle.setFont(headerFont); headerCellStyle.setAlignment(CellStyle.ALIGN_CENTER); Font headerFont1 = wb.createFont(); headerFont1.setBoldweight(Font.U_SINGLE_ACCOUNTING); headerFont1.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle1.setFont(headerFont); headerCellStyle1.setAlignment(CellStyle.ALIGN_RIGHT); Font headerFont3 = wb.createFont(); headerFont3.setBoldweight(Font.U_SINGLE); headerFont3.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle2.setFont(headerFont1); headerCellStyle2.setAlignment(CellStyle.ALIGN_RIGHT); HSSFSheet sheet = wb.getSheetAt(0);/*from w ww . j a va2 s.c om*/ int noOfColumns = sheet.getRow(0).getLastCellNum(); for (int i = 0; i < noOfColumns; i++) { sheet.autoSizeColumn(i); } sheet.shiftRows(0, sheet.getLastRowNum(), 4); HSSFRow firstRow = sheet.createRow(1); firstRow.createCell(0).setCellValue(pageName); firstRow.getCell(0).setCellStyle(headerCellStyle); HSSFRow secondRow = sheet.createRow(0); secondRow.createCell(0).setCellValue(getLoggedInOffice().getName()); secondRow.getCell(0).setCellStyle(headerCellStyle); HSSFRow thirdRow = sheet.createRow(3); String date = ndc.convertToNepaliDate(new Date()); SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss a"); String time = sdf.format(new Date()); thirdRow.createCell(0) .setCellValue("Generated on:" + date + " " + time + " by:" + getLoggedInUser().getName()); thirdRow.getCell(0).setCellStyle(headerCellStyle2); HSSFRow fourthRow = sheet.createRow(2); fourthRow.createCell(0).setCellValue("FROM: " + startDateString + " TO: " + endDateString); fourthRow.getCell(0).setCellStyle(headerCellStyle); sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 7)); sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 7)); sheet.addMergedRegion(new CellRangeAddress(2, 2, 0, 7)); sheet.addMergedRegion(new CellRangeAddress(3, 3, 0, 7)); HSSFRow lastRow; for (Row row : sheet) { if (row.getRowNum() > 4) { for (int i = 3; i < 8; i++) { String cost = row.getCell(i).getStringCellValue(); if (cost != null && !cost.isEmpty()) { row.getCell(i).setCellType(HSSFCell.CELL_TYPE_BLANK); row.getCell(i).setCellType(HSSFCell.CELL_TYPE_NUMERIC); row.getCell(i).setCellValue(Double.parseDouble(cost.replace(",", ""))); } } } } }
From source file:com.accounting.reportMBean.StockLedgerMBeans.java
public void postProcessXLS(Object document) { String startDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate4"); String endDateReading = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate1"); HSSFWorkbook wb = (HSSFWorkbook) document; HSSFCellStyle headerCellStyle = wb.createCellStyle(); HSSFCellStyle headerCellStyle1 = wb.createCellStyle(); HSSFCellStyle headerCellStyle2 = wb.createCellStyle(); Font headerFont = wb.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); headerFont.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle.setFont(headerFont); headerCellStyle.setAlignment(CellStyle.ALIGN_CENTER); Font headerFont1 = wb.createFont(); headerFont1.setBoldweight(Font.U_SINGLE_ACCOUNTING); headerFont1.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle1.setFont(headerFont); headerCellStyle1.setAlignment(CellStyle.ALIGN_RIGHT); HSSFSheet sheet = wb.getSheetAt(0);/*from w ww . j av a 2 s. com*/ int noOfColumns = sheet.getRow(0).getLastCellNum(); Font headerFont3 = wb.createFont(); headerFont3.setBoldweight(Font.U_SINGLE); headerFont3.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle2.setFont(headerFont1); headerCellStyle2.setAlignment(CellStyle.ALIGN_RIGHT); for (int i = 0; i < noOfColumns; i++) { sheet.autoSizeColumn(i); } sheet.shiftRows(0, sheet.getLastRowNum(), 4); HSSFRow firstRow = sheet.createRow(0); firstRow.createCell(0).setCellValue(reportHeader); firstRow.getCell(0).setCellStyle(headerCellStyle); HSSFRow secondRow = sheet.createRow(1); secondRow.createCell(0).setCellValue(getLoggedInOffice().getName()); secondRow.getCell(0).setCellStyle(headerCellStyle); HSSFRow thirdRow = sheet.createRow(3); String generatedDate = ndc.convertToNepaliDate(new Date()); SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss a"); String time = sdf.format(new Date()); thirdRow.createCell(0) .setCellValue("Generated on:" + generatedDate + " " + time + " by:" + getLoggedInUser().getName()); thirdRow.getCell(0).setCellStyle(headerCellStyle2); HSSFRow fourthRow = sheet.createRow(2); fourthRow.createCell(0).setCellValue("From: " + startDateString + " To: " + endDateReading); fourthRow.getCell(0).setCellStyle(headerCellStyle); System.out.println("The cell count " + cellCount); sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, cellCount)); sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, cellCount)); sheet.addMergedRegion(new CellRangeAddress(2, 2, 0, cellCount)); sheet.addMergedRegion(new CellRangeAddress(3, 3, 0, cellCount)); for (Row row : sheet) { if (row.getRowNum() > 4) { for (int i = 3; i < count; i++) { String cost = row.getCell(i).getStringCellValue(); if (cost != null && !cost.isEmpty()) { row.getCell(i).setCellType(HSSFCell.CELL_TYPE_BLANK); row.getCell(i).setCellType(HSSFCell.CELL_TYPE_NUMERIC); row.getCell(i).setCellValue(Double.parseDouble(cost.replace(",", ""))); } } } } }
From source file:com.actelion.research.spiritapp.report.AbstractReport.java
License:Open Source License
public void populateReport(Study study) throws Exception { assert study != null; this.study = study; initWorkbook();//from w ww. j a v a 2s . co m //Create the workbook populateWorkBook(); //Post processing //Add Table borders (between different styles of cells) for (int i = 0; i < wb.getNumberOfSheets(); i++) { Sheet sheet = wb.getSheetAt(i); for (int r = 4; r <= sheet.getLastRowNum(); r++) { Row row = sheet.getRow(r); if (row == null) continue; Row rowUp = sheet.getRow(r - 1); Row rowDown = sheet.getRow(r + 1); for (int c = 0; c <= row.getLastCellNum(); c++) { Cell cell = row.getCell(c); Cell cellLeft = c == 0 ? null : row.getCell(c - 1); boolean borderLeftAbove = cellLeft != null && cellLeft.getCellStyle().getBorderTop() == 1; boolean borderLeftUnder = cellLeft != null && cellLeft.getCellStyle().getBorderBottom() == 1; if ((cell != null && cell.getCellStyle().getBorderLeft() + cell.getCellStyle().getBorderRight() > 0) || (cell == null && c + 1 <= row.getLastCellNum() && row.getCell(c + 1) != null)) { if (borderLeftAbove) drawLineAbove(sheet, r, c, c, (short) 1); if (borderLeftUnder) drawLineUnder(sheet, r, c, c, (short) 1); } if (cell != null) { Font font = wb.getFontAt(cell.getCellStyle().getFontIndex()); if (font.getFontHeightInPoints() >= 12) continue; Cell cellUp = rowUp != null && c < rowUp.getLastCellNum() ? rowUp.getCell(c) : null; Cell cellDown = rowDown != null && c < rowDown.getLastCellNum() ? rowDown.getCell(c) : null; if (cellUp == null /*|| (cell.getCellType()!=0 && cellUp.getCellType()!=0 && cellUp.getCellType()!=cell.getCellType())*/ ) { //Border above drawLineAbove(sheet, r, c, c, (short) 1); } if (cellDown == null /*|| (cell.getCellType()!=0 && cellDown.getCellType()!=0 && cellDown.getCellType()!=cell.getCellType())*/) { //Border under drawLineUnder(sheet, r, c, c, (short) 1); } } } } } }