List of usage examples for org.apache.poi.hssf.usermodel HSSFSheet autoSizeColumn
@Override public void autoSizeColumn(int column)
This process can be relatively slow on large sheets, so this should normally only be called once per column, at the end of your processing.
From source file:com.kcs.action.report.ReportJournalSummaryAction.java
@Override public String export() throws Exception { list = service.findJournalSummaryByCriteria(DateUtil.convertDateFromJsp(dataSetDate)); getLogger().debug("exportExcel : begin..."); getLogger().debug("exportExcel : list >>> " + list); DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss"); HSSFWorkbook myWorkBook = new HSSFWorkbook(); HSSFSheet mySheet = myWorkBook.createSheet("Journal"); setFileName("Export Data Journal (Summary)" + dateFormat.format(new Date()) + "excel".concat(".xls")); if (null != list && list.size() > 0) { int rownum = 0; Row row = mySheet.createRow(rownum++); int cellnum = 0; row.createCell(cellnum++).setCellValue("JournalGroup"); row.createCell(cellnum++).setCellValue("Ccy"); row.createCell(cellnum++).setCellValue("BuyAmt"); row.createCell(cellnum++).setCellValue("SellAmt"); row.createCell(cellnum++).setCellValue("TranType"); for (Journal obj : list) { Row rowData = mySheet.createRow(rownum++); cellnum = 0;//from ww w . ja v a2s . co m rowData.createCell(cellnum++).setCellValue(obj.getJOURNAL_GROUP() + ""); rowData.createCell(cellnum++).setCellValue(obj.getCCY() + ""); rowData.createCell(cellnum++).setCellValue(obj.getBUY_AMT() + ""); rowData.createCell(cellnum++).setCellValue(obj.getSELL_AMT() + ""); rowData.createCell(cellnum++).setCellValue(obj.getTRANS_TYPE() + ""); } for (int j = 0; j < cellnum; j++) { mySheet.autoSizeColumn(j); } } ByteArrayOutputStream boas = new ByteArrayOutputStream(); myWorkBook.write(boas); setExcelStream(new ByteArrayInputStream(boas.toByteArray())); getLogger().debug("exportExcel : end..."); return "excel"; }
From source file:com.kcs.action.ReportCompareUtilizeFwdAction.java
public String export() throws Exception { logger.debug("= = = = = EXPORT = = = = ="); logger.debug("PALM : processDate >>> " + DateUtil.convertDateFromJsp(processDate) + " reportType >>> " + reportType);/*from ww w . ja va2s.c o m*/ list = reportCompareUtilizeFWDService.findWithCriteriaService(reportType, DateUtil.convertDateFromJsp(processDate)); fileType = "XLS"; HSSFWorkbook myWorkBook = new HSSFWorkbook(); HSSFSheet mySheet = myWorkBook.createSheet("Utilize_FWD"); if ("RPT_TYP1_41".equals(reportType)) { fileName = "Report_FWD_not_found_EES_(Trade_Finance)_CBS_(Remittance)_" + hidDate + ".xls"; Row rowHeader1 = mySheet.createRow(0); rowHeader1.createCell(0).setCellValue( "? FWD ? EES (Trade Finance) & CBS (Remittance)"); } else if ("RPT_TYP2_41".equals(reportType)) { fileName = "Report_EES_(Trade_Finance)_CBS_(Remittance)_not_found_FWD_" + hidDate + ".xls"; Row rowHeader1 = mySheet.createRow(0); rowHeader1.createCell(0).setCellValue( "? EES (Trade Finance) & CBS (Remittance)? FWD"); } // Cell cell1 = CellUtil.createCell(rowHeader1, 0,"? FWD ? EES (Trade Finance) & CBS (Remittance)"); // CellUtil.setAlignment(cell1, myWorkBook, CellStyle.ALIGN_CENTER); Row rowHeader2 = mySheet.createRow(1); rowHeader2.createCell(0).setCellValue(processDate); // Cell cell2 = CellUtil.createCell(rowHeader2, 1,processDate); // CellUtil.setAlignment(cell2, myWorkBook, CellStyle.ALIGN_CENTER); mySheet.addMergedRegion(new CellRangeAddress(0, //first row (0-based) 0, //last row (0-based) 0, //first column (0-based) 2 //last column (0-based) )); mySheet.addMergedRegion(new CellRangeAddress(1, //first row (0-based) 1, //last row (0-based) 0, //first column (0-based) 2 //last column (0-based) )); if (null != list && list.size() > 0) { int rownum = 2; Row row = mySheet.createRow(rownum++); int cellnum = 0; row.createCell(cellnum++).setCellValue("Curr"); row.createCell(cellnum++).setCellValue("Fi Arrg No"); row.createCell(cellnum++).setCellValue("Amount"); for (ReportCompareUtilizeFwd obj : list) { Row rowData = mySheet.createRow(rownum++); cellnum = 0; rowData.createCell(cellnum++).setCellValue(obj.getCURR() + ""); rowData.createCell(cellnum++).setCellValue(obj.getFI_ARRG_NO() + ""); rowData.createCell(cellnum++).setCellValue(obj.getAMT() + ""); } for (int j = 0; j < cellnum; j++) { mySheet.autoSizeColumn(j); } } ByteArrayOutputStream boas = new ByteArrayOutputStream(); myWorkBook.write(boas); setExcelStream(new ByteArrayInputStream(boas.toByteArray())); logger.debug("exportExcel : end..."); return "excel"; // return REPORT; }
From source file:com.lingxiang2014.ExcelView.java
License:Open Source License
public void buildExcelDocument(Map<String, Object> model, HSSFWorkbook workbook, HttpServletRequest request, HttpServletResponse response) throws Exception { Assert.notEmpty(properties);/* ww w . ja v a 2s . c o m*/ HSSFSheet sheet; if (StringUtils.isNotEmpty(sheetName)) { sheet = workbook.createSheet(sheetName); } else { sheet = workbook.createSheet(); } int rowNumber = 0; if (titles != null && titles.length > 0) { HSSFRow header = sheet.createRow(rowNumber); header.setHeight((short) 400); for (int i = 0; i < properties.length; i++) { HSSFCell cell = header.createCell(i); HSSFCellStyle cellStyle = workbook.createCellStyle(); cellStyle.setFillForegroundColor(HSSFColor.LIGHT_CORNFLOWER_BLUE.index); cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); HSSFFont font = workbook.createFont(); font.setFontHeightInPoints((short) 11); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); cellStyle.setFont(font); cell.setCellStyle(cellStyle); if (i == 0) { HSSFPatriarch patriarch = sheet.createDrawingPatriarch(); HSSFComment comment = patriarch .createComment(new HSSFClientAnchor(0, 0, 0, 0, (short) 1, 1, (short) 4, 4)); comment.setString(new HSSFRichTextString("P" + "o" + "w" + "e" + "r" + "e" + "d" + " " + "B" + "y" + " " + "S" + "H" + "O" + "P" + "+" + "+")); cell.setCellComment(comment); } if (titles.length > i && titles[i] != null) { cell.setCellValue(titles[i]); } else { cell.setCellValue(properties[i]); } if (widths != null && widths.length > i && widths[i] != null) { sheet.setColumnWidth(i, widths[i]); } else { sheet.autoSizeColumn(i); } } rowNumber++; } if (data != null) { for (Object item : data) { HSSFRow row = sheet.createRow(rowNumber); for (int i = 0; i < properties.length; i++) { HSSFCell cell = row.createCell(i); if (converters != null && converters.length > i && converters[i] != null) { Class<?> clazz = PropertyUtils.getPropertyType(item, properties[i]); ConvertUtils.register(converters[i], clazz); cell.setCellValue(BeanUtils.getProperty(item, properties[i])); ConvertUtils.deregister(clazz); if (clazz.equals(Date.class)) { DateConverter dateConverter = new DateConverter(); dateConverter.setPattern(DEFAULT_DATE_PATTERN); ConvertUtils.register(dateConverter, Date.class); } } else { cell.setCellValue(BeanUtils.getProperty(item, properties[i])); } if (rowNumber == 0 || rowNumber == 1) { if (widths != null && widths.length > i && widths[i] != null) { sheet.setColumnWidth(i, widths[i]); } else { sheet.autoSizeColumn(i); } } } rowNumber++; } } if (contents != null && contents.length > 0) { rowNumber++; for (String content : contents) { HSSFRow row = sheet.createRow(rowNumber); HSSFCell cell = row.createCell(0); HSSFCellStyle cellStyle = workbook.createCellStyle(); HSSFFont font = workbook.createFont(); font.setColor(HSSFColor.GREY_50_PERCENT.index); cellStyle.setFont(font); cell.setCellStyle(cellStyle); cell.setCellValue(content); rowNumber++; } } response.setContentType("application/force-download"); if (StringUtils.isNotEmpty(filename)) { response.setHeader("Content-disposition", "attachment; filename=" + URLEncoder.encode(filename, "UTF-8")); } else { response.setHeader("Content-disposition", "attachment"); } }
From source file:com.macleod2486.magicbuilder.BlockConstructed.java
License:Open Source License
public void getBlock(int selection) { selection--;/*from ww w . j av a 2 s .c o m*/ try { int indexAdjust = 0; int rowIndex; int numberOfSets = Integer.parseInt(NumberOfBlocks.get(selection)); int blockNameIndex = selection; selection = Integer.parseInt(IndexOfBlocks.get(selection)); String tempItem; //Various elements Document page; Element setSection; Elements row; Elements td; //Worksheet the information will be written too HSSFWorkbook block = new HSSFWorkbook(); HSSFSheet blockSet; Row infoRow; DateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy"); Date date = new Date(); while (numberOfSets > 0) { page = Jsoup.connect(tcgSite + BlockSets.get(selection + indexAdjust).toString()).get(); setSection = page.select("table").get(2); row = setSection.select("tr"); rowIndex = 1; blockSet = block.createSheet(BlockSets.get(selection + indexAdjust).toString() .replaceAll("%20", " ").replaceAll("%27", " ")); infoRow = blockSet.createRow(0); infoRow.createCell(0).setCellValue("Card Name"); infoRow.createCell(1).setCellValue("High Price"); infoRow.createCell(2).setCellValue("Medium Price"); infoRow.createCell(3).setCellValue("Low Price"); for (Element cardrow : row) { td = cardrow.select("td"); tempItem = td.get(0).text().substring(1); if (!tempItem.contains("Forest") && !tempItem.contains("Mountain") && !tempItem.contains("Swamp") && !tempItem.contains("Island") && !tempItem.contains("Plains") && !tempItem.isEmpty()) { if (td.get(5).text().length() > 2 && td.get(6).text().length() > 2 && td.get(7).text().length() > 2) { infoRow = blockSet.createRow(rowIndex); infoRow.createCell(0).setCellValue(td.get(0).text().substring(1)); infoRow.createCell(1).setCellValue(Double.parseDouble( td.get(5).text().substring(1, td.get(5).text().length() - 1).replace(",", ""))); infoRow.createCell(2).setCellValue(Double.parseDouble( td.get(6).text().substring(1, td.get(6).text().length() - 1).replace(",", ""))); infoRow.createCell(3).setCellValue(Double.parseDouble( td.get(7).text().substring(1, td.get(7).text().length() - 1).replace(",", ""))); rowIndex++; } } } blockSet.autoSizeColumn(0); blockSet.autoSizeColumn(1); blockSet.autoSizeColumn(2); indexAdjust++; numberOfSets--; } File blockFile = new File( BlockNames.get(blockNameIndex) + "-Block-" + dateFormat.format(date) + "-.xls"); FileOutputStream blockOutput = new FileOutputStream(blockFile); block.write(blockOutput); blockOutput.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.macleod2486.magicbuilder.Constructed.java
License:Open Source License
public void getCards() { try {/*w w w .j av a2 s . c o m*/ //Keeps track of the rows within the sheet as data is being written int rowNum; //Creates a excel file for the information to be stored HSSFWorkbook standard = new HSSFWorkbook(); HSSFSheet setname; Row newRow; //Various values to screen the data String clean; double highprice = 0; double mediumPrice = 0; double lowPrice = 0; String temp; //Variables to take in information Document page; Element table; Elements row; Elements item; //Variables for extra information about the set double averageHighPrice = 0; double averageMediumPrice = 0; double averageLowPrice = 0; DecimalFormat format = new DecimalFormat("#.00"); /* * Grabs the modified set values to then be used for the website url format * Not the most effecient for loop but will be modified as time goes on. */ for (int limit = 0; limit < Sets.size(); limit++) { rowNum = 0; System.out.println("\nSet name: " + Names.get(limit).toString() + "\n"); //Creates a new sheet per set after it filters out bad characters if (Names.get(limit).toString().contains(":")) { Names.set(limit, Names.get(limit).toString().replaceAll(":", "\\W")); } else if (Names.get(limit).toString().contains("/")) { Names.set(limit, Names.get(limit).replaceAll("/", "\\W")); } setname = standard.createSheet(Names.get(limit).toString()); //Sets up the initial row in the sheet newRow = setname.createRow(0); newRow.createCell(0).setCellValue("Card Name"); newRow.createCell(1).setCellValue("High Price"); newRow.createCell(2).setCellValue("Medium Price"); newRow.createCell(3).setCellValue("Low Price"); /*Each modified string value is then put in the following url to then parse the information from it. */ page = Jsoup.connect( "http://magic.tcgplayer.com/db/price_guide.asp?setname=" + Sets.get(limit).toString()) .get(); table = page.select("table").get(2); row = table.select("tr"); //Grabs each card that was selected for (Element tableRow : row) { //Gets the first row item = tableRow.select("td"); clean = item.get(0).text(); //Filters out land cards if (!clean.isEmpty()) { if (item.get(5).text().length() > 2 && item.get(6).text().length() > 2 && item.get(7).text().length() > 2) { //Creates new row in the sheet newRow = setname.createRow(rowNum + 1); //Gets the name of the card clean = clean.substring(1); newRow.createCell(0).setCellValue(clean); //This gets the high price temp = item.get(5).text(); highprice = removeCommas(temp.substring(1, temp.length() - 2)); newRow.createCell(1).setCellValue(highprice); averageHighPrice += highprice; //This gets the medium price temp = item.get(6).text(); mediumPrice = removeCommas(temp.substring(1, temp.length() - 2)); newRow.createCell(2).setCellValue(mediumPrice); averageMediumPrice += mediumPrice; //This gets the low price temp = item.get(7).text(); lowPrice = removeCommas(temp.substring(1, temp.length() - 2)); newRow.createCell(3).setCellValue(lowPrice); averageLowPrice += lowPrice; System.out.println( clean + " H:$" + highprice + " M:$" + mediumPrice + " L:$" + lowPrice); rowNum++; } } } if (Double.isNaN(averageHighPrice) && Double.isNaN(averageMediumPrice) && Double.isNaN(averageLowPrice)) { //Finds the averages averageHighPrice /= rowNum; averageMediumPrice /= rowNum; averageLowPrice /= rowNum; //Formats them averageHighPrice = Double.parseDouble(format.format(averageHighPrice)); averageMediumPrice = Double.parseDouble(format.format(averageMediumPrice)); averageLowPrice = Double.parseDouble(format.format(averageLowPrice)); //Inserts the values into the table newRow = setname.getRow(0); newRow.createCell(4).setCellValue("Average High Price"); newRow.createCell(5).setCellValue("Average Medium Price"); newRow.createCell(6).setCellValue("Average Low Price"); newRow = setname.getRow(1); newRow.createCell(4).setCellValue(averageHighPrice); newRow.createCell(5).setCellValue(averageMediumPrice); newRow.createCell(6).setCellValue(averageLowPrice); System.out.println("Average Prices " + averageHighPrice + " " + averageMediumPrice + " " + averageLowPrice); } //Zeroes them out averageHighPrice = averageMediumPrice = averageLowPrice = 0; //Sets the sheet to auto size columns for (int index = 0; index < 7; index++) { setname.autoSizeColumn(index); } } //Creates the date to be added in the output file name. DateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy"); Date date = new Date(); if (this.selection == 0) { File standardFile = new File("Standard-" + dateFormat.format(date) + "-.xls"); FileOutputStream standardOutput = new FileOutputStream(standardFile); standard.write(standardOutput); standardOutput.close(); } else if (this.selection == 1) { File standardFile = new File("Modern-" + dateFormat.format(date) + "-.xls"); FileOutputStream standardOutput = new FileOutputStream(standardFile); standard.write(standardOutput); standardOutput.close(); } else { File standardFile = new File("All-" + dateFormat.format(date) + "-.xls"); FileOutputStream standardOutput = new FileOutputStream(standardFile); standard.write(standardOutput); standardOutput.close(); } } catch (Exception e) { e.printStackTrace(); if (e.toString().contains("Status=400")) { System.out.println("That webpage does not exist!"); } else if (e.toString().contains("SocketTimeout")) { System.out.println("Your connection timed out"); } } }
From source file:com.mss.mirage.employee.general.EmployeeServiceImpl.java
License:Open Source License
public String generateEmployeeList(String loginId) { DateUtility dateutility = new DateUtility(); String filePath = ""; StringBuffer sb = null;//ww w .j a va 2 s .c o m Connection connection = null; /** callableStatement is a reference variable for CallableStatement . */ CallableStatement callableStatement = null; /** preStmt,preStmtTemp are reference variable for PreparedStatement . */ PreparedStatement preStmt = null, preStmtTemp = null; /** The queryString is useful to get queryString result to the particular jsp page */ String queryString = ""; Statement statement = null; /** The statement is useful to execute the above queryString */ ResultSet resultSet = null; String timeSheetStatus = ""; HashMap map = null; HashMap map1 = null; List finalList = new ArrayList(); try { String TABLE_EMP_STATE_HISTORY = Properties.getProperty("TABLE_EMP_STATE_HISTORY"); File file = new File(Properties.getProperty("Emp.StateHistory.Path")); if (!file.exists()) { file.mkdirs(); } FileOutputStream fileOut = new FileOutputStream( file.getAbsolutePath() + File.separator + loginId + "_StateHistory.xls"); connection = ConnectionProvider.getInstance().getConnection(); String query = null; // query = "SELECT * FROM tblEmpStateHistory WHERE LoginId='"+loginId+"' ORDER BY StartDate DESC"; query = "SELECT * FROM " + TABLE_EMP_STATE_HISTORY + " WHERE LoginId='" + loginId + "' ORDER BY StartDate DESC"; // System.out.println("query123-->"+query); String reportToName = ""; List teamList = null; int j = 1; preStmt = connection.prepareStatement(query); resultSet = preStmt.executeQuery(); while (resultSet.next()) { String state = ""; if (!"".equals(resultSet.getString("State")) && resultSet.getString("State") != null) { state = resultSet.getString("State"); } double IntRatePerHour = resultSet.getFloat("IntRatePerHour"); double InvRatePerHour = resultSet.getFloat("InvRatePerHour"); String LoginId = resultSet.getString("LoginId"); String SkillSet = ""; if (!"".equals(resultSet.getString("SkillSet")) && resultSet.getString("SkillSet") != null) { SkillSet = resultSet.getString("SkillSet"); } String EndDate = ""; if (!"".equals(resultSet.getString("EndDate")) && resultSet.getString("EndDate") != null) { EndDate = resultSet.getString("EndDate"); } String StartDate = ""; if (!"".equals(resultSet.getString("StartDate")) && resultSet.getString("StartDate") != null) { StartDate = resultSet.getString("StartDate"); } String CreatedDate = ""; if (!"".equals(resultSet.getString("CreatedDate")) && resultSet.getString("CreatedDate") != null) { CreatedDate = resultSet.getString("CreatedDate"); } String PrjName = ""; if (!"".equals(resultSet.getString("PrjName")) && resultSet.getString("PrjName") != null) { PrjName = resultSet.getString("PrjName"); } String reportsTo = ""; map = new HashMap(); map.put("SNO", String.valueOf(j)); map.put("state", state); map.put("IntRatePerHour", IntRatePerHour); map.put("InvRatePerHour", InvRatePerHour); map.put("LoginId", LoginId); map.put("SkillSet", SkillSet); map.put("EndDate", EndDate); map.put("StartDate", StartDate); map.put("CreatedDate", CreatedDate); map.put("PrjName", PrjName); //System.out.println("map=="+map); finalList.add(map); j++; } if (finalList.size() > 0) { filePath = file.getAbsolutePath() + File.separator + loginId + "_StateHistory.xls"; HSSFWorkbook hssfworkbook = new HSSFWorkbook(); HSSFSheet sheet = hssfworkbook.createSheet("State History"); HSSFCellStyle cs = hssfworkbook.createCellStyle(); HSSFCellStyle headercs = hssfworkbook.createCellStyle(); headercs.setFillForegroundColor(HSSFColor.BLACK.index); headercs.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); headercs.setBorderTop((short) 1); // single line border headercs.setBorderBottom((short) 1); // single line border HSSFFont timesBoldFont = hssfworkbook.createFont(); timesBoldFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); timesBoldFont.setColor(HSSFColor.WHITE.index); timesBoldFont.setFontName("Arial"); headercs.setFont(timesBoldFont); HSSFFont footerFont = hssfworkbook.createFont(); footerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); footerFont.setFontName("Arial"); HSSFCellStyle footercs = hssfworkbook.createCellStyle(); footercs.setFont(footerFont); HSSFDataFormat df = hssfworkbook.createDataFormat(); HSSFRow row = sheet.createRow((short) 0); HSSFCell cell = row.createCell((short) 0); HSSFCell cell1 = row.createCell((short) 1); HSSFCell cell2 = row.createCell((short) 2); HSSFCell cell3 = row.createCell((short) 3); HSSFCell cell4 = row.createCell((short) 4); HSSFCell cell5 = row.createCell((short) 5); HSSFCell cell6 = row.createCell((short) 6); HSSFCell cell7 = row.createCell((short) 7); HSSFCell cell8 = row.createCell((short) 8); cell.setCellValue("SNO"); cell1.setCellValue("State"); cell2.setCellValue("StartDate"); cell3.setCellValue("EndDate"); cell4.setCellValue("IntRatePerHour"); cell5.setCellValue("InvRatePerHour"); cell6.setCellValue("SkillSet"); cell7.setCellValue("ProjectName"); cell8.setCellValue("CreatedDate"); cell.setCellStyle(headercs); cell1.setCellStyle(headercs); cell2.setCellStyle(headercs); cell3.setCellStyle(headercs); cell4.setCellStyle(headercs); cell5.setCellStyle(headercs); cell6.setCellStyle(headercs); cell7.setCellStyle(headercs); cell8.setCellStyle(headercs); int count = 1; if (finalList.size() > 0) { Map stateHistorylMap = null; for (int i = 0; i < finalList.size(); i++) { stateHistorylMap = (Map) finalList.get(i); row = sheet.createRow((short) count++); cell = row.createCell((short) 0); cell1 = row.createCell((short) 1); cell2 = row.createCell((short) 2); cell3 = row.createCell((short) 3); cell4 = row.createCell((short) 4); cell5 = row.createCell((short) 5); cell6 = row.createCell((short) 6); cell7 = row.createCell((short) 7); cell8 = row.createCell((short) 8); cell.setCellValue((String) stateHistorylMap.get("SNO")); cell1.setCellValue((String) stateHistorylMap.get("state")); cell2.setCellValue((String) stateHistorylMap.get("StartDate")); cell3.setCellValue((String) stateHistorylMap.get("EndDate")); cell4.setCellValue((Double) stateHistorylMap.get("IntRatePerHour")); cell5.setCellValue((Double) stateHistorylMap.get("InvRatePerHour")); cell6.setCellValue((String) stateHistorylMap.get("SkillSet")); cell7.setCellValue((String) stateHistorylMap.get("PrjName")); cell8.setCellValue((String) stateHistorylMap.get("CreatedDate")); cell.setCellStyle(cs); cell1.setCellStyle(cs); cell2.setCellStyle(cs); cell3.setCellStyle(cs); cell4.setCellStyle(cs); cell5.setCellStyle(cs); cell6.setCellStyle(cs); cell7.setCellStyle(cs); cell8.setCellStyle(cs); } row = sheet.createRow((short) count++); cell = row.createCell((short) 0); cell1 = row.createCell((short) 1); cell2 = row.createCell((short) 2); cell3 = row.createCell((short) 3); cell4 = row.createCell((short) 4); cell.setCellValue(""); cell4.setCellValue(""); cell.setCellStyle(footercs); cell1.setCellStyle(footercs); cell2.setCellStyle(footercs); cell3.setCellStyle(footercs); cell4.setCellStyle(footercs); } sheet.autoSizeColumn((int) 0); sheet.autoSizeColumn((int) 1); sheet.autoSizeColumn((int) 2); sheet.autoSizeColumn((int) 3); sheet.autoSizeColumn((int) 4); hssfworkbook.write(fileOut); fileOut.flush(); fileOut.close(); } } catch (FileNotFoundException fne) { fne.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); } finally { System.out.println("finally"); try { if (resultSet != null) { resultSet.close(); resultSet = null; } if (preStmt != null) { preStmt.close(); preStmt = null; } if (connection != null) { connection.close(); connection = null; } } catch (Exception se) { se.printStackTrace(); } } return filePath; }
From source file:com.mss.mirage.marketing.MarketingServiceImpl.java
License:Open Source License
public String generateInvestmentXls(String queryString) throws ServiceLocatorException { String filePath = ""; StringBuffer sb = null;// w w w. j a va 2 s. co m Connection connection = null; /** * preStmt,preStmtTemp are reference variable for PreparedStatement . */ PreparedStatement preStmt = null; /** * The queryString is useful to get queryString result to the particular * jsp page */ /** * The statement is useful to execute the above queryString */ ResultSet resultSet = null; HashMap map = null; double totalAmount = 0.0; double totalOpprtunity = 0.0; double floortotalsum = 0.0; String generatedPath = ""; List finalList = new ArrayList(); try { generatedPath = com.mss.mirage.util.Properties.getProperty("Marketing.Investment.Path"); File file = new File(generatedPath); if (!file.exists()) { file.mkdirs(); } FileOutputStream fileOut = new FileOutputStream(file.getAbsolutePath() + "/Investment.xls"); connection = ConnectionProvider.getInstance().getConnection(); String query = null; if (!"".equals(queryString)) { query = queryString; } else { query = "SELECT * from vwInvestments WHERE STATUS='Active' ORDER BY createdDate DESC"; } String reportToName = ""; List teamList = null; int j = 1; // System.out.println("query...."+query); preStmt = connection.prepareStatement(query); resultSet = preStmt.executeQuery(); while (resultSet.next()) { String InvestmentName = resultSet.getString("Inv_Name"); String TotalExpenses = resultSet.getString("TotalExpenses"); String StartDate = resultSet.getString("StartDate"); String EndDate = resultSet.getString("EndDate"); String Location = resultSet.getString("Location"); String InvestmentType = resultSet.getString("InvestmentType"); String TotalOpprtunity = resultSet.getString("TotalOpprtunity"); totalAmount = totalAmount + resultSet.getDouble("TotalExpenses"); totalOpprtunity = totalOpprtunity + resultSet.getDouble("TotalOpprtunity"); map = new HashMap(); map.put("SNO", String.valueOf(j)); map.put("InvestmentName", InvestmentName); map.put("TotalExpenses", TotalExpenses); map.put("StartDate", StartDate); map.put("EndDate", EndDate); map.put("Location", Location); if ("S".equalsIgnoreCase(InvestmentType)) { map.put("InvestmentType", "Lead Source"); } else if ("P".equalsIgnoreCase(InvestmentType)) { map.put("InvestmentType", "Lead Pass"); } map.put("TotalOpprtunity", TotalOpprtunity); map.put("Sum", totalAmount); map.put("SumOpp", totalOpprtunity); finalList.add(map); j++; } if (finalList.size() > 0) { filePath = file.getAbsolutePath() + "/Investment.xls"; HSSFWorkbook hssfworkbook = new HSSFWorkbook(); HSSFSheet sheet = hssfworkbook.createSheet("Investment Sheet"); HSSFFont timesBoldFont1 = hssfworkbook.createFont(); timesBoldFont1.setFontHeightInPoints((short) 13); timesBoldFont1.setColor(HSSFColor.BLACK.index); timesBoldFont1.setFontName("Arial"); HSSFCellStyle cellColor = hssfworkbook.createCellStyle(); cellColor.setFillForegroundColor(HSSFColor.GREY_40_PERCENT.index); cellColor.setAlignment(HSSFCellStyle.ALIGN_LEFT); cellColor.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); cellColor.setBorderTop((short) 1); // single line border cellColor.setBorderBottom((short) 1); // single line border cellColor.setFont(timesBoldFont1); HSSFCellStyle cellColor1 = hssfworkbook.createCellStyle(); cellColor1.setFillForegroundColor(HSSFColor.WHITE.index); cellColor1.setAlignment(HSSFCellStyle.ALIGN_LEFT); cellColor1.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); cellColor1.setBorderTop((short) 1); // single line border cellColor1.setBorderBottom((short) 1); // single line border cellColor1.setFont(timesBoldFont1); HSSFCellStyle cs = hssfworkbook.createCellStyle(); HSSFCellStyle headercs = hssfworkbook.createCellStyle(); headercs.setFillForegroundColor(HSSFColor.BLUE.index); headercs.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); headercs.setBorderTop((short) 1); // single line border headercs.setBorderBottom((short) 1); // single line border // cs.setFont(timesBoldFont1); HSSFFont timesBoldFont = hssfworkbook.createFont(); timesBoldFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); timesBoldFont.setFontHeightInPoints((short) 13); timesBoldFont.setColor(HSSFColor.WHITE.index); timesBoldFont.setFontName("Calibri"); headercs.setFont(timesBoldFont); // cs.setFont(timesBoldFont); HSSFFont footerFont = hssfworkbook.createFont(); footerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); timesBoldFont.setFontHeightInPoints((short) 13); footerFont.setFontName("Calibri"); HSSFCellStyle footercs = hssfworkbook.createCellStyle(); footercs.setFont(footerFont); HSSFDataFormat df = hssfworkbook.createDataFormat(); HSSFRow row = sheet.createRow((short) 0); HSSFCell cell = row.createCell((short) 0); HSSFCell cell1 = row.createCell((short) 1); HSSFCell cell2 = row.createCell((short) 2); HSSFCell cell3 = row.createCell((short) 3); HSSFCell cell4 = row.createCell((short) 4); HSSFCell cell5 = row.createCell((short) 5); HSSFCell cell6 = row.createCell((short) 6); HSSFCell cell7 = row.createCell((short) 7); cell.setCellValue("SNO"); cell1.setCellValue("InvestmentName"); cell2.setCellValue("TotalExpenses"); cell3.setCellValue("StartDate"); cell4.setCellValue("EndDate"); cell5.setCellValue("Location"); cell6.setCellValue("InvestmentType"); cell7.setCellValue("TotalOpprtunity"); cell.setCellStyle(headercs); cell1.setCellStyle(headercs); cell2.setCellStyle(headercs); cell3.setCellStyle(headercs); cell4.setCellStyle(headercs); cell5.setCellStyle(headercs); cell6.setCellStyle(headercs); cell7.setCellStyle(headercs); int count = 1; if (finalList.size() > 0) { Map stateHistorylMap = null; for (int i = 0; i < finalList.size(); i++) { stateHistorylMap = (Map) finalList.get(i); row = sheet.createRow((short) count++); cell = row.createCell((short) 0); cell1 = row.createCell((short) 1); cell2 = row.createCell((short) 2); cell3 = row.createCell((short) 3); cell4 = row.createCell((short) 4); cell5 = row.createCell((short) 5); cell6 = row.createCell((short) 6); cell7 = row.createCell((short) 7); cell.setCellValue((String) stateHistorylMap.get("SNO")); cell1.setCellValue((String) stateHistorylMap.get("InvestmentName")); HSSFCellStyle css1 = hssfworkbook.createCellStyle(); HSSFCellStyle css2 = hssfworkbook.createCellStyle(); css1.setFillForegroundColor(HSSFColor.GREY_40_PERCENT.index); css1.setAlignment(HSSFCellStyle.ALIGN_LEFT); css1.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); css1.setBorderTop((short) 1); // single line border css1.setBorderBottom((short) 1); // single line border css1.setFont(timesBoldFont1); HSSFDataFormat df1 = hssfworkbook.createDataFormat(); css1.setDataFormat(df1.getFormat("#,##0.0")); css2.setDataFormat(df1.getFormat("#,##0.0")); css2.setAlignment(HSSFCellStyle.ALIGN_LEFT); css2.setFont(timesBoldFont1); cell2.setCellValue(Convert.toDouble(stateHistorylMap.get("TotalExpenses"))); cell3.setCellValue((String) stateHistorylMap.get("StartDate")); cell4.setCellValue((String) stateHistorylMap.get("EndDate")); cell5.setCellValue((String) stateHistorylMap.get("Location")); cell6.setCellValue((String) stateHistorylMap.get("InvestmentType")); cell7.setCellValue((String) stateHistorylMap.get("TotalOpprtunity")); if (count % 2 == 0) { cell.setCellStyle(cellColor1); cell1.setCellStyle(cellColor1); cell2.setCellStyle(css2); cell3.setCellStyle(cellColor1); cell4.setCellStyle(cellColor1); cell5.setCellStyle(cellColor1); cell6.setCellStyle(cellColor1); cell7.setCellStyle(cellColor1); } else { cell.setCellStyle(cellColor); cell1.setCellStyle(cellColor); cell2.setCellStyle(css1); cell3.setCellStyle(cellColor); cell4.setCellStyle(cellColor); cell5.setCellStyle(cellColor); cell6.setCellStyle(cellColor); cell7.setCellStyle(cellColor); } } row = sheet.createRow((short) count++); cell = row.createCell((short) 0); cell1 = row.createCell((short) 1); cell2 = row.createCell((short) 2); cell3 = row.createCell((short) 3); cell4 = row.createCell((short) 4); cell5 = row.createCell((short) 5); cell6 = row.createCell((short) 6); cell7 = row.createCell((short) 7); cell.setCellValue(""); cell7.setCellValue(""); cell.setCellStyle(footercs); cell1.setCellStyle(footercs); cell2.setCellStyle(footercs); cell3.setCellStyle(footercs); cell4.setCellStyle(footercs); cell5.setCellStyle(footercs); cell6.setCellStyle(footercs); cell7.setCellStyle(footercs); } HSSFCellStyle totalSum = hssfworkbook.createCellStyle(); totalSum.setFillForegroundColor(HSSFColor.LIGHT_GREEN.index); totalSum.setAlignment(HSSFCellStyle.ALIGN_LEFT); totalSum.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); totalSum.setBorderTop((short) 1); // single line border totalSum.setBorderBottom((short) 1); // single line border totalSum.setFont(timesBoldFont1); HSSFCellStyle totalSum1 = hssfworkbook.createCellStyle(); totalSum1.setFillForegroundColor(HSSFColor.LIGHT_GREEN.index); totalSum1.setAlignment(HSSFCellStyle.ALIGN_RIGHT); totalSum1.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); totalSum1.setBorderTop((short) 1); // single line border totalSum1.setBorderBottom((short) 1); // single line border totalSum1.setFont(timesBoldFont1); HSSFDataFormat totalSumdf1 = hssfworkbook.createDataFormat(); totalSum.setDataFormat((short) 7); HSSFCellStyle test = hssfworkbook.createCellStyle(); HSSFDataFormat testdf = hssfworkbook.createDataFormat(); sheet.autoSizeColumn((int) 0); sheet.autoSizeColumn((int) 3); sheet.autoSizeColumn((int) 4); sheet.setColumnWidth(1, 50 * 256); sheet.setColumnWidth(2, 35 * 256); sheet.setColumnWidth(5, 25 * 256); sheet.setColumnWidth(6, 25 * 256); sheet.setColumnWidth(7, 25 * 256); BigDecimal bb, bc, cc, cd; bb = new BigDecimal(totalAmount); bc = bb.setScale(2, RoundingMode.CEILING); cc = new BigDecimal(totalOpprtunity); cd = cc.setScale(2, RoundingMode.CEILING); totalSum.setDataFormat(testdf.getFormat("#,##0.0")); cell.setCellStyle(totalSum); cell1.setCellValue("Sum "); cell1.setCellStyle(totalSum1); cell2.setCellValue(bc.longValue()); cell2.setCellStyle(totalSum); cell3.setCellStyle(totalSum); cell4.setCellStyle(totalSum); cell5.setCellStyle(totalSum); cell6.setCellStyle(totalSum); cell7.setCellValue(cd.longValue()); cell7.setCellStyle(totalSum); hssfworkbook.write(fileOut); fileOut.flush(); fileOut.close(); } } catch (FileNotFoundException fne) { fne.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); } finally { try { if (resultSet != null) { resultSet.close(); resultSet = null; } if (preStmt != null) { preStmt.close(); preStmt = null; } if (connection != null) { connection.close(); connection = null; } } catch (Exception se) { se.printStackTrace(); } } return filePath; }
From source file:com.nokia.s60tools.swmtanalyser.model.ExcelCreator.java
License:Open Source License
private boolean createOverViewTab() { //create a new sheet HSSFSheet sheet = wb.createSheet(); // declare a row object reference HSSFRow row = null;//from w w w .j av a2s. co m // declare a cell object reference HSSFCell cell = null; //set the sheet name in Unicode wb.setSheetName(0, "Overview"); row = sheet.createRow(0); //r.setHeight((short)500); cell = row.createCell(0); cell.setCellStyle(styles.get("header")); cell.setCellValue(new HSSFRichTextString("Overview")); row = sheet.createRow(1); cell = row.createCell(0); cell.setCellValue(new HSSFRichTextString("Number of Cycles")); cell = row.createCell(1); cell.setCellStyle(styles.get("cell_number")); CycleData firstCycle = logData.getLogData()[0]; if (ovData.noOfcycles == 1) cell.setCellValue(new HSSFRichTextString(ovData.noOfcycles + " (" + firstCycle.getCycleNumber() + ")")); else cell.setCellValue(ovData.noOfcycles); row = sheet.createRow(2); cell = row.createCell(0); cell.setCellValue(new HSSFRichTextString("Number of Cycles Truncated")); cell = row.createCell(1); cell.setCellValue(constants.size()); row = sheet.createRow(3); cell = row.createCell(0); cell.setCellValue(new HSSFRichTextString("Time Period")); HSSFCell timePeriod = row.createCell(1); row = sheet.createRow(4); cell = row.createCell(0); cell.setCellValue(new HSSFRichTextString("Time Duration")); cell = row.createCell(1); cell.setCellValue(new HSSFRichTextString(ovData.duration + " sec(" + ovData.durationString + ")")); row = sheet.createRow(5); cell = row.createCell(0); cell.setCellValue(new HSSFRichTextString("ROM Checksum")); cell = row.createCell(1); cell.setCellValue(new HSSFRichTextString(firstCycle.getRomCheckSum())); row = sheet.createRow(6); cell = row.createCell(0); cell.setCellValue(new HSSFRichTextString("ROM Version")); cell = row.createCell(1); cell.setCellValue(new HSSFRichTextString(firstCycle.getRomVersion())); sheet.createRow(7); sheet.createRow(8); sheet.createRow(9); row = sheet.createRow(10); cell = row.createCell(0); cell.setCellStyle(styles.get("header2")); cell.setCellValue(new HSSFRichTextString("")); cell = row.createCell(1); cell.setCellStyle(styles.get("header2")); cell.setCellValue(new HSSFRichTextString("Delta")); HSSFRow totalHeapSizeRow = sheet.createRow(11); cell = totalHeapSizeRow.createCell(0); cell.setCellStyle(styles.get("cell_bold")); cell.setCellValue(new HSSFRichTextString("Heap Size")); HSSFRow freeCellRow = sheet.createRow(12); cell = freeCellRow.createCell(0); cell.setCellStyle(styles.get("cell_bold")); cell.setCellValue(new HSSFRichTextString("Free Cell count")); HSSFRow alloCellRow = sheet.createRow(13); cell = alloCellRow.createCell(0); cell.setCellStyle(styles.get("cell_bold")); cell.setCellValue(new HSSFRichTextString("Allocated Cell count")); HSSFRow freeSpaceRow = sheet.createRow(14); cell = freeSpaceRow.createCell(0); cell.setCellStyle(styles.get("cell_bold")); cell.setCellValue(new HSSFRichTextString("Free space")); HSSFRow allocSpaceRow = sheet.createRow(15); cell = allocSpaceRow.createCell(0); cell.setCellStyle(styles.get("cell_bold")); cell.setCellValue(new HSSFRichTextString("Allocated space")); HSSFRow slackSpaceRow = sheet.createRow(16); cell = slackSpaceRow.createCell(0); cell.setCellStyle(styles.get("cell_bold")); cell.setCellValue(new HSSFRichTextString("Slack space")); HSSFRow filesRow = sheet.createRow(17); cell = filesRow.createCell(0); cell.setCellStyle(styles.get("cell_bold")); cell.setCellValue(new HSSFRichTextString("Total files")); HSSFRow psHandlesRow = sheet.createRow(18); cell = psHandlesRow.createCell(0); cell.setCellStyle(styles.get("cell_bold")); cell.setCellValue(new HSSFRichTextString("Total P&S Handles")); sheet.createRow(19); sheet.createRow(20); sheet.createRow(21); sheet.createRow(22); row = sheet.createRow(23); createOverviewFields(row); createDataInOverView(sheet, 24); cell = totalHeapSizeRow.createCell(1); cell.setCellStyle(styles.get("blue_font")); cell.setCellValue(totalHeapSizeChange); cell = freeCellRow.createCell(1); cell.setCellStyle(styles.get("blue_font")); cell.setCellValue(totalFreeCellChange); cell = alloCellRow.createCell(1); cell.setCellStyle(styles.get("blue_font")); cell.setCellValue(totalAllocCellChange); cell = freeSpaceRow.createCell(1); cell.setCellStyle(styles.get("blue_font")); cell.setCellValue(totalFreeSpaceChange); cell = allocSpaceRow.createCell(1); cell.setCellStyle(styles.get("blue_font")); cell.setCellValue(totalAllocSpaceChange); cell = slackSpaceRow.createCell(1); cell.setCellStyle(styles.get("blue_font")); cell.setCellValue(totalSlackSpaceChange); cell = filesRow.createCell(1); cell.setCellStyle(styles.get("blue_font")); cell.setCellValue(totalFilesChange); cell = psHandlesRow.createCell(1); cell.setCellStyle(styles.get("blue_font")); cell.setCellValue(totalHandlesChange); sheet.autoSizeColumn((short) 0); sheet.autoSizeColumn((short) 1); sheet.autoSizeColumn((short) 2); sheet.autoSizeColumn((short) 3); sheet.autoSizeColumn((short) 4); sheet.autoSizeColumn((short) 5); sheet.autoSizeColumn((short) 6); sheet.autoSizeColumn((short) 7); sheet.autoSizeColumn((short) 8); sheet.autoSizeColumn((short) 9); sheet.autoSizeColumn((short) 10); sheet.autoSizeColumn((short) 11); if (ovData.noOfcycles > 1) timePeriod.setCellValue(new HSSFRichTextString(ovData.fromTime + " to " + ovData.toTime)); else timePeriod.setCellValue(new HSSFRichTextString(ovData.fromTime)); return true; }
From source file:com.nokia.s60tools.swmtanalyser.model.ExcelCreator.java
License:Open Source License
/** * This method creates the sheet for RAM and DISK Memory data. * It shows the variation of RAM and Disk Memory in each cycle. * *//* w ww.java 2 s . c o m*/ private void createDiskVariationSheet() { //create a new sheet HSSFSheet sheet = wb.createSheet(); // declare a row object reference HSSFRow row = null; HSSFRow description = null; // declare a cell object reference HSSFCell cell = null; //set the sheet name in Unicode wb.setSheetName(1, "RAM and Disk Memory"); row = sheet.createRow(0); //r.setHeight((short)500); cell = row.createCell(0); cell.setCellStyle(styles.get("header")); cell.setCellValue(new HSSFRichTextString("RAM and Disk Memory")); description = sheet.createRow(1); //creates an empty row row = sheet.createRow(2); row = sheet.createRow(3); cell = row.createCell(0); cell.setCellStyle(styles.get("header2")); cell.setCellValue(new HSSFRichTextString("")); addCycleIntervals(row); cell = row.createCell((int) (row.getLastCellNum())); cell.setCellStyle(styles.get("header2")); cell.setCellValue(new HSSFRichTextString("Delta")); SWMTLogReaderUtils utils = new SWMTLogReaderUtils(); ArrayList<String> diskNames = utils.getAllDiskNames(logData); int rowNo = 4; row = sheet.createRow(rowNo); cell = row.createCell(0); cell.setCellStyle(styles.get("cell_normal")); cell.setCellValue(new HSSFRichTextString("RAM (Used)")); ArrayList<SystemData> systemData = utils.getSystemDataFromAllCycles(logData); long[] usedMemValues = new long[logData.getNumberOfCycles()]; j = 1; for (int i = 0; i < logData.getNumberOfCycles(); i++) { long totalMem = systemData.get(i).getTotalMemory(); long freeMem = systemData.get(i).getFreeMemory(); if (totalMem == -1 || freeMem == -1) { //cell.getCellStyle().setAlignment(HSSFCellStyle.ALIGN_CENTER); usedMemValues[i] = -1; } else { long usedMemory = totalMem - freeMem; usedMemValues[i] = usedMemory; } if (constants.contains(i + 1)) continue; cell = row.createCell(j++); cell.setCellStyle(styles.get("cell_number")); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); if (usedMemValues[i] == -1) cell.setCellValue(new HSSFRichTextString(NOT_AVAILABLE)); else cell.setCellValue(usedMemValues[i]); //cell.setCellValue(logData.get(i).getFreeMemory()); } cell = row.createCell(logData.getNumberOfCycles() + 1 - constants.size()); cell.setCellStyle(styles.get("cell_number")); long usedMemChange = utils.calculateDeltaForGivenSet(usedMemValues); cell.setCellValue(usedMemChange); /*cell = row.createCell(logData.size()+1); cell.setCellStyle(styles.get("cell_number")); long firstCycleValue = logData.get(0).getFreeMemory(); long lastCycleValue = logData.get(logData.size()-1).getFreeMemory(); if(firstCycleValue!= -1 && lastCycleValue!= -1) cell.setCellValue(lastCycleValue - firstCycleValue); else{ //cell.getCellStyle().setAlignment(HSSFCellStyle.ALIGN_CENTER); cell.setCellValue(new HSSFRichTextString(NOT_AVAILABLE)); }*/ rowNo++; row = sheet.createRow(rowNo); cell = row.createCell(0); cell.setCellStyle(styles.get("cell_normal")); cell.setCellValue(new HSSFRichTextString("RAM (Size)")); long[] totalMemValues = new long[logData.getNumberOfCycles()]; j = 1; for (int i = 0; i < logData.getNumberOfCycles(); i++) { long totalMem = systemData.get(i).getTotalMemory(); if (totalMem == -1) { totalMemValues[i] = -1; } else { totalMemValues[i] = totalMem; } //cell.setCellValue(logData.get(i).getFreeMemory()); if (constants.contains(i + 1)) continue; cell = row.createCell(j++); cell.setCellStyle(styles.get("cell_number")); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); if (totalMemValues[i] == -1) cell.setCellValue(new HSSFRichTextString(NOT_AVAILABLE)); else cell.setCellValue(totalMemValues[i]); } cell = row.createCell(logData.getNumberOfCycles() + 1 - constants.size()); cell.setCellStyle(styles.get("cell_number")); long totalMemChange = utils.calculateDeltaForGivenSet(totalMemValues); cell.setCellValue(totalMemChange); Collections.sort(diskNames); for (String name : diskNames) { rowNo++; row = sheet.createRow(rowNo); cell = row.createCell(0); cell.setCellStyle(styles.get("cell_normal")); cell.setCellValue(new HSSFRichTextString(name + " (Used)")); ArrayList<DiskOverview> values = utils.getUsedMemoryAndSizesForDisk(name, logData); long[] usedSizes = new long[values.size()]; j = 1; for (int i = 0; i < values.size(); i++) { if (constants.contains(i + 1)) continue; cell = row.createCell(j++); cell.setCellStyle(styles.get("cell_number")); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); long usedSize = values.get(i).getUsedSize(); if (usedSize == -1) { //cell.getCellStyle().setAlignment(HSSFCellStyle.ALIGN_CENTER); cell.setCellValue(new HSSFRichTextString(NOT_AVAILABLE)); } else cell.setCellValue(usedSize); usedSizes[i] = usedSize; } cell = row.createCell(logData.getNumberOfCycles() + 1 - constants.size()); cell.setCellStyle(styles.get("cell_number")); long deltaValue = utils.calculateDeltaForGivenSet(usedSizes); cell.setCellValue(deltaValue); rowNo++; row = sheet.createRow(rowNo); cell = row.createCell(0); cell.setCellStyle(styles.get("cell_normal")); cell.setCellValue(new HSSFRichTextString(name + " (Size)")); long[] sizeValues = new long[values.size()]; j = 1; for (int i = 0; i < values.size(); i++) { if (constants.contains(i + 1)) continue; cell = row.createCell(j++); cell.setCellStyle(styles.get("cell_number")); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); long size = values.get(i).getSize(); if (size == -1) { //cell.getCellStyle().setAlignment(HSSFCellStyle.ALIGN_CENTER); cell.setCellValue(new HSSFRichTextString(NOT_AVAILABLE)); } else cell.setCellValue(size); sizeValues[i] = size; } cell = row.createCell(logData.getNumberOfCycles() + 1 - constants.size()); cell.setCellStyle(styles.get("cell_number")); long sizeDelta = utils.calculateDeltaForGivenSet(sizeValues); cell.setCellValue(sizeDelta); } for (int i = 0; i <= logData.getNumberOfCycles(); i++) { sheet.autoSizeColumn((short) i); } cell = description.createCell(0); cell.setCellValue(new HSSFRichTextString( "Specifies the amount of used RAM and disk memories of all drives in bytes, for each cycle in seconds")); }
From source file:com.nokia.s60tools.swmtanalyser.model.ExcelCreator.java
License:Open Source License
private void createHeapSizeTab() { HSSFSheet sheet = wb.createSheet(); // declare a row object reference HSSFRow row = null;/*w w w. j a v a2 s. c o m*/ HSSFRow description = null; // declare a cell object reference HSSFCell cell = null; //set the sheet name in Unicode wb.setSheetName(4, "Total Heap Size"); row = sheet.createRow(0); //r.setHeight((short)500); cell = row.createCell(0); cell.setCellStyle(styles.get("header")); cell.setCellValue(new HSSFRichTextString("Total Heap Size")); description = sheet.createRow(1); //creates an empty row. row = sheet.createRow(2); row = sheet.createRow(3); cell = row.createCell(0); cell.setCellStyle(styles.get("header1")); cell.setCellValue(new HSSFRichTextString("Threads")); addCycleIntervals(row); cell = row.createCell((int) row.getLastCellNum()); cell.setCellStyle(styles.get("header2")); cell.setCellValue(new HSSFRichTextString("Delta")); int rowNo = 4; for (String heap : heapThreads) { row = sheet.createRow(rowNo); cell = row.createCell(0); cell.setCellStyle(styles.get("cell_normal")); cell.setCellValue(new HSSFRichTextString(heap)); ArrayList<ThreadData> heapValues = heapData.get(heap.toLowerCase()); if (heapValues != null) { int j = 1; for (int i = 0; i < heapValues.size(); i++) { if (constants.contains(i + 1)) { if (heap.equalsIgnoreCase("!SensorServer[1020507e]0001::OrientationThread")) DbgUtility.println(DbgUtility.PRIORITY_OPERATION, "Skipping data from Cycle.." + i); continue; } cell = row.createCell(j++); cell.setCellStyle(styles.get("cell_number")); ThreadData thData = heapValues.get(i); if (thData.getStatus() == 0) { //cell.getCellStyle().setAlignment(HSSFCellStyle.ALIGN_CENTER); cell.setCellValue(new HSSFRichTextString(NOT_AVAILABLE)); } else cell.setCellValue(thData.getHeapChunkSize()); } } cell = row.createCell(logData.getNumberOfCycles() + 1 - constants.size()); cell.setCellStyle(styles.get("cell_number")); ThreadData delta = deltaData.get(heap.toLowerCase()); //DbgUtility.println(DbgUtility.PRIORITY_OPERATION, "Delta for the thread " + heap + " is " + delta); if (delta != null) { long heapSizeDelta = delta.getHeapChunkSize(); cell.setCellValue(heapSizeDelta); } else cell.setCellValue(0); rowNo++; } for (int i = 0; i <= logData.getNumberOfCycles(); i++) { sheet.autoSizeColumn((short) i); } cell = description.createCell(0); cell.setCellValue(new HSSFRichTextString( "Specifies the total heap size for each thread in bytes, for each cycle in seconds")); }