Example usage for java.util Hashtable size

List of usage examples for java.util Hashtable size

Introduction

In this page you can find the example usage for java.util Hashtable size.

Prototype

public synchronized int size() 

Source Link

Document

Returns the number of keys in this hashtable.

Usage

From source file:com.afunms.report.abstraction.ExcelReport1.java

/**
 * @param filename//from   w  ww .j av a 2 s  .c  o m
 */
public void createReport_weblogicAll(String filename) {
    if (impReport.getTable() == null) {
        fileName = null;
        return;
    }
    WritableWorkbook wb = null;
    try {
        fileName = ResourceCenter.getInstance().getSysPath() + filename;
        Hashtable allreport_has = new Hashtable();
        allreport_has = reportHash;
        wb = Workbook.createWorkbook(new File(fileName));
        if (allreport_has != null && allreport_has.size() > 0) {
            Iterator keys = allreport_has.keySet().iterator();
            String ip = "";
            int sheetNum = 0;
            while (keys.hasNext()) {
                ip = keys.next().toString();
                String newip = doip(ip);
                Hashtable report_has = (Hashtable) allreport_has.get(ip);
                reportHash = report_has;
                fileName = ResourceCenter.getInstance().getSysPath() + filename;
                String starttime = (String) reportHash.get("starttime");
                String totime = (String) reportHash.get("totime");

                String hostname = (String) reportHash.get("equipname");
                Weblogic weblogic = (Weblogic) reportHash.get("weblogic");
                String weblogicnow = (String) reportHash.get("weblogicnow");
                WritableSheet sheet = wb.createSheet(hostname + "", sheetNum);
                sheetNum++;
                Calendar colTime = (Calendar) reportHash.get("time");

                Hashtable maxping = (Hashtable) reportHash.get("ping");

                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

                String[] memoryItemch = { "", "", "", "" };
                String[] memoryItem = { "Capability", "Utilization" };
                String[] diskItem = { "AllSize", "UsedSize", "Utilization" };
                String[] diskItemch = { "", "", "" };

                // WritableFont labelFont = new
                // WritableFont(WritableFont.createFont(""), 12,
                // WritableFont.BOLD, false);
                // WritableCellFormat labelFormat = new
                // WritableCellFormat(labelFont);
                //
                // WritableCellFormat _labelFormat = new
                // WritableCellFormat();
                // _labelFormat.setBackground(jxl.format.Colour.GRAY_25);
                //
                // WritableCellFormat p_labelFormat = new
                // WritableCellFormat();
                // p_labelFormat.setBackground(jxl.format.Colour.ICE_BLUE);
                //
                // WritableCellFormat b_labelFormat = new
                // WritableCellFormat();
                // b_labelFormat.setBackground(jxl.format.Colour.GRAY_50);

                Label tmpLabel = null;
                tmpLabel = new Label(0, 0, hostname + "", labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(0, 1, ":" + impReport.getTimeStamp());
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(0, 2, ": " + starttime + "  " + totime);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(0, 4, "", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(1, 4, "", _labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(3, 4, "", _labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(5, 4, "", _labelFormat);
                sheet.addCell(tmpLabel);
                sheet.mergeCells(0, 0, 7, 0);
                sheet.mergeCells(0, 1, 7, 1);
                sheet.mergeCells(0, 2, 7, 2);
                sheet.mergeCells(0, 4, 0, 12);
                sheet.mergeCells(1, 4, 2, 4);
                sheet.mergeCells(3, 4, 4, 4);
                sheet.mergeCells(5, 4, 7, 4);
                tmpLabel = new Label(1, 5, weblogicnow + "%", p_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(3, 5, (String) maxping.get("pingmax"), p_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(5, 5, (String) maxping.get("avgpingcon"), p_labelFormat);
                sheet.addCell(tmpLabel);
                sheet.mergeCells(1, 5, 2, 5);
                sheet.mergeCells(3, 5, 4, 5);
                sheet.mergeCells(5, 5, 7, 5);
                // 
                File file = new File(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/"
                        + newip + "WeblogicPing" + ".png");
                sheet.addImage(new WritableImage(1, 6, 7, 7, file));

                // 
                Hashtable hash = (Hashtable) report_has.get("weblogicnmphash");
                // Hashtable hash = null;
                // WeblogicSnmp weblogicsnmp = null;
                // WeblogicConfigDao weblogicconfigdao = new
                // WeblogicConfigDao();
                // weblogicsnmp = new WeblogicSnmp(weblogic.getIpAddress(),
                // weblogic.getCommunity(), weblogic
                // .getPortnum());
                // hash = weblogicsnmp.collectData();
                List queuedatalist = new ArrayList();
                tmpLabel = new Label(0, 14, "", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(1, 14, "", _labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(2, 14, "", _labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(3, 14, "", _labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(4, 14, "", _labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(5, 14, "", _labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(6, 14, "", _labelFormat);
                sheet.addCell(tmpLabel);
                sheet.mergeCells(6, 14, 7, 14);
                if (hash != null) {
                    queuedatalist = (List) hash.get("queueValue");
                }
                sheet.mergeCells(0, 14, 0, 14 + queuedatalist.size());
                int row = 0;
                for (int i = 0; i < queuedatalist.size(); i++) {
                    p_labelFormat = this.colorChange(i);
                    WeblogicQueue vo = (WeblogicQueue) queuedatalist.get(i);
                    tmpLabel = new Label(1, 15 + i, i + 1 + "", p_labelFormat);
                    sheet.addCell(tmpLabel);
                    tmpLabel = new Label(2, 15 + i, vo.getExecuteQueueRuntimeName(), p_labelFormat);
                    sheet.addCell(tmpLabel);
                    tmpLabel = new Label(3, 15 + i, vo.getThreadPoolRuntimeExecuteThreadIdleCount(),
                            p_labelFormat);
                    sheet.addCell(tmpLabel);
                    tmpLabel = new Label(4, 15 + i, vo.getExecuteQueueRuntimePendingRequestOldestTime(),
                            p_labelFormat);
                    sheet.addCell(tmpLabel);
                    tmpLabel = new Label(5, 15 + i, vo.getExecuteQueueRuntimePendingRequestCurrentCount(),
                            p_labelFormat);
                    sheet.addCell(tmpLabel);
                    tmpLabel = new Label(6, 15 + i, vo.getExecuteQueueRuntimePendingRequestTotalCount(),
                            p_labelFormat);
                    sheet.addCell(tmpLabel);
                    sheet.mergeCells(6, 15 + i, 7, 15 + i);
                    row++;
                }
                // jdbc
                int row1 = 15 + row + 1;
                tmpLabel = new Label(0, row1, "JDBC", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(1, row1, "", _labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(2, row1, "", _labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(3, row1, "", _labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(4, row1, "", _labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(5, row1, "", _labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(6, row1, "", _labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(7, row1, "", _labelFormat);
                sheet.addCell(tmpLabel);
                List jdbcdatalist = new ArrayList();
                // weblogicsnmp = new WeblogicSnmp(weblogic.getIpAddress(),
                // weblogic.getCommunity(), weblogic
                // .getPortnum());
                // hash = weblogicsnmp.collectData();
                jdbcdatalist = (List) hash.get("jdbcValue");
                sheet.mergeCells(0, row1, 0, row1 + jdbcdatalist.size());
                int row2 = 0;
                for (int i = 0; i < jdbcdatalist.size(); i++) {
                    p_labelFormat = this.colorChange(i);
                    WeblogicJdbc vo = (WeblogicJdbc) jdbcdatalist.get(i);
                    tmpLabel = new Label(1, row1 + 1 + i, i + 1 + "", p_labelFormat);
                    sheet.addCell(tmpLabel);
                    tmpLabel = new Label(2, row1 + 1 + i, vo.getJdbcConnectionPoolName(), p_labelFormat);
                    sheet.addCell(tmpLabel);
                    tmpLabel = new Label(3, row1 + 1 + i,
                            vo.getJdbcConnectionPoolRuntimeActiveConnectionsCurrentCount(), p_labelFormat);
                    sheet.addCell(tmpLabel);
                    tmpLabel = new Label(4, row1 + 1 + i, vo.getJdbcConnectionPoolRuntimeVersionJDBCDriver(),
                            p_labelFormat);
                    sheet.addCell(tmpLabel);
                    tmpLabel = new Label(5, row1 + 1 + i, vo.getJdbcConnectionPoolRuntimeMaxCapacity(),
                            p_labelFormat);
                    sheet.addCell(tmpLabel);
                    tmpLabel = new Label(6, row1 + 1 + i,
                            vo.getJdbcConnectionPoolRuntimeActiveConnectionsAverageCount(), p_labelFormat);
                    sheet.addCell(tmpLabel);
                    tmpLabel = new Label(7, row1 + 1 + i, vo.getJdbcConnectionPoolRuntimeHighestNumAvailable(),
                            p_labelFormat);
                    sheet.addCell(tmpLabel);
                    row2++;
                }
                // jvm
                int row3 = row1 + 1 + row2 + 1;
                // weblogicsnmp = new WeblogicSnmp(weblogic.getIpAddress(),
                // weblogic.getCommunity(), weblogic
                // .getPortnum());
                // hash = weblogicsnmp.collectData();
                List heapdatalist = new ArrayList();
                heapdatalist = (List) hash.get("heapValue");
                tmpLabel = new Label(0, row3, "JVM", b_labelFormat);
                sheet.addCell(tmpLabel);
                sheet.mergeCells(0, row3, 0, row3 + heapdatalist.size());
                tmpLabel = new Label(1, row3, "", _labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(2, row3, "", _labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(4, row3, "", _labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(6, row3, "", _labelFormat);
                sheet.addCell(tmpLabel);
                sheet.mergeCells(2, row3, 3, row3);
                sheet.mergeCells(4, row3, 5, row3);
                sheet.mergeCells(6, row3, 7, row3);
                int row4 = 0;
                for (int i = 0; i < heapdatalist.size(); i++) {
                    p_labelFormat = this.colorChange(i);
                    WeblogicHeap vo = (WeblogicHeap) heapdatalist.get(i);
                    tmpLabel = new Label(1, row3 + 1 + i, i + 1 + "", p_labelFormat);
                    sheet.addCell(tmpLabel);
                    tmpLabel = new Label(2, row3 + 1 + i, vo.getJvmRuntimeName(), p_labelFormat);
                    sheet.addCell(tmpLabel);
                    tmpLabel = new Label(4, row3 + 1 + i, vo.getJvmRuntimeHeapSizeCurrent(), p_labelFormat);
                    sheet.addCell(tmpLabel);
                    tmpLabel = new Label(6, row3 + 1 + i, vo.getJvmRuntimeHeapFreeCurrent(), p_labelFormat);
                    sheet.addCell(tmpLabel);
                    sheet.mergeCells(2, row3 + 1 + i, 3, row3 + 1 + i);
                    sheet.mergeCells(4, row3 + 1 + i, 5, row3 + 1 + i);
                    sheet.mergeCells(6, row3 + 1 + i, 7, row3 + 1 + i);
                    row4++;
                }
                int row5 = row3 + 1 + row4 + 1;
                tmpLabel = new Label(0, row5, "", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(1, row5, "", _labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(2, row5, "", _labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(3, row5, "", _labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(4, row5, "", _labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(5, row5, "Socket", _labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(6, row5, "", _labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(7, row5, "IP", _labelFormat);
                sheet.addCell(tmpLabel);
                List serverdatalist = new ArrayList();
                // weblogicsnmp = new WeblogicSnmp(weblogic.getIpAddress(),
                // weblogic.getCommunity(), weblogic
                // .getPortnum());
                // hash = weblogicsnmp.collectData();
                serverdatalist = (List) hash.get("serverValue");
                sheet.mergeCells(0, row5, 0, row5 + serverdatalist.size());
                for (int i = 0; i < serverdatalist.size(); i++) {
                    p_labelFormat = this.colorChange(i);
                    WeblogicServer vo = (WeblogicServer) serverdatalist.get(i);
                    tmpLabel = new Label(1, row5 + 1 + i, i + 1 + "", p_labelFormat);
                    sheet.addCell(tmpLabel);
                    tmpLabel = new Label(2, row5 + 1 + i, vo.getServerRuntimeName(), p_labelFormat);
                    sheet.addCell(tmpLabel);
                    tmpLabel = new Label(3, row5 + 1 + i, vo.getServerRuntimeListenAddress(), p_labelFormat);
                    sheet.addCell(tmpLabel);
                    tmpLabel = new Label(4, row5 + 1 + i, vo.getServerRuntimeListenPort(), p_labelFormat);
                    sheet.addCell(tmpLabel);
                    tmpLabel = new Label(5, row5 + 1 + i, vo.getServerRuntimeOpenSocketsCurrentCount(),
                            p_labelFormat);
                    sheet.addCell(tmpLabel);
                    tmpLabel = new Label(6, row5 + 1 + i, vo.getServerRuntimeState(), p_labelFormat);
                    sheet.addCell(tmpLabel);
                    tmpLabel = new Label(7, row5 + 1 + i, weblogic.getIpAddress(), p_labelFormat);
                    sheet.addCell(tmpLabel);
                }
            }
        }
        wb.write();
    } catch (Exception e) {
        SysLogger.error("", e);
    } finally {
        try {
            if (wb != null)
                wb.close();
        } catch (Exception e) {
            SysLogger.error("", e);
        }
    }
}

From source file:com.afunms.report.abstraction.ExcelReport1.java

/**
 * @param file//from   w  w w  .j a  v a  2s . c  o m
 * @param type
 * @throws DocumentException
 * @throws IOException
 */
public void createReport_iisNewDoc(String file, String type) throws DocumentException, IOException {
    Hashtable Memory = (Hashtable) reportHash.get("Memory");
    // EventListDao eventListDao = new EventListDao();

    Hashtable maxping = (Hashtable) reportHash.get("ping");
    String starttime = (String) reportHash.get("starttime");
    String totime = (String) reportHash.get("totime");
    String hostname = (String) reportHash.get("equipname");
    String hostnameDoc = (String) reportHash.get("equipnameDoc");
    String ip = (String) reportHash.get("ip");
    String typename = (String) reportHash.get("typename");
    String startdate = (String) reportHash.get("startdate");
    Tomcat tomcat = (Tomcat) reportHash.get("tomcat");
    Hashtable maxjvm = (Hashtable) reportHash.get("maxjvm");
    String downnum = (String) reportHash.get("downnum");
    IIS iis = (IIS) reportHash.get("iis");
    // time
    Hashtable pollingtime_ht = new Hashtable();
    IISManager tm = new IISManager();
    String lasttime;
    String nexttime;
    try {
        pollingtime_ht = tm.getCollecttime(iis.getIpAddress());
    } catch (Exception e) {

        SysLogger.error("", e);
    }
    if (pollingtime_ht != null) {
        lasttime = (String) pollingtime_ht.get("lasttime");
        nexttime = (String) pollingtime_ht.get("nexttime");
    } else {
        lasttime = null;
        nexttime = null;
    }
    // 
    List data_list = new ArrayList();
    Hashtable iisvalues = ShareData.getIisdata();
    if (iisvalues != null && iisvalues.size() > 0) {
        data_list = (List) iisvalues.get(ip);
    }
    System.out.println(data_list + "----------------------------====================");
    String totalBytesSentHighWord = "";
    String totalBytesSentLowWord = "";
    String totalBytesReceivedHighWord = "";
    String totalBytesReceivedLowWord = "";

    String totalFilesSent = "";
    String totalFilesReceived = "";
    String currentAnonymousUsers = "";
    String totalAnonymousUsers = "";

    String maxAnonymousUsers = "";
    String currentConnections = "";
    String maxConnections = "";
    String connectionAttempts = "";

    String logonAttempts = "";
    String totalGets = "";
    String totalPosts = "";
    String totalNotFoundErrors = "";
    if (data_list != null && data_list.size() > 0) {

        IISVo iisvo = (IISVo) data_list.get(0);
        totalBytesSentHighWord = iisvo.getTotalBytesSentHighWord();
        totalBytesSentLowWord = iisvo.getTotalBytesSentLowWord();
        totalBytesReceivedHighWord = iisvo.getTotalBytesReceivedHighWord();
        totalBytesReceivedLowWord = iisvo.getTotalBytesReceivedLowWord();

        totalFilesSent = iisvo.getTotalFilesSent();
        totalFilesReceived = iisvo.getTotalFilesReceived();
        currentAnonymousUsers = iisvo.getCurrentAnonymousUsers();
        totalAnonymousUsers = iisvo.getTotalAnonymousUsers();

        maxAnonymousUsers = iisvo.getMaxAnonymousUsers();
        currentConnections = iisvo.getCurrentConnections();
        maxConnections = iisvo.getMaxConnections();
        connectionAttempts = iisvo.getConnectionAttempts();

        logonAttempts = iisvo.getLogonAttempts();
        totalGets = iisvo.getTotalGets();
        totalPosts = iisvo.getTotalPosts();
        totalNotFoundErrors = iisvo.getTotalNotFoundErrors();

    }
    // end 
    /* String type = (String)request.getAttribute("type"); */
    Document document = null;
    // (Writer)document(Writer)
    if ("pdf".equals(type)) {
        document = new Document(PageSize.B4);
        PdfWriter.getInstance(document, new FileOutputStream(file));
    } else {
        document = new Document(PageSize.A4);
        RtfWriter2.getInstance(document, new FileOutputStream(file));
    }
    document.open();
    // 
    BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
    // 
    Font titleFont = new Font(bfChinese, 12, Font.BOLD);
    // 
    Font contextFont = new Font(bfChinese, 12, Font.NORMAL);

    Font fontChinese = new Font(bfChinese, 12, Font.NORMAL, Color.black);
    Table aTable = new Table(8);
    this.setTableFormat(aTable);
    // float[] widths = { 220f, 220f, 220f, 110f, 110f, 110f, 110f, 220f };
    // aTable.setWidths(widths);
    // aTable.setWidth(100); //  90%
    // aTable.setAlignment(Element.ALIGN_CENTER);// 
    // aTable.setAutoFillEmptyCells(true); // 
    // aTable.setBorderWidth(1); // 
    // aTable.setBorderColor(new Color(0, 125, 255)); // 
    // aTable.setPadding(2);// 
    // aTable.setSpacing(0);// 
    // aTable.setBorder(2);// 

    // aTable.endHeaders();
    Cell cell = null;
    cell = new Cell(new Phrase("\n" + "" + hostname + "" + "\n", titleFont));
    cell.setColspan(8);
    this.setCellFormat(cell, true);
    aTable.addCell(cell);
    cell = new Cell(new Phrase("\n" + "" + "\n", titleFont));
    aTable.addCell(cell);
    this.setCellFormat(cell, true);
    cell = new Cell(new Phrase("\n" + starttime + "  " + totime + "\n", contextFont));
    cell.setColspan(7);
    this.setCellFormat(cell, false);
    aTable.addCell(cell);
    cell = new Cell(new Phrase("\n" + "" + "\n", titleFont));
    this.setCellFormat(cell, true);
    aTable.addCell(cell);
    cell = new Cell(new Phrase(hostnameDoc, contextFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase("IP", titleFont));
    this.setCellFormat(cell, true);
    aTable.addCell(cell);
    cell = new Cell(new Phrase(ip, contextFont));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);

    cell = new Cell(new Phrase("", titleFont));
    cell.setColspan(2);
    this.setCellFormat(cell, true);
    aTable.addCell(cell);
    cell = new Cell(new Phrase(typename, contextFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase("\n" + "" + "\n", titleFont));
    this.setCellFormat(cell, true);
    aTable.addCell(cell);
    String grade = (String) reportHash.get("grade");
    cell = new Cell(new Phrase("\n" + grade + "\n", contextFont));
    cell.setColspan(7);

    aTable.addCell(cell);
    cell = new Cell(new Phrase("" + "\n" + "" + "\n" + "" + "\n" + "", titleFont));
    cell.setRowspan(10);
    this.setCellFormat(cell, true);
    aTable.addCell(cell);

    cell = new Cell(new Phrase("\n" + "" + "\n", titleFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase("\n" + "" + "\n", titleFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase((String) maxping.get("pingmax"), contextFont));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase("", titleFont));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);

    cell = new Cell(new Phrase((String) maxping.get("avgpingcon"), contextFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);

    cell = new Cell(new Phrase("\n" + "" + "\n", titleFont));

    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase("\n" + ":" + "\n", titleFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(lasttime, contextFont));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(":", titleFont));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(nexttime, contextFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);

    cell = new Cell(new Phrase("\n" + "" + "\n", titleFont));
    cell.setRowspan(8);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);

    cell = new Cell(new Phrase("\n" + "32 :" + "\n", titleFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(totalBytesSentHighWord, contextFont));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase("32 :", titleFont));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(totalBytesSentLowWord, contextFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);

    cell = new Cell(new Phrase("\n" + "32 :" + "\n", titleFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(totalBytesReceivedHighWord, contextFont));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase("32 :", titleFont));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(totalBytesReceivedLowWord, contextFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);

    cell = new Cell(new Phrase("\n" + ":" + "\n", titleFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(totalFilesSent, contextFont));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(":", titleFont));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(totalFilesReceived, contextFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);

    cell = new Cell(new Phrase("\n" + ":" + "\n", titleFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(currentAnonymousUsers, contextFont));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(":", titleFont));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(totalAnonymousUsers, contextFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);

    cell = new Cell(new Phrase("\n" + ":" + "\n", titleFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(maxAnonymousUsers, contextFont));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(":", titleFont));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(currentConnections, contextFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);

    cell = new Cell(new Phrase("\n" + ":" + "\n", titleFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(maxConnections, contextFont));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase("::", titleFont));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(connectionAttempts, contextFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);

    cell = new Cell(new Phrase("\n" + ":" + "\n", titleFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(logonAttempts, contextFont));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase("GET:", titleFont));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(totalGets, contextFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);

    cell = new Cell(new Phrase("\n" + "POST:" + "\n", titleFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(totalPosts, contextFont));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(":", titleFont));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(totalNotFoundErrors, contextFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);

    cell = new Cell(new Phrase("" + "\n" + "" + "\n" + "" + "\n" + "", titleFont));
    this.setCellFormat(cell, true);
    aTable.addCell(cell);
    cell = new Cell(new Phrase("\n" + "" + downnum + "" + "\n", contextFont));
    cell.setColspan(7);
    aTable.addCell(cell);

    cell = new Cell(new Phrase("\n" + "" + "\n", titleFont));
    this.setCellFormat(cell, true);
    cell.setColspan(8);
    aTable.addCell(cell);
    String strping = "";
    if ("0".equals(downnum)) {
        strping = "    2   " + downnum + "" + "\n"
                + "\n";
    } else {
        strping = "    2   " + "\n" + "\n";
    }
    cell = new Cell(new Phrase("    1   " + " \n" + "\n"
            + strping + "\n" + "\n" + "\n", contextFont));
    cell.setColspan(8);
    aTable.addCell(cell);
    // end 

    // end  }
    document.add(aTable);
    document.close();
}

From source file:com.afunms.report.abstraction.ExcelReport1.java

/**
 * @author HONGLI oracleexcel//from  w  w w. ja  v  a 2  s .  c  om
 * @param filename
 * @throws DocumentException
 * @throws IOException
 */
public void createReportOracleCldExcel(String filename) throws DocumentException, IOException {
    if (impReport.getTable() == null) {
        fileName = null;
        return;
    }
    WritableWorkbook wb = null;
    try {
        fileName = ResourceCenter.getInstance().getSysPath() + filename;
        wb = Workbook.createWorkbook(new File(fileName));

        String[] sysItem1 = { "shared_pool", "large_pool", "DEFAULT_buffer_cache", "java_pool" };
        String[] sysItemch1 = { "", "", "", "Java" };
        String[] sysItem2 = { "aggregate_PGA_target_parameter", "total_PGA_allocated",
                "maximum_PGA_allocated" };
        String[] sysItemch2 = { "PGA", "PGA", "PGA" };
        String hostname = (String) reportHash.get("dbname");
        String ip = (String) reportHash.get("ip");
        String newip = doip(ip);
        WritableSheet sheet = wb.createSheet(hostname + "", 0);
        String Ping = (String) reportHash.get("Ping");
        String starttime = (String) reportHash.get("starttime");
        String totime = (String) reportHash.get("totime");
        String typename = (String) reportHash.get("typename");
        String runstr = (String) reportHash.get("runstr");
        String grade = (String) reportHash.get("grade");
        String pingnow = (String) reportHash.get("pingnow");
        String pingmin = (String) reportHash.get("pingmin");
        String pingconavg = (String) reportHash.get("pingconavg");
        DBVo vo = (DBVo) reportHash.get("vo");
        String buffercache = "0";// 
        String dictionarycache = "0";// 
        String librarycache = "0";// 
        String pctmemorysorts = "0";// 
        String pctbufgets = "0";// 10
        String opencurstr = "0";// 
        Hashtable memPerfValue = (Hashtable) reportHash.get("memPerfValue");
        Hashtable memValue = (Hashtable) reportHash.get("memValue");
        Hashtable cursors = (Hashtable) reportHash.get("cursors");
        if (cursors == null) {
            cursors = new Hashtable();
        }
        if (memPerfValue == null)
            memPerfValue = new Hashtable();
        if (memPerfValue != null) {
            if (memPerfValue.containsKey("buffercache") && memPerfValue.get("buffercache") != null) {
                buffercache = (String) memPerfValue.get("buffercache") + "%";
            }
            if (memPerfValue.containsKey("dictionarycache") && memPerfValue.get("dictionarycache") != null) {
                dictionarycache = (String) memPerfValue.get("dictionarycache") + "%";
            }
            if (memPerfValue.containsKey("librarycache") && memPerfValue.get("librarycache") != null) {
                librarycache = (String) memPerfValue.get("librarycache") + "%";
            }
            if (memPerfValue.containsKey("pctmemorysorts") && memPerfValue.get("pctmemorysorts") != null) {
                pctmemorysorts = (String) memPerfValue.get("pctmemorysorts") + "%";
            }
            if (memPerfValue.containsKey("pctbufgets") && memPerfValue.get("pctbufgets") != null) {
                pctbufgets = (String) memPerfValue.get("pctbufgets") + "%";
            }
            if (cursors.containsKey("opencur") && cursors.get("opencur") != null) {
                opencurstr = (String) cursors.get("opencur");
            }
        }

        Hashtable maxping = (Hashtable) reportHash.get("ping");

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        // WritableFont labelFont = new
        // WritableFont(WritableFont.createFont(""), 12,
        // WritableFont.BOLD, false);
        // WritableCellFormat labelFormat = new
        // WritableCellFormat(labelFont);
        //
        // WritableCellFormat _labelFormat = new WritableCellFormat();
        // _labelFormat.setBackground(jxl.format.Colour.GRAY_25);
        //
        // WritableCellFormat p_labelFormat = new WritableCellFormat();
        // p_labelFormat.setBackground(jxl.format.Colour.ICE_BLUE);
        //
        // WritableCellFormat b_labelFormat = new WritableCellFormat();
        // b_labelFormat.setBackground(jxl.format.Colour.GRAY_50);

        Label tmpLabel = null;
        tmpLabel = new Label(0, 0, hostname + "", labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(0, 1, ":" + impReport.getTimeStamp(), labelFormat1);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(0, 2, ": " + starttime + "  " + totime, labelFormat1);
        sheet.addCell(tmpLabel);
        sheet.mergeCells(0, 0, 10, 0);
        sheet.mergeCells(0, 1, 10, 1);
        sheet.mergeCells(0, 2, 10, 2);
        // ip
        tmpLabel = new Label(0, 4, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(2, 4, "IP", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(4, 4, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(6, 4, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(8, 4, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        sheet.mergeCells(0, 4, 1, 4);
        sheet.mergeCells(2, 4, 3, 4);
        sheet.mergeCells(4, 4, 5, 4);
        sheet.mergeCells(6, 4, 7, 4);
        sheet.mergeCells(8, 4, 10, 4);
        tmpLabel = new Label(0, 5, vo.getDbName(), p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(2, 5, ip, p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(4, 5, typename, p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(6, 5, runstr, p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(8, 5, grade, p_labelFormat);
        sheet.addCell(tmpLabel);
        sheet.mergeCells(0, 5, 1, 5);
        sheet.mergeCells(2, 5, 3, 5);
        sheet.mergeCells(4, 5, 5, 5);
        sheet.mergeCells(6, 5, 7, 5);
        sheet.mergeCells(8, 5, 10, 5);

        // 
        tmpLabel = new Label(0, 7, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(3, 7, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(6, 7, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        sheet.mergeCells(0, 7, 2, 7);
        sheet.mergeCells(3, 7, 5, 7);
        sheet.mergeCells(6, 7, 10, 7);
        tmpLabel = new Label(0, 8, pingnow + "%", p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(3, 8, pingmin + "%", p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(6, 8, pingconavg + "%", p_labelFormat);
        sheet.addCell(tmpLabel);
        sheet.mergeCells(0, 8, 2, 8);
        sheet.mergeCells(3, 8, 5, 8);
        sheet.mergeCells(6, 8, 10, 8);

        // 
        File file = new File(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/" + newip
                + "ConnectUtilization" + ".png");
        // sheet,0,0,5,1,,,
        // allRow = allRow+2;
        sheet.addImage(new WritableImage(0, 9, 11, 8, file));
        // allRow = allRow+7;
        int row = 17;

        // 
        tmpLabel = new Label(0, row, "   ", labelFormat);
        sheet.addCell(tmpLabel);
        sheet.mergeCells(0, row, 10, row);
        row++;
        tmpLabel = new Label(0, row, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(1, row, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(3, row, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(5, row, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(7, row, "10", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(9, row, " ", b_labelFormat);
        sheet.addCell(tmpLabel);
        sheet.mergeCells(1, row, 2, row);
        sheet.mergeCells(3, row, 4, row);
        sheet.mergeCells(5, row, 6, row);
        sheet.mergeCells(7, row, 8, row);
        sheet.mergeCells(9, row, 10, row);
        row++;
        tmpLabel = new Label(0, row, buffercache, p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(1, row, dictionarycache, p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(3, row, librarycache, p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(5, row, pctmemorysorts, p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(7, row, pctbufgets, p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(9, row, opencurstr, p_labelFormat);
        sheet.addCell(tmpLabel);
        sheet.mergeCells(1, row, 2, row);
        sheet.mergeCells(3, row, 4, row);
        sheet.mergeCells(5, row, 6, row);
        sheet.mergeCells(7, row, 8, row);
        sheet.mergeCells(9, row, 10, row);

        // 
        row = row + 2;
        tmpLabel = new Label(0, row, "", labelFormat);
        sheet.addCell(tmpLabel);
        sheet.mergeCells(0, row, 10, row);
        row++;
        tmpLabel = new Label(0, row, sysItemch2[0], b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(1, row, sysItemch2[1], b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(2, row, sysItemch2[2], b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(3, row, sysItemch1[0], b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(5, row, sysItemch1[1], b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(7, row, sysItemch1[2], b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(9, row, sysItemch1[3], b_labelFormat);
        sheet.addCell(tmpLabel);
        sheet.mergeCells(3, row, 4, row);
        sheet.mergeCells(5, row, 6, row);
        sheet.mergeCells(7, row, 8, row);
        sheet.mergeCells(9, row, 10, row);
        row++;
        tmpLabel = new Label(0, row, memValue.get(sysItem2[0]) + "MB", p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(1, row, memValue.get(sysItem2[1]) + "MB", p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(2, row, memValue.get(sysItem2[2]) + "MB", p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(3, row, memValue.get(sysItem1[0]) + "MB", p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(5, row, memValue.get(sysItem1[1]) + "MB", p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(7, row, memValue.get(sysItem1[2]) + "MB", p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(9, row, memValue.get(sysItem1[3]) + "MB", p_labelFormat);
        sheet.addCell(tmpLabel);
        sheet.mergeCells(3, row, 4, row);
        sheet.mergeCells(5, row, 6, row);
        sheet.mergeCells(7, row, 8, row);
        sheet.mergeCells(9, row, 10, row);

        // 
        row = row + 2;
        tmpLabel = new Label(0, row, "", labelFormat);
        sheet.addCell(tmpLabel);
        sheet.mergeCells(0, row, 10, row);
        row++;
        tmpLabel = new Label(0, row, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(1, row, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(2, row, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(3, row, "MB", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(4, row, "MB", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(5, row, "", b_labelFormat);
        sheet.addCell(tmpLabel);

        // HONGLI ADD START1
        tmpLabel = new Label(6, row, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(7, row, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(8, row, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(9, row, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        // HONGLI ADD END1

        // HONGLI MODIFY START1
        tmpLabel = new Label(10, row, "", b_labelFormat);
        // HONGLI MODIFY END1

        sheet.addCell(tmpLabel);

        // 
        row = row++;
        Vector tableinfo_v = (Vector) reportHash.get("tableinfo_v");

        // HONGLI ADD START2
        Hashtable dbio = (Hashtable) reportHash.get("dbio");
        // HONGLI ADD END2

        for (int i = 0; i < tableinfo_v.size(); i++) {
            p_labelFormat = super.colorChange(i);
            Hashtable ht = (Hashtable) tableinfo_v.get(i);
            String _filename = ht.get("file_name").toString();
            String tablespace = ht.get("tablespace").toString();
            String size = ht.get("size_mb").toString();
            String free = ht.get("free_mb").toString();
            String percent = ht.get("percent_free").toString();
            String status = ht.get("status").toString();

            // HONGLI ADD START3
            String pyr = "";
            String pbr = "";
            String pyw = "";
            String pbw = "";
            if (dbio.containsKey(_filename)) {
                Hashtable iodetail = (Hashtable) dbio.get(_filename);
                if (iodetail != null && iodetail.size() > 0) {
                    pyr = (String) iodetail.get("pyr");
                    pbr = (String) iodetail.get("pbr");
                    pyw = (String) iodetail.get("pyw");
                    pbw = (String) iodetail.get("pbw");
                }
            }
            // HONGLI ADD END3

            tmpLabel = new Label(0, row, String.valueOf(i + 1), p_labelFormat);
            sheet.addCell(tmpLabel);
            tmpLabel = new Label(1, row, _filename, p_labelFormat);
            sheet.addCell(tmpLabel);
            tmpLabel = new Label(2, row, tablespace, p_labelFormat);
            sheet.addCell(tmpLabel);
            tmpLabel = new Label(3, row, size, p_labelFormat);
            sheet.addCell(tmpLabel);
            tmpLabel = new Label(4, row, free, p_labelFormat);
            sheet.addCell(tmpLabel);
            tmpLabel = new Label(5, row, percent, p_labelFormat);
            sheet.addCell(tmpLabel);

            // HONGLI ADD START4
            tmpLabel = new Label(6, row, pyr, p_labelFormat);
            sheet.addCell(tmpLabel);
            tmpLabel = new Label(7, row, pbr, p_labelFormat);
            sheet.addCell(tmpLabel);
            tmpLabel = new Label(8, row, pyw, p_labelFormat);
            sheet.addCell(tmpLabel);
            tmpLabel = new Label(9, row, pbw, p_labelFormat);
            sheet.addCell(tmpLabel);
            // HONGLI ADD END4

            tmpLabel = new Label(10, row, status, p_labelFormat);
            sheet.addCell(tmpLabel);
            row++;

        }
        //    
        row = row + 2;
        tmpLabel = new Label(0, row, "     ", labelFormat);
        sheet.addCell(tmpLabel);
        sheet.mergeCells(0, row, 10, row);
        row++;
        tmpLabel = new Label(0, row, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(5, row, " ", b_labelFormat);
        sheet.addCell(tmpLabel);
        sheet.mergeCells(0, row, 4, row);
        sheet.mergeCells(5, row, 10, row);
        row++;
        tmpLabel = new Label(0, row, (String) reportHash.get("downnum"), p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(5, row, reportHash.get("count") + "", p_labelFormat);
        sheet.addCell(tmpLabel);
        sheet.mergeCells(0, row, 4, row);
        sheet.mergeCells(5, row, 10, row);

        // 
        addEventListToExcel(sheet, row);

        if (impReport.getChart() != null) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            try {
                ChartUtilities.writeChartAsPNG(baos, impReport.getChart().getChart(),
                        impReport.getChart().getWidth(), impReport.getChart().getHeight());
            } catch (IOException ioe) {
            }
            WritableImage wi = new WritableImage(2, 10000 + 5, 8, 12, baos.toByteArray());
            sheet.addImage(wi);
        }
        wb.write();
    } catch (Exception e) {
        SysLogger.error("Error in ExcelReport.createReport()", e);
    } finally {
        try {
            if (wb != null)
                wb.close();
        } catch (Exception e) {
            SysLogger.error("", e);
        }
    }
}

From source file:com.afunms.report.abstraction.ExcelReport1.java

public void createReport_sql(String filename) {
    if (impReport.getTable() == null) {
        fileName = null;/*from  w  ww. j  a  v a2 s. c  o m*/
        return;
    }
    WritableWorkbook wb = null;
    try {
        // fileName = ResourceCenter.getInstance().getSysPath() +
        // "temp\\dhcnms_report.xls";
        // fileName = CommonAppUtil.getAppName() +
        // "/temp/hostnms_report.xls";
        fileName = ResourceCenter.getInstance().getSysPath() + filename;
        wb = Workbook.createWorkbook(new File(fileName));

        String hostname = (String) reportHash.get("dbname");
        String ip = (String) reportHash.get("ip");
        String newip = doip(ip);
        WritableSheet sheet = wb.createSheet(hostname + "", 0);
        String Ping = (String) reportHash.get("Ping");
        String starttime = (String) reportHash.get("starttime");
        String totime = (String) reportHash.get("totime");

        Hashtable maxping = (Hashtable) reportHash.get("ping");

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        WritableFont labelFont = new WritableFont(WritableFont.createFont(""), 12, WritableFont.BOLD,
                false);
        WritableCellFormat labelFormat = new WritableCellFormat(labelFont);

        WritableCellFormat _labelFormat = new WritableCellFormat();
        _labelFormat.setBackground(jxl.format.Colour.GRAY_25);

        WritableCellFormat p_labelFormat = new WritableCellFormat();
        p_labelFormat.setBackground(jxl.format.Colour.ICE_BLUE);

        WritableCellFormat b_labelFormat = new WritableCellFormat();
        b_labelFormat.setBackground(jxl.format.Colour.GRAY_50);

        Label tmpLabel = null;
        tmpLabel = new Label(1, 0, hostname + "", labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(0, 1, ":" + impReport.getTimeStamp());
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(0, 2, ": " + starttime + "  " + totime);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(0, 4, "", b_labelFormat);
        sheet.addCell(tmpLabel);

        tmpLabel = new Label(1, 4, "", _labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(2, 4, "", _labelFormat);
        sheet.addCell(tmpLabel);

        tmpLabel = new Label(0, 5, (String) maxping.get("pingnow"), p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(1, 5, (String) maxping.get("pingmax"), p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(2, 5, (String) maxping.get("avgpingcon"), p_labelFormat);
        sheet.addCell(tmpLabel);

        // 
        File file = new File(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/" + newip
                + "ConnectUtilization" + ".png");
        // sheet,0,0,5,1,,,
        // allRow = allRow+2;
        sheet.addImage(new WritableImage(1, 6, 7, 7, file));
        // allRow = allRow+7;

        tmpLabel = new Label(0, 14, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(1, 14, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(2, 14, "MB", _labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(3, 14, "MB", _labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(4, 14, "", _labelFormat);
        sheet.addCell(tmpLabel);
        int row = 14;

        // 
        Hashtable dbValue = (Hashtable) reportHash.get("tableinfo_v");
        Hashtable alldatabase = new Hashtable();
        if (dbValue.get("database") != null)
            alldatabase = (Hashtable) dbValue.get("database");
        Vector names = new Vector();
        if (dbValue.get("names") != null)
            names = (Vector) dbValue.get("names");

        if (alldatabase != null && alldatabase.size() > 0) {
            if (names == null)
                names = new Vector();
            for (int i = 0; i < names.size(); i++) {
                String key = (String) names.get(i);
                if (alldatabase.get(key) == null)
                    continue;
                Hashtable data = (Hashtable) alldatabase.get(key);
                String dbname = data.get("dbname").toString();
                String size = data.get("size").toString();
                String usedsize = "";
                if (data.get("usedsize") != null) {
                    usedsize = data.get("usedsize").toString();
                }
                String usedperc = "";
                if (data.get("usedperc") != null)
                    usedperc = data.get("usedperc").toString();
                row = row + 1;
                tmpLabel = new Label(0, row, i + 1 + "", p_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(1, row, dbname, p_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(2, row, size, p_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(3, row, usedsize, p_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(4, row, usedperc, p_labelFormat);
                sheet.addCell(tmpLabel);
            }
        }

        if (impReport.getChart() != null) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            try {
                ChartUtilities.writeChartAsPNG(baos, impReport.getChart().getChart(),
                        impReport.getChart().getWidth(), impReport.getChart().getHeight());
            } catch (IOException ioe) {
            }
            WritableImage wi = new WritableImage(2, 10000 + 5, 8, 12, baos.toByteArray());
            sheet.addImage(wi);
        }
        wb.write();
    } catch (Exception e) {
        // SysLogger.error("Error in ExcelReport.createReport()",e);
        SysLogger.error("", e);
    } finally {
        try {
            if (wb != null)
                wb.close();
        } catch (Exception e) {
        }
    }
}

From source file:com.afunms.report.abstraction.ExcelReport1.java

public void createReport_iisNewPDF(String file) throws DocumentException, IOException {
    Hashtable maxping = (Hashtable) reportHash.get("ping");
    String starttime = (String) reportHash.get("starttime");
    String totime = (String) reportHash.get("totime");
    String hostname = (String) reportHash.get("equipname");
    String hostnameDoc = (String) reportHash.get("equipnameDoc");
    String ip = (String) reportHash.get("ip");
    String typename = (String) reportHash.get("typename");
    String startdate = (String) reportHash.get("startdate");
    Tomcat tomcat = (Tomcat) reportHash.get("tomcat");
    Hashtable maxjvm = (Hashtable) reportHash.get("maxjvm");
    String downnum = (String) reportHash.get("downnum");
    IIS iis = (IIS) reportHash.get("iis");
    // time//w  ww .j av a2s  .  co m
    Hashtable pollingtime_ht = new Hashtable();
    IISManager tm = new IISManager();
    String lasttime;
    String nexttime;
    try {
        pollingtime_ht = tm.getCollecttime(iis.getIpAddress());
    } catch (Exception e) {

        SysLogger.error("", e);
    }
    if (pollingtime_ht != null) {
        lasttime = (String) pollingtime_ht.get("lasttime");
        nexttime = (String) pollingtime_ht.get("nexttime");
    } else {
        lasttime = null;
        nexttime = null;
    }
    // 
    List data_list = new ArrayList();
    Hashtable iisvalues = ShareData.getIisdata();
    if (iisvalues != null && iisvalues.size() > 0) {
        data_list = (List) iisvalues.get(ip);
    }
    System.out.println(data_list + "----------------------------====================");
    String totalBytesSentHighWord = "";
    String totalBytesSentLowWord = "";
    String totalBytesReceivedHighWord = "";
    String totalBytesReceivedLowWord = "";

    String totalFilesSent = "";
    String totalFilesReceived = "";
    String currentAnonymousUsers = "";
    String totalAnonymousUsers = "";

    String maxAnonymousUsers = "";
    String currentConnections = "";
    String maxConnections = "";
    String connectionAttempts = "";

    String logonAttempts = "";
    String totalGets = "";
    String totalPosts = "";
    String totalNotFoundErrors = "";
    if (data_list != null && data_list.size() > 0) {

        IISVo iisvo = (IISVo) data_list.get(0);
        totalBytesSentHighWord = iisvo.getTotalBytesSentHighWord();
        totalBytesSentLowWord = iisvo.getTotalBytesSentLowWord();
        totalBytesReceivedHighWord = iisvo.getTotalBytesReceivedHighWord();
        totalBytesReceivedLowWord = iisvo.getTotalBytesReceivedLowWord();

        totalFilesSent = iisvo.getTotalFilesSent();
        totalFilesReceived = iisvo.getTotalFilesReceived();
        currentAnonymousUsers = iisvo.getCurrentAnonymousUsers();
        totalAnonymousUsers = iisvo.getTotalAnonymousUsers();

        maxAnonymousUsers = iisvo.getMaxAnonymousUsers();
        currentConnections = iisvo.getCurrentConnections();
        maxConnections = iisvo.getMaxConnections();
        connectionAttempts = iisvo.getConnectionAttempts();

        logonAttempts = iisvo.getLogonAttempts();
        totalGets = iisvo.getTotalGets();
        totalPosts = iisvo.getTotalPosts();
        totalNotFoundErrors = iisvo.getTotalNotFoundErrors();

    }
    // end 
    /* String type = (String)request.getAttribute("type"); */
    Document document = new Document(PageSize.A4);
    // (Writer)document(Writer)
    PdfWriter.getInstance(document, new FileOutputStream(file));
    document.open();
    // 
    BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
    // 
    Font titleFont = new Font(bfChinese, 12, Font.BOLD);
    // 
    Font contextFont = new Font(bfChinese, 12, Font.NORMAL);
    Font contextFont1 = new Font(bfChinese, 10, Font.NORMAL);
    Font fontChinese = new Font(bfChinese, 12, Font.NORMAL, Color.black);
    Table aTable = new Table(8);
    float[] widths = { 220f, 220f, 220f, 110f, 110f, 110f, 110f, 220f };
    aTable.setWidths(widths);
    aTable.setWidth(100); //  90%
    aTable.setAlignment(Element.ALIGN_CENTER);// 
    aTable.setAutoFillEmptyCells(true); // 
    aTable.setBorderWidth(1); // 
    aTable.setBorderColor(new Color(0, 125, 255)); // 
    aTable.setPadding(2);// 
    aTable.setSpacing(0);// 
    aTable.setBorder(2);// 

    aTable.endHeaders();
    Cell cell = null;
    cell = new Cell(new Phrase("\n" + "" + hostname + "" + "\n", titleFont));
    cell.setColspan(8);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_CENTER);
    aTable.addCell(cell);
    cell = new Cell(new Phrase("\n" + "" + "\n", titleFont));
    aTable.addCell(cell);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    cell = new Cell(new Phrase("\n" + starttime + "  " + totime + "\n", contextFont1));
    cell.setColspan(7);

    aTable.addCell(cell);
    cell = new Cell(new Phrase("\n" + "" + "\n", titleFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(hostnameDoc, contextFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase("IP", titleFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(ip));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);

    cell = new Cell(new Phrase("", titleFont));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(typename));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase("\n" + "" + "\n", titleFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    String grade = (String) reportHash.get("grade");
    cell = new Cell(new Phrase("\n" + grade + "\n", contextFont));
    cell.setColspan(7);

    aTable.addCell(cell);
    cell = new Cell(new Phrase("" + "\n" + "" + "\n" + "" + "\n" + "", titleFont));
    cell.setRowspan(10);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);

    cell = new Cell(new Phrase("\n" + "" + "\n", titleFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase("\n" + "" + "\n", titleFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase((String) maxping.get("pingmax")));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase("", titleFont));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);

    cell = new Cell(new Phrase((String) maxping.get("avgpingcon")));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);

    cell = new Cell(new Phrase("\n" + "" + "\n", titleFont));

    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase("\n" + ":" + "\n", titleFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(lasttime));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(":", titleFont));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(nexttime));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);

    cell = new Cell(new Phrase("\n" + "" + "\n", titleFont));
    cell.setRowspan(8);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);

    cell = new Cell(new Phrase("\n" + "32 :" + "\n", titleFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(totalBytesSentHighWord));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase("32 :", titleFont));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(totalBytesSentLowWord));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);

    cell = new Cell(new Phrase("\n" + "32 :" + "\n", titleFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(totalBytesReceivedHighWord));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase("32 :", titleFont));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(totalBytesReceivedLowWord));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);

    cell = new Cell(new Phrase("\n" + ":" + "\n", titleFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(totalFilesSent));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(":", titleFont));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(totalFilesReceived));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);

    cell = new Cell(new Phrase("\n" + ":" + "\n", titleFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(currentAnonymousUsers));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(":", titleFont));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(totalAnonymousUsers));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);

    cell = new Cell(new Phrase("\n" + ":" + "\n", titleFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(maxAnonymousUsers));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(":", titleFont));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(currentConnections));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);

    cell = new Cell(new Phrase("\n" + ":" + "\n", titleFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(maxConnections));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase("::", titleFont));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(connectionAttempts));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);

    cell = new Cell(new Phrase("\n" + ":" + "\n", titleFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(logonAttempts));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase("GET:", titleFont));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(totalGets));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);

    cell = new Cell(new Phrase("\n" + "POST:" + "\n", titleFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(totalPosts));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(":", titleFont));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(totalNotFoundErrors));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);

    cell = new Cell(new Phrase("" + "\n" + "" + "\n" + "" + "\n" + "", titleFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase("\n" + "" + downnum + "" + "\n", contextFont));
    cell.setColspan(7);
    aTable.addCell(cell);

    cell = new Cell(new Phrase("\n" + "" + "\n", titleFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    cell.setColspan(8);
    aTable.addCell(cell);
    String strping = "";
    if ("0".equals(downnum)) {
        strping = "    2   " + downnum + "" + "\n"
                + "\n";
    } else {
        strping = "    2   " + "\n" + "\n";
    }
    cell = new Cell(new Phrase("    1   " + " \n" + "\n"
            + strping + "\n" + "\n" + "\n", contextFont)

    );
    cell.setColspan(8);
    aTable.addCell(cell);
    // end 

    // end  }
    document.add(aTable);
    document.close();

}

From source file:com.afunms.report.abstraction.ExcelReport1.java

public void createReport_informixall(String filename) {
    if (impReport.getTable() == null) {
        fileName = null;//from  w w w . ja  v a2 s.c  om
        return;
    }
    WritableWorkbook wb = null;
    try {
        // fileName = ResourceCenter.getInstance().getSysPath() +
        // "temp\\dhcnms_report.xls";
        fileName = ResourceCenter.getInstance().getSysPath() + filename;
        wb = Workbook.createWorkbook(new File(fileName));
        Hashtable allreporthash = new Hashtable();
        allreporthash = reportHash;
        if (allreporthash != null && allreporthash.size() > 0) {
            Iterator keys = allreporthash.keySet().iterator();
            String ip = "";
            int sheetNum = 0;
            while (keys.hasNext()) {
                ip = keys.next().toString();
                String newip = doip(ip);
                Hashtable report_has = (Hashtable) allreporthash.get(ip);

                String hostname = (String) report_has.get("dbname");
                WritableSheet sheet = wb.createSheet(hostname + "", 0);
                String Ping = (String) report_has.get("Ping");
                String starttime = (String) report_has.get("starttime");
                String totime = (String) report_has.get("totime");
                Hashtable dbinfo = new Hashtable();
                dbinfo = (Hashtable) report_has.get("dbValue");
                Hashtable maxping = (Hashtable) report_has.get("ping");

                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

                this.dbTitlePing(sheet, ip, report_has);
                int row = 18;
                Label tmpLabel = null;
                tmpLabel = new Label(0, row, "   ", labelFormat);
                sheet.addCell(tmpLabel);
                sheet.mergeCells(0, row, 10, row);
                row++;
                tmpLabel = new Label(0, row, "", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(1, row, " ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(2, row, " ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(3, row, "", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(4, row, "", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(5, row, " ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(7, row, " ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(9, row, "  ", b_labelFormat);
                sheet.addCell(tmpLabel);
                sheet.mergeCells(5, row, 6, row);
                sheet.mergeCells(7, row, 8, row);
                sheet.mergeCells(9, row, 10, row);
                row++;
                // 
                ArrayList dbspaces = new ArrayList();
                if (dbinfo != null) {
                    dbspaces = (ArrayList) dbinfo.get("informixspaces");// 
                }
                if (dbspaces != null) {
                    if (dbspaces.size() > 0) {
                        DecimalFormat df = new DecimalFormat("#.###");
                        for (int i = 0; i < dbspaces.size(); i++) {
                            p_labelFormat = this.colorChange(i);
                            Hashtable tablesVO = (Hashtable) dbspaces.get(i);
                            tmpLabel = new Label(0, row, (i + 1) + "", p_labelFormat);
                            sheet.addCell(tmpLabel);
                            tmpLabel = new Label(1, row, (String) tablesVO.get("dbspace"), p_labelFormat);
                            sheet.addCell(tmpLabel);
                            tmpLabel = new Label(2, row, (String) tablesVO.get("owner"), p_labelFormat);
                            sheet.addCell(tmpLabel);
                            tmpLabel = new Label(3, row, (String) tablesVO.get("fname"), p_labelFormat);
                            sheet.addCell(tmpLabel);
                            tmpLabel = new Label(4, row,
                                    df.format(Float.parseFloat(tablesVO.get("pages_size") + "")) + "M",
                                    p_labelFormat);
                            sheet.addCell(tmpLabel);
                            tmpLabel = new Label(5, row,
                                    df.format(Float.parseFloat(tablesVO.get("pages_used") + "")) + "M",
                                    p_labelFormat);
                            sheet.addCell(tmpLabel);
                            tmpLabel = new Label(7, row,
                                    df.format(Float.parseFloat(tablesVO.get("pages_free") + "")) + "M",
                                    p_labelFormat);
                            sheet.addCell(tmpLabel);
                            tmpLabel = new Label(9, row,
                                    df.format(100 - Float.parseFloat(tablesVO.get("percent_free") + "")) + "%",
                                    p_labelFormat);
                            sheet.addCell(tmpLabel);
                            sheet.mergeCells(5, row, 6, row);
                            sheet.mergeCells(7, row, 8, row);
                            sheet.mergeCells(9, row, 10, row);
                            row++;
                        }
                    }
                }
                row = row + 2;
                // Informix
                tmpLabel = new Label(0, row, "     ", labelFormat);
                sheet.addCell(tmpLabel);
                sheet.mergeCells(0, row, 10, row);
                row++;
                tmpLabel = new Label(0, row, "", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(1, row, "  ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(2, row, " ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(3, row, "", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(4, row, " ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(5, row, " ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(7, row, " ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(9, row, "  ", b_labelFormat);
                sheet.addCell(tmpLabel);
                sheet.mergeCells(5, row, 6, row);
                sheet.mergeCells(7, row, 8, row);
                sheet.mergeCells(9, row, 10, row);
                row++;
                List dbsession = (ArrayList) dbinfo.get("sessionList");// 
                if (dbsession != null && dbsession.size() > 0) {
                    for (int i = 0; i < dbsession.size(); i++) {
                        p_labelFormat = this.colorChange(i);
                        Hashtable tablesVO = (Hashtable) dbsession.get(i);
                        String seqscans = String.valueOf(tablesVO.get("seqscans"));
                        if ("null".equals(seqscans)) {
                            seqscans = "";
                        }
                        String total_sorts = String.valueOf(tablesVO.get("total_sorts"));
                        if ("null".equals(total_sorts)) {
                            total_sorts = "";
                        }
                        String dsksorts = String.valueOf(tablesVO.get("dsksorts"));
                        if ("null".equals(dsksorts)) {
                            dsksorts = "";
                        }
                        tmpLabel = new Label(0, row, (i + 1) + "", p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(1, row, (String) tablesVO.get("username"), p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(2, row, (String) tablesVO.get("hostname"), p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(3, row, tablesVO.get("access") + "", p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(4, row, tablesVO.get("locksheld") + "", p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(5, row, seqscans, p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(7, row, total_sorts, p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(9, row, dsksorts, p_labelFormat);
                        sheet.addCell(tmpLabel);
                        sheet.mergeCells(5, row, 6, row);
                        sheet.mergeCells(7, row, 8, row);
                        sheet.mergeCells(9, row, 10, row);
                        row++;
                    }
                }

                row = row + 2;
                // Informix
                tmpLabel = new Label(0, row, "    ", labelFormat);
                sheet.addCell(tmpLabel);
                sheet.mergeCells(0, row, 10, row);
                row++;
                tmpLabel = new Label(0, row, "", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(1, row, "  ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(3, row, " ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(5, row, "", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(7, row, " ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(9, row, "  ", b_labelFormat);
                sheet.addCell(tmpLabel);
                sheet.mergeCells(1, row, 2, row);
                sheet.mergeCells(3, row, 4, row);
                sheet.mergeCells(5, row, 6, row);
                sheet.mergeCells(7, row, 8, row);
                sheet.mergeCells(9, row, 10, row);
                row++;
                List dblock = (ArrayList) dbinfo.get("lockList");// 
                if (dblock != null && dblock.size() > 0) {
                    for (int i = 0; i < dblock.size(); i++) {
                        p_labelFormat = this.colorChange(i);
                        Hashtable tablesVO = (Hashtable) dblock.get(i);
                        String type = (String) tablesVO.get("type");
                        String desc = "";
                        if ("B".equals(type)) {
                            desc = "";
                        } else if ("IS".equals(type)) {
                            desc = "";
                        } else if ("S".equals(type)) {
                            desc = "";
                        } else if ("XS".equals(type)) {
                            desc = "";
                        } else if ("U".equals(type)) {
                            desc = "";
                        } else if ("IX".equals(type)) {
                            desc = "";
                        } else if ("SIX".equals(type)) {
                            desc = "";
                        } else if ("X".equals(type)) {
                            desc = "";
                        } else if ("XR".equals(type)) {
                            desc = "";
                        }
                        tmpLabel = new Label(0, row, (i + 1) + "", p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(1, row, (String) tablesVO.get("username"), p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(3, row, (String) tablesVO.get("hostname"), p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(5, row, tablesVO.get("dbsname") + "", p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(7, row, tablesVO.get("tabname") + "", p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(9, row, desc, p_labelFormat);
                        sheet.addCell(tmpLabel);
                        sheet.mergeCells(1, row, 2, row);
                        sheet.mergeCells(3, row, 4, row);
                        sheet.mergeCells(5, row, 6, row);
                        sheet.mergeCells(7, row, 8, row);
                        sheet.mergeCells(9, row, 10, row);
                        row++;
                    }
                }
                row = row + 2;

                // Informix
                tmpLabel = new Label(0, row, "     ", labelFormat);
                sheet.addCell(tmpLabel);
                sheet.mergeCells(0, row, 10, row);
                row++;
                tmpLabel = new Label(0, row, "", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(1, row, "ID  ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(2, row, " ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(3, row, " ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(4, row, " ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(5, row, "  ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(6, row, " ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(7, row, "  ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(9, row, "  ", b_labelFormat);
                sheet.addCell(tmpLabel);
                sheet.mergeCells(7, row, 8, row);
                sheet.mergeCells(9, row, 10, row);
                row++;
                List dblog = (ArrayList) dbinfo.get("informixlog");// 
                if (dblog != null && dblog.size() > 0) {
                    for (int i = 0; i < dblog.size(); i++) {
                        p_labelFormat = this.colorChange(i);
                        Hashtable tablesVO = (Hashtable) dblog.get(i);
                        tmpLabel = new Label(0, row, (i + 1) + "", p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(1, row, String.valueOf(tablesVO.get("uniqid")), p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(2, row, String.valueOf(tablesVO.get("size")), p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(3, row, String.valueOf(tablesVO.get("used")), p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(4, row, String.valueOf(tablesVO.get("is_used")), p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(5, row, String.valueOf(tablesVO.get("is_current")), p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(6, row, String.valueOf(tablesVO.get("is_backed_up")),
                                p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(7, row, String.valueOf(tablesVO.get("is_archived")),
                                p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(9, row, String.valueOf(tablesVO.get("is_temp")), p_labelFormat);
                        sheet.addCell(tmpLabel);
                        sheet.mergeCells(7, row, 8, row);
                        sheet.mergeCells(9, row, 10, row);
                        row++;
                    }
                }
                row = row + 2;

                // InformixIO
                tmpLabel = new Label(0, row, "IO ", labelFormat);
                sheet.addCell(tmpLabel);
                sheet.mergeCells(0, row, 10, row);
                row++;
                tmpLabel = new Label(0, row, "", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(1, row, "   ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(2, row, "  ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(3, row, " ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(4, row, " ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(5, row, "  ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(6, row, "  ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(7, row, "   ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(8, row, "   ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(9, row, "    ", b_labelFormat);
                sheet.addCell(tmpLabel);
                sheet.mergeCells(9, row, 10, row);
                row++;
                List dbio = (ArrayList) dbinfo.get("iolist");// IO
                if (dbio != null && dbio.size() > 0) {
                    for (int i = 0; i < dbio.size(); i++) {
                        p_labelFormat = this.colorChange(i);
                        Hashtable tablesVO = (Hashtable) dbio.get(i);
                        tmpLabel = new Label(0, row, (i + 1) + "", p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(1, row, String.valueOf(tablesVO.get("chunknum")), p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(2, row, String.valueOf(tablesVO.get("reads")), p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(3, row, String.valueOf(tablesVO.get("pagesread")), p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(4, row, String.valueOf(tablesVO.get("writes")), p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(5, row, String.valueOf(tablesVO.get("pageswritten")),
                                p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(6, row, String.valueOf(tablesVO.get("mreads")), p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(7, row, String.valueOf(tablesVO.get("mpagesread")), p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(8, row, String.valueOf(tablesVO.get("mwrites")), p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(9, row, String.valueOf(tablesVO.get("mpageswritten")),
                                p_labelFormat);
                        sheet.addCell(tmpLabel);
                        sheet.mergeCells(9, row, 10, row);
                        row++;
                    }
                }
                row = row + 2;
                //    
                this.addEventReport(sheet, report_has, row);
                row += 2;
                // 
                this.addEventListToExcel(sheet, row);
                if (impReport.getChart() != null) {
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    try {
                        ChartUtilities.writeChartAsPNG(baos, impReport.getChart().getChart(),
                                impReport.getChart().getWidth(), impReport.getChart().getHeight());
                    } catch (IOException ioe) {
                        SysLogger.error("", ioe);
                    }
                    WritableImage wi = new WritableImage(2, 10000 + 5, 8, 12, baos.toByteArray());
                    sheet.addImage(wi);
                }
            }
            wb.write();
        }

    } catch (Exception e) {
        // SysLogger.error("Error in ExcelReport.createReport()",e);
        SysLogger.error("", e);
    } finally {
        try {
            if (wb != null)
                wb.close();
        } catch (Exception e) {
        }
    }
}

From source file:com.afunms.report.abstraction.ExcelReport1.java

public void createReport_syball2(String filename) {
    if (impReport.getTable() == null) {
        fileName = null;/*from w ww.  j a  v  a2  s  . com*/
        return;
    }
    WritableWorkbook wb = null;
    try {
        // fileName = ResourceCenter.getInstance().getSysPath() +
        // "temp\\dhcnms_report.xls";
        fileName = ResourceCenter.getInstance().getSysPath() + filename;
        wb = Workbook.createWorkbook(new File(fileName));
        Hashtable allreporthash = new Hashtable();
        allreporthash = reportHash;
        if (allreporthash != null && allreporthash.size() > 0) {
            Iterator keys = allreporthash.keySet().iterator();
            String ip = "";
            int sheetNum = 0;
            while (keys.hasNext()) {
                ip = keys.next().toString();
                String newip = doip(ip);
                Hashtable report_has = (Hashtable) allreporthash.get(ip);

                String hostname = (String) report_has.get("dbname");
                WritableSheet sheet = wb.createSheet(hostname + "", 0);
                String Ping = (String) report_has.get("Ping");
                String starttime = (String) report_has.get("starttime");
                String totime = (String) report_has.get("totime");
                Hashtable mems = (Hashtable) report_has.get("mems");// 
                Hashtable sysValue = (Hashtable) report_has.get("sysValue");// 
                String typename = (String) report_has.get("typename");
                String runstr = (String) report_has.get("runstr");
                String grade = (String) report_has.get("grade");
                String pingnow = (String) report_has.get("pingnow");
                String pingmin = (String) report_has.get("pingmin");
                String pingconavg = (String) report_has.get("pingconavg");
                DBVo vo = (DBVo) report_has.get("vo");
                Hashtable maxping = (Hashtable) report_has.get("ping");
                SybaseVO sysbaseVO = (SybaseVO) report_has.get("sysbaseVO");

                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

                WritableFont labelFont = new WritableFont(WritableFont.createFont(""), 12,
                        WritableFont.BOLD, false);
                WritableCellFormat labelFormat = new WritableCellFormat(labelFont);

                WritableCellFormat _labelFormat = new WritableCellFormat();
                _labelFormat.setBackground(jxl.format.Colour.GRAY_25);

                WritableCellFormat p_labelFormat = new WritableCellFormat();
                p_labelFormat.setBackground(jxl.format.Colour.ICE_BLUE);

                WritableCellFormat b_labelFormat = new WritableCellFormat();
                b_labelFormat.setBackground(jxl.format.Colour.GRAY_50);

                Label tmpLabel = null;
                tmpLabel = new Label(1, 0, hostname + "", labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(0, 1, ":" + impReport.getTimeStamp());
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(0, 2, ": " + starttime + "  " + totime);
                sheet.addCell(tmpLabel);

                // ip
                tmpLabel = new Label(0, 4, "", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(1, 4, "IP", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(2, 4, "", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(3, 4, "", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(4, 4, "", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(0, 5, vo.getDbName(), p_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(1, 5, ip, p_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(2, 5, typename, p_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(3, 5, runstr, p_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(4, 5, grade, p_labelFormat);
                sheet.addCell(tmpLabel);

                // 
                tmpLabel = new Label(0, 7, "", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(1, 7, "", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(2, 7, "", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(0, 8, pingnow + "%", p_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(1, 8, pingmin + "%", p_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(2, 8, pingconavg + "%", p_labelFormat);
                sheet.addCell(tmpLabel);

                // 
                File file = new File(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/"
                        + newip + "ConnectUtilization" + ".png");
                // sheet,0,0,5,1,,,
                // allRow = allRow+2;
                sheet.addImage(new WritableImage(1, 9, 7, 7, file));
                // allRow = allRow+7;
                int row = 15;
                tmpLabel = new Label(0, row, "", labelFormat);
                sheet.addCell(tmpLabel);
                row++;
                tmpLabel = new Label(0, row, "", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(1, row, " ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(2, row, "MB", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(3, row, "MB ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(4, row, "(%)", b_labelFormat);
                sheet.addCell(tmpLabel);
                row++;

                List dbInfo = (ArrayList) sysbaseVO.getDbInfo();
                if (dbInfo != null && dbInfo.size() > 0) {

                    for (int i = 0; i < dbInfo.size(); i++) {
                        TablesVO tempSpace = (TablesVO) dbInfo.get(i);
                        String db_name = (String) tempSpace.getDb_name();
                        String db_size = (String) tempSpace.getDb_size();
                        String db_freesize = (String) tempSpace.getDb_freesize();
                        String db_usedperc = (String) tempSpace.getDb_usedperc();
                        tmpLabel = new Label(0, row, (i + 1) + "", p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(1, row, db_name, p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(2, row, db_size, p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(3, row, db_freesize, p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(4, row, db_usedperc, p_labelFormat);
                        sheet.addCell(tmpLabel);
                        row++;
                    }
                }
                row = row + 2;

                // 
                tmpLabel = new Label(0, row, " ", labelFormat);
                sheet.addCell(tmpLabel);
                row++;
                tmpLabel = new Label(0, row, "(MB)", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(1, row, "(MB) ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(2, row, "Metadata(MB)", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(3, row, "(MB) ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(4, row, "(MB) ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(5, row, "(%)", b_labelFormat);
                sheet.addCell(tmpLabel);
                row++;
                tmpLabel = new Label(0, row, sysbaseVO.getTotal_dataCache(), p_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(1, row, sysbaseVO.getTotal_physicalMemory(), p_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(2, row, sysbaseVO.getMetadata_cache(), p_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(3, row, sysbaseVO.getProcedure_cache(), p_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(4, row, sysbaseVO.getTotal_logicalMemory(), p_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(5, row, sysbaseVO.getData_hitrate(), p_labelFormat);
                sheet.addCell(tmpLabel);
                row++;

                // Sysbase 
                tmpLabel = new Label(0, row, "Sysbase   ", labelFormat);
                sheet.addCell(tmpLabel);
                row++;
                tmpLabel = new Label(0, row, " ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(1, row, "  ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(2, row, "  ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(3, row, "  ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(4, row, " ", b_labelFormat);
                sheet.addCell(tmpLabel);
                row++;
                List serverlist = (List) sysbaseVO.getServersInfo();
                if (serverlist != null && serverlist.size() > 0) {
                    for (int k = 0; k < serverlist.size(); k++) {
                        TablesVO tVO = (TablesVO) serverlist.get(k);
                        tmpLabel = new Label(0, row, (k + 1) + "", p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(1, row, tVO.getServer_name(), p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(2, row, tVO.getServer_network_name(), p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(3, row, tVO.getServer_class(), p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(4, row, tVO.getServer_status(), p_labelFormat);
                        sheet.addCell(tmpLabel);
                        row++;
                    }
                }
                row = row + 2;

                // Sysbase 
                tmpLabel = new Label(0, row, "Sysbase   ", labelFormat);
                sheet.addCell(tmpLabel);
                row++;
                tmpLabel = new Label(0, row, " ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(1, row, "   ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(2, row, "id   ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(3, row, "   ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(4, row, "  ", b_labelFormat);
                sheet.addCell(tmpLabel);
                row++;
                List userlist = (List) sysbaseVO.getUserInfo();
                if (userlist != null && userlist.size() > 0) {
                    for (int k = 0; k < userlist.size(); k++) {
                        TablesVO tVO = (TablesVO) userlist.get(k);
                        tmpLabel = new Label(0, row, (k + 1) + "", p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(1, row, tVO.getUsers_name(), p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(2, row, tVO.getID_in_db(), p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(3, row, tVO.getGroup_name(), p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(4, row, tVO.getLogin_name(), p_labelFormat);
                        sheet.addCell(tmpLabel);
                        row++;
                    }
                }
                row = row + 2;

                // Sysbase 
                tmpLabel = new Label(0, row, "Sysbase   ", labelFormat);
                sheet.addCell(tmpLabel);
                row++;
                tmpLabel = new Label(0, row, " ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(1, row, "   ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(2, row, "    ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(3, row, "    ", b_labelFormat);
                sheet.addCell(tmpLabel);
                row++;
                List devicelist = (List) sysbaseVO.getDeviceInfo();
                if (devicelist != null && devicelist.size() > 0) {
                    for (int k = 0; k < devicelist.size(); k++) {
                        TablesVO tVO = (TablesVO) devicelist.get(k);
                        tmpLabel = new Label(0, row, (k + 1) + "", p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(1, row, tVO.getDevice_name(), p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(2, row, tVO.getDevice_physical_name(), p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(3, row, tVO.getDevice_description(), p_labelFormat);
                        sheet.addCell(tmpLabel);
                        row++;
                    }
                }
                row = row + 2;

                //    
                tmpLabel = new Label(0, row, "     ", labelFormat);
                sheet.addCell(tmpLabel);
                row++;
                tmpLabel = new Label(0, row, "", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(1, row, " ", b_labelFormat);
                sheet.addCell(tmpLabel);
                row++;
                tmpLabel = new Label(0, row, (String) report_has.get("downnum"), p_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(1, row, report_has.get("count") + "", p_labelFormat);
                sheet.addCell(tmpLabel);

                // 
                WritableCellFormat red_labelFormat = new WritableCellFormat();
                WritableCellFormat orange_labelFormat = new WritableCellFormat();
                WritableCellFormat yellow_labelFormat = new WritableCellFormat();

                red_labelFormat.setBackground(jxl.format.Colour.RED);
                orange_labelFormat.setBackground(jxl.format.Colour.ORANGE);
                yellow_labelFormat.setBackground(jxl.format.Colour.YELLOW);

                row = row + 2;
                tmpLabel = new Label(0, row, "", labelFormat);
                sheet.addCell(tmpLabel);
                row++;
                tmpLabel = new Label(0, row, " ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(1, row, "", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(2, row, " ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(3, row, " ", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(4, row, "", b_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(5, row, "", b_labelFormat);
                sheet.addCell(tmpLabel);
                row++;
                int index = 0;
                java.text.SimpleDateFormat _sdf = new java.text.SimpleDateFormat("MM-dd HH:mm");
                List list = (ArrayList) report_has.get("list");
                if (list != null && list.size() > 0) {
                    for (int i = 0; i < list.size(); i++) {
                        index++;
                        EventList eventlist = (EventList) list.get(i);
                        Date cc = eventlist.getRecordtime().getTime();
                        Integer eventid = eventlist.getId();
                        String eventlocation = eventlist.getEventlocation();
                        String content = eventlist.getContent();
                        String level = String.valueOf(eventlist.getLevel1());
                        String status = String.valueOf(eventlist.getManagesign());
                        String s = status;
                        String showlevel = null;
                        String act = "";
                        if ("1".equals(level)) {
                            showlevel = "";
                        } else if ("2".equals(level)) {
                            showlevel = "";
                        } else {
                            showlevel = "";
                        }
                        if ("0".equals(status)) {
                            status = "";
                        }
                        if ("1".equals(status)) {
                            status = "";
                        }
                        if ("2".equals(status)) {
                            status = "";
                        }
                        String rptman = eventlist.getReportman();
                        String rtime1 = _sdf.format(cc);

                        tmpLabel = new Label(0, row, String.valueOf(index), p_labelFormat);
                        sheet.addCell(tmpLabel);
                        if ("3".equals(level)) {
                            tmpLabel = new Label(1, row, showlevel, red_labelFormat);
                            sheet.addCell(tmpLabel);
                        } else if ("2".equals(level)) {
                            tmpLabel = new Label(1, row, showlevel, orange_labelFormat);
                            sheet.addCell(tmpLabel);
                        } else {
                            tmpLabel = new Label(1, row, showlevel, yellow_labelFormat);
                            sheet.addCell(tmpLabel);
                        }
                        tmpLabel = new Label(2, row, content, p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(3, row, rtime1, p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(4, row, rptman, p_labelFormat);
                        sheet.addCell(tmpLabel);
                        tmpLabel = new Label(5, row, status, p_labelFormat);
                        sheet.addCell(tmpLabel);
                        row++;
                    }
                }

                if (impReport.getChart() != null) {
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    try {
                        ChartUtilities.writeChartAsPNG(baos, impReport.getChart().getChart(),
                                impReport.getChart().getWidth(), impReport.getChart().getHeight());
                    } catch (IOException ioe) {
                    }
                    WritableImage wi = new WritableImage(2, 10000 + 5, 8, 12, baos.toByteArray());
                    sheet.addImage(wi);
                }
            }
            wb.write();
        }

    } catch (Exception e) {
        // SysLogger.error("Error in ExcelReport.createReport()",e);
        SysLogger.error("", e);
    } finally {
        try {
            if (wb != null)
                wb.close();
        } catch (Exception e) {
        }
    }
}

From source file:com.afunms.report.abstraction.ExcelReport1.java

public void createReport_sqlPDF(String filename) throws DocumentException, IOException {
    if (impReport.getTable() == null) {
        fileName = null;/*  w  ww  .  j a  va  2  s  .c  om*/
        return;
    }
    try {
        // 
        Document document = new Document(PageSize.A4);
        // (Writer)document(Writer)
        PdfWriter.getInstance(document, new FileOutputStream(filename));
        document.open();
        // 
        BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
        // 
        Font titleFont = new Font(bfChinese, 12, Font.BOLD);
        // 
        Font contextFont = new Font(bfChinese, 12, Font.NORMAL);
        String hostname = (String) reportHash.get("dbname");
        String ip = (String) reportHash.get("ip");
        String newip = doip(ip);
        Paragraph title = new Paragraph(hostname + "", titleFont);
        // 
        title.setAlignment(Element.ALIGN_CENTER);
        // title.setFont(titleFont);
        document.add(title);
        String Ping = (String) reportHash.get("Ping");
        String starttime = (String) reportHash.get("starttime");
        String totime = (String) reportHash.get("totime");

        Hashtable maxping = (Hashtable) reportHash.get("ping");

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        String contextString = ":" + impReport.getTimeStamp() + " \n"// 
                + ":" + starttime + "  " + totime;

        Paragraph context = new Paragraph(contextString, contextFont);
        // 
        context.setAlignment(Element.ALIGN_LEFT);
        // context.setFont(contextFont);
        // 
        context.setSpacingBefore(5);
        // 
        context.setFirstLineIndent(5);
        document.add(context);
        document.add(new Paragraph("\n"));
        /*
         * tmpLabel = new Label(0, 1, ":" + impReport.getTimeStamp());
         * sheet.addCell(tmpLabel); tmpLabel = new Label(0, 2, ": " +
         * starttime + "  " + totime);
         */
        PdfPTable aTable = new PdfPTable(3);
        float[] widths = { 220f, 220f, 220f };
        aTable.setWidths(widths);
        aTable.setWidthPercentage(100);
        PdfPCell cell = null;
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new PdfPCell(new Phrase((String) maxping.get("pingnow")));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new PdfPCell(new Phrase((String) maxping.get("pingmax")));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new PdfPCell(new Phrase((String) maxping.get("avgpingcon")));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);

        Image img = Image.getInstance(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/"
                + newip + "ConnectUtilization" + ".png");
        img.setAlignment(Image.LEFT);//
        //  document.add(aTable);
        img.scalePercent(76);
        document.add(aTable);
        document.add(img);

        document.add(new Paragraph("\n"));
        PdfPTable aTable1 = new PdfPTable(6);
        float[] width = { 220f, 220f, 220f, 220f, 220f, 220f };
        aTable1.setWidths(width);
        aTable1.setWidthPercentage(100);
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new PdfPCell(new Phrase("MB", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new PdfPCell(new Phrase("MB", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new PdfPCell(new Phrase("(%)", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        // aTable1.endHeaders();

        // 
        Hashtable dbValue = (Hashtable) reportHash.get("tableinfo_v");
        Hashtable alldatabase = new Hashtable();
        if (dbValue.get("database") != null)
            alldatabase = (Hashtable) dbValue.get("database");
        Vector names = new Vector();
        if (dbValue.get("names") != null)
            names = (Vector) dbValue.get("names");

        if (alldatabase != null && alldatabase.size() > 0) {
            if (names == null)
                names = new Vector();
            int row = 1;
            for (int i = 0; i < names.size(); i++) {
                String key = (String) names.get(i);
                if (alldatabase.get(key) == null)
                    continue;
                Hashtable data = (Hashtable) alldatabase.get(key);
                String dbname = data.get("dbname").toString();
                String size = data.get("size").toString();
                String usedsize = "";
                if (data.get("usedsize") != null) {
                    usedsize = data.get("usedsize").toString();
                }
                String usedperc = "";
                if (data.get("usedperc") != null)
                    usedperc = data.get("usedperc").toString();
                cell = new PdfPCell(new Phrase(""));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                cell = new PdfPCell(new Phrase(row + ""));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                cell = new PdfPCell(new Phrase(dbname));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                cell = new PdfPCell(new Phrase(size));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                cell = new PdfPCell(new Phrase(usedsize));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                cell = new PdfPCell(new Phrase(usedperc));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                row++;

            }
        }

        if (impReport.getChart() != null) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            try {
                ChartUtilities.writeChartAsPNG(baos, impReport.getChart().getChart(),
                        impReport.getChart().getWidth(), impReport.getChart().getHeight());
            } catch (IOException ioe) {
            }
            Image img1 = Image.getInstance(baos.toByteArray());
            img1.setAbsolutePosition(0, 0);
            img1.setAlignment(Image.MIDDLE);// 

            document.add(img1);
        }

        document.add(aTable1);
        document.close();
    } catch (Exception e) {
        // TODO: handle exception
    }
}

From source file:com.afunms.report.abstraction.ExcelReport1.java

public void createReport_sqlDoc(String filename) throws DocumentException, IOException {
    if (impReport.getTable() == null) {
        fileName = null;/*from w  w w.ja  va 2s.co  m*/
        return;
    }
    try {
        // 
        Document document = new Document(PageSize.A4);
        // (Writer)document(Writer)
        RtfWriter2.getInstance(document, new FileOutputStream(filename));
        document.open();
        // 
        BaseFont bfChinese = BaseFont.createFont("Times-Roman", "", BaseFont.NOT_EMBEDDED);
        // 
        Font titleFont = new Font(bfChinese, 12, Font.BOLD);
        // 
        Font contextFont = new Font(bfChinese, 12, Font.NORMAL);
        String hostname = (String) reportHash.get("dbname");
        String ip = (String) reportHash.get("ip");
        String newip = doip(ip);
        Paragraph title = new Paragraph(hostname + "", titleFont);
        // 
        title.setAlignment(Element.ALIGN_CENTER);
        // title.setFont(titleFont);
        document.add(title);
        String Ping = (String) reportHash.get("Ping");
        String starttime = (String) reportHash.get("starttime");
        String totime = (String) reportHash.get("totime");

        Hashtable maxping = (Hashtable) reportHash.get("ping");

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        String contextString = ":" + impReport.getTimeStamp() + " \n"// 
                + ":" + starttime + "  " + totime;

        Paragraph context = new Paragraph(contextString, contextFont);
        // 
        context.setAlignment(Element.ALIGN_LEFT);
        // context.setFont(contextFont);
        // 
        context.setSpacingBefore(5);
        // 
        context.setFirstLineIndent(5);
        document.add(context);
        /*
         * tmpLabel = new Label(0, 1, ":" + impReport.getTimeStamp());
         * sheet.addCell(tmpLabel); tmpLabel = new Label(0, 2, ": " +
         * starttime + "  " + totime);
         */
        Table aTable = new Table(3);
        float[] widths = { 220f, 220f, 220f };
        aTable.setWidths(widths);
        aTable.setWidth(100); //  90%
        aTable.setAlignment(Element.ALIGN_CENTER);// 
        aTable.setAutoFillEmptyCells(true); // 
        aTable.setBorderWidth(1); // 
        aTable.setBorderColor(new Color(0, 125, 255)); // 
        aTable.setPadding(2);// 
        aTable.setSpacing(0);// 
        aTable.setBorder(2);// 
        aTable.endHeaders();
        Cell cell = null;
        cell = new Cell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new Cell(new Phrase((String) maxping.get("pingnow"), contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new Cell(new Phrase((String) maxping.get("pingmax"), contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new Cell(new Phrase((String) maxping.get("avgpingcon"), contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);

        // 

        document.add(aTable);
        Image img = Image.getInstance(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/"
                + newip + "ConnectUtilization" + ".png");
        img.setAlignment(Image.LEFT);//
        document.add(img);

        document.add(new Paragraph("\n"));
        Table aTable1 = new Table(6);
        float[] width = { 220f, 220f, 220f, 220f, 220f, 220f };
        aTable1.setWidths(width);
        aTable1.setWidth(100); //  90%
        aTable1.setAlignment(Element.ALIGN_CENTER);// 
        aTable1.setAutoFillEmptyCells(true); // 
        aTable1.setBorderWidth(1); // 
        aTable1.setBorderColor(new Color(0, 125, 255)); // 
        aTable1.setPadding(2);// 
        aTable1.setSpacing(0);// 
        aTable1.setBorder(2);// 

        cell = new Cell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new Cell(new Phrase("MB", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new Cell(new Phrase("MB", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new Cell(new Phrase("(%)", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        // aTable1.endHeaders();

        // 
        Hashtable dbValue = (Hashtable) reportHash.get("tableinfo_v");
        Hashtable alldatabase = new Hashtable();
        if (dbValue.get("database") != null)
            alldatabase = (Hashtable) dbValue.get("database");
        Vector names = new Vector();
        if (dbValue.get("names") != null)
            names = (Vector) dbValue.get("names");

        if (alldatabase != null && alldatabase.size() > 0) {
            if (names == null)
                names = new Vector();
            int row = 1;
            for (int i = 0; i < names.size(); i++) {
                String key = (String) names.get(i);
                if (alldatabase.get(key) == null)
                    continue;
                Hashtable data = (Hashtable) alldatabase.get(key);
                String dbname = data.get("dbname").toString();
                String size = data.get("size").toString();
                String usedsize = "";
                if (data.get("usedsize") != null) {
                    usedsize = data.get("usedsize").toString();
                }
                String usedperc = "";
                if (data.get("usedperc") != null)
                    usedperc = data.get("usedperc").toString();
                cell = new Cell(new Phrase(""));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                cell = new Cell(new Phrase(row + "", titleFont));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                cell = new Cell(new Phrase(dbname, titleFont));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                cell = new Cell(new Phrase(size, titleFont));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                cell = new Cell(new Phrase(usedsize, titleFont));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                cell = new Cell(new Phrase(usedperc, titleFont));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                row++;

            }
        }

        if (impReport.getChart() != null) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            try {
                ChartUtilities.writeChartAsPNG(baos, impReport.getChart().getChart(),
                        impReport.getChart().getWidth(), impReport.getChart().getHeight());
            } catch (IOException ioe) {
            }
            Image img1 = Image.getInstance(baos.toByteArray());
            img1.setAbsolutePosition(0, 0);
            img1.setAlignment(Image.MIDDLE);// 

            document.add(img1);
        }

        document.add(aTable1);
        document.close();
    } catch (Exception e) {
        // TODO: handle exception
    }
}

From source file:com.afunms.report.abstraction.ExcelReport1.java

/**
 * @author HONGLI sqlserverexcel/*  w w w . j  av a2  s. c o m*/
 * @param filename
 * @throws DocumentException
 * @throws IOException
 */
public void createReport_SqlServerCldXls(String filename) throws DocumentException, IOException {
    if (impReport.getTable() == null) {
        fileName = null;
        return;
    }
    WritableWorkbook wb = null;
    try {
        wb = Workbook.createWorkbook(new File(filename));

        String hostname = (String) reportHash.get("dbname");
        String ip = (String) reportHash.get("ip");
        String newip = doip(ip);
        WritableSheet sheet = wb.createSheet(hostname + "", 0);
        String Ping = (String) reportHash.get("Ping");
        String starttime = (String) reportHash.get("starttime");
        String totime = (String) reportHash.get("totime");
        Hashtable mems = (Hashtable) reportHash.get("mems");// 
        Hashtable sysValue = (Hashtable) reportHash.get("sysValue");// 
        String typename = (String) reportHash.get("typename");
        String runstr = (String) reportHash.get("runstr");
        String grade = (String) reportHash.get("grade");
        String pingnow = (String) reportHash.get("pingnow");
        String pingmin = (String) reportHash.get("pingmin");
        String pingconavg = (String) reportHash.get("pingconavg");
        DBVo vo = (DBVo) reportHash.get("vo");
        Hashtable maxping = (Hashtable) reportHash.get("ping");

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        WritableFont labelFont = new WritableFont(WritableFont.createFont(""), 12, WritableFont.BOLD,
                false);
        WritableCellFormat labelFormat = new WritableCellFormat(labelFont);

        WritableCellFormat _labelFormat = new WritableCellFormat();
        _labelFormat.setBackground(jxl.format.Colour.GRAY_25);

        WritableCellFormat p_labelFormat = new WritableCellFormat();
        p_labelFormat.setBackground(jxl.format.Colour.ICE_BLUE);

        WritableCellFormat b_labelFormat = new WritableCellFormat();
        b_labelFormat.setBackground(jxl.format.Colour.GRAY_50);

        Label tmpLabel = null;
        tmpLabel = new Label(1, 0, hostname + "", labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(0, 1, ":" + impReport.getTimeStamp());
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(0, 2, ": " + starttime + "  " + totime);
        sheet.addCell(tmpLabel);

        // ip
        tmpLabel = new Label(0, 4, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(1, 4, "IP", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(2, 4, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(3, 4, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(4, 4, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(0, 5, vo.getDbName(), p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(1, 5, ip, p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(2, 5, typename, p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(3, 5, runstr, p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(4, 5, grade, p_labelFormat);
        sheet.addCell(tmpLabel);

        // 
        tmpLabel = new Label(0, 7, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(1, 7, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(2, 7, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(0, 8, pingnow + "%", p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(1, 8, pingmin + "%", p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(2, 8, pingconavg + "%", p_labelFormat);
        sheet.addCell(tmpLabel);

        // 
        File file = new File(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/" + newip
                + "ConnectUtilization" + ".png");
        // sheet,0,0,5,1,,,
        // allRow = allRow+2;
        sheet.addImage(new WritableImage(1, 9, 7, 7, file));
        // allRow = allRow+7;

        // 
        tmpLabel = new Label(0, 16, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(1, 16, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(2, 16, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(3, 16, "SQL", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(4, 16, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(0, 17, (String) mems.get("totalMemory"), p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(1, 17, (String) mems.get("optMemory"), p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(2, 17, (String) mems.get("conMemory"), p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(3, 17, (String) mems.get("sqlMem"), p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(4, 17, (String) mems.get("lockMem"), p_labelFormat);
        sheet.addCell(tmpLabel);

        // 
        tmpLabel = new Label(0, 19, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(1, 19, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(2, 19, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(3, 19, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(0, 20, (String) sysValue.get("productlevel"), p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(1, 20, (String) sysValue.get("IsIntegratedSecurityOnly"), p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(2, 20, (String) sysValue.get("IsSingleUser"), p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(3, 20, (String) sysValue.get("IsClustered"), p_labelFormat);
        sheet.addCell(tmpLabel);

        // 
        tmpLabel = new Label(0, 22, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(1, 22, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(2, 22, "(MB)", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(3, 22, "(MB)", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(4, 22, "(%)", b_labelFormat);
        sheet.addCell(tmpLabel);

        int row = 22;
        // 
        Hashtable dbValue = (Hashtable) reportHash.get("tableinfo_v");
        Hashtable alldatabase = new Hashtable();
        if (dbValue.get("database") != null)
            alldatabase = (Hashtable) dbValue.get("database");
        Vector names = new Vector();
        if (dbValue.get("names") != null)
            names = (Vector) dbValue.get("names");

        if (alldatabase != null && alldatabase.size() > 0) {
            if (names == null)
                names = new Vector();
            for (int i = 0; i < names.size(); i++) {
                String key = (String) names.get(i);
                if (alldatabase.get(key) == null)
                    continue;
                Hashtable data = (Hashtable) alldatabase.get(key);
                String dbname = data.get("dbname").toString();
                String size = data.get("size").toString();
                String usedsize = "";
                if (data.get("usedsize") != null) {
                    usedsize = data.get("usedsize").toString();
                }
                String usedperc = "";
                if (data.get("usedperc") != null)
                    usedperc = data.get("usedperc").toString();
                row = row + 1;
                tmpLabel = new Label(0, row, i + "", p_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(1, row, dbname, p_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(2, row, size, p_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(3, row, usedsize, p_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(4, row, usedperc, p_labelFormat);
                sheet.addCell(tmpLabel);
            }
        }
        //    
        row = row + 2;
        tmpLabel = new Label(0, row, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(1, row, " ", b_labelFormat);
        sheet.addCell(tmpLabel);
        row++;
        tmpLabel = new Label(0, row, (String) reportHash.get("downnum"), p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(1, row, reportHash.get("count") + "", p_labelFormat);
        sheet.addCell(tmpLabel);

        // 
        addEventListToExcel(sheet, row);

        if (impReport.getChart() != null) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            try {
                ChartUtilities.writeChartAsPNG(baos, impReport.getChart().getChart(),
                        impReport.getChart().getWidth(), impReport.getChart().getHeight());
            } catch (IOException ioe) {
            }
            WritableImage wi = new WritableImage(2, 10000 + 5, 8, 12, baos.toByteArray());
            sheet.addImage(wi);
        }
        wb.write();
    } catch (Exception e) {
        SysLogger.error("", e);
    } finally {
        try {
            if (wb != null)
                wb.close();
        } catch (Exception e) {
        }
    }
}