Example usage for org.apache.poi.hssf.usermodel HSSFWorkbook createSheet

List of usage examples for org.apache.poi.hssf.usermodel HSSFWorkbook createSheet

Introduction

In this page you can find the example usage for org.apache.poi.hssf.usermodel HSSFWorkbook createSheet.

Prototype

@Override
public HSSFSheet createSheet(String sheetname) 

Source Link

Document

Create a new sheet for this Workbook and return the high level representation.

Usage

From source file:co.turnus.profiling.io.XlsHalsteadAnalysisWriter.java

License:Open Source License

private void writeActorClassesTable(HSSFWorkbook workbook, SourceCodeData report) {
    int sheetNumber = 0;
    for (ActorClassStaticData aData : report.getActorsData()) {
        HalsteadAnalyser a = new HalsteadAnalyser(aData);
        String aClass = aData.getActorClass().getName();

        HSSFSheet sheet = workbook.createSheet("Class n." + sheetNumber++);
        // Action Actor Class Results
        Cell cell = sheet.createRow(0).createCell(0);
        HSSFRichTextString title = new HSSFRichTextString("Halstead Analysis for the Actor Class: " + aClass);
        title.applyFont(titleFont);/* ww w .j ava2s.  co m*/
        cell.setCellValue(title);

        Row row = sheet.createRow(2);
        row.createCell(0).setCellValue("Summary");
        row.createCell(1).setCellValue("n1");
        row.createCell(2).setCellValue("n2");
        row.createCell(3).setCellValue("n");
        row.createCell(4).setCellValue("N1");
        row.createCell(5).setCellValue("N2");
        row.createCell(6).setCellValue("N");
        row.createCell(7).setCellValue("cN");
        row.createCell(8).setCellValue("V");
        row.createCell(9).setCellValue("D");
        row.createCell(10).setCellValue("E");
        row.createCell(11).setCellValue("T");
        row.createCell(12).setCellValue("B");
        row.createCell(13).setCellValue("I");
        row.createCell(14).setCellValue("NoL");

        row = sheet.createRow(3);
        row.createCell(1).setCellValue(a.getn1());
        row.createCell(2).setCellValue(a.getn2());
        row.createCell(3).setCellValue(a.getn());
        row.createCell(4).setCellValue(a.getN1());
        row.createCell(5).setCellValue(a.getN2());
        row.createCell(6).setCellValue(a.getN());
        row.createCell(7).setCellValue(a.getcN());
        row.createCell(8).setCellValue(a.getV());
        row.createCell(9).setCellValue(a.getD());
        row.createCell(10).setCellValue(a.getE());
        row.createCell(11).setCellValue(a.getT());
        row.createCell(12).setCellValue(a.getB());
        row.createCell(13).setCellValue(a.getI());
        row.createCell(14).setCellValue(aData.getNumberOfLines());

        int i = 5;
        row = sheet.createRow(i++);
        row.createCell(0).setCellValue("Action");
        row.createCell(1).setCellValue("n1");
        row.createCell(2).setCellValue("n2");
        row.createCell(3).setCellValue("n");
        row.createCell(4).setCellValue("N1");
        row.createCell(5).setCellValue("N2");
        row.createCell(6).setCellValue("N");
        row.createCell(7).setCellValue("cN");
        row.createCell(8).setCellValue("V");
        row.createCell(9).setCellValue("D");
        row.createCell(10).setCellValue("E");
        row.createCell(11).setCellValue("T");
        row.createCell(12).setCellValue("B");
        row.createCell(13).setCellValue("I");
        for (ActionStaticData actionData : aData.getActionsData()) {
            a = new HalsteadAnalyser(actionData);
            row = sheet.createRow(i++);
            row.createCell(0).setCellValue(actionData.getAction().getId());
            row.createCell(1).setCellValue(a.getn1());
            row.createCell(2).setCellValue(a.getn2());
            row.createCell(3).setCellValue(a.getn());
            row.createCell(4).setCellValue(a.getN1());
            row.createCell(5).setCellValue(a.getN2());
            row.createCell(6).setCellValue(a.getN());
            row.createCell(7).setCellValue(a.getcN());
            row.createCell(8).setCellValue(a.getV());
            row.createCell(9).setCellValue(a.getD());
            row.createCell(10).setCellValue(a.getE());
            row.createCell(11).setCellValue(a.getT());
            row.createCell(12).setCellValue(a.getB());
            row.createCell(13).setCellValue(a.getI());
        }

        /*
         * i++; row = sheet.createRow(i++);
         * row.createCell(0).setCellValue("Procedure");
         * row.createCell(1).setCellValue("n1");
         * row.createCell(2).setCellValue("n2");
         * row.createCell(3).setCellValue("n");
         * row.createCell(4).setCellValue("N1");
         * row.createCell(5).setCellValue("N2");
         * row.createCell(6).setCellValue("N");
         * row.createCell(7).setCellValue("cN");
         * row.createCell(8).setCellValue("V");
         * row.createCell(9).setCellValue("D");
         * row.createCell(10).setCellValue("E");
         * row.createCell(11).setCellValue("T");
         * row.createCell(12).setCellValue("B");
         * row.createCell(13).setCellValue("I");
         * 
         * for (ProcedureStaticData pData : aData.getProceduresData()) { a =
         * new HalsteadAnalyser(pData); row = sheet.createRow(i++);
         * row.createCell(0).setCellValue(pData.getProcedure().getName());
         * row.createCell(1).setCellValue(a.getn1());
         * row.createCell(2).setCellValue(a.getn2());
         * row.createCell(3).setCellValue(a.getn());
         * row.createCell(4).setCellValue(a.getN1());
         * row.createCell(5).setCellValue(a.getN2());
         * row.createCell(6).setCellValue(a.getN());
         * row.createCell(7).setCellValue(a.getcN());
         * row.createCell(8).setCellValue(a.getV());
         * row.createCell(9).setCellValue(a.getD());
         * row.createCell(10).setCellValue(a.getE());
         * row.createCell(11).setCellValue(a.getT());
         * row.createCell(12).setCellValue(a.getB());
         * row.createCell(13).setCellValue(a.getI()); }
         */
    }

}

From source file:co.turnus.profiling.io.XlsHalsteadAnalysisWriter.java

License:Open Source License

private void writeSummary(HSSFWorkbook workbook, Network network, SourceCodeData report) {
    BasicStaticData networkData = ProfilingFactory.eINSTANCE.createBasicStaticData();

    for (ActorClassStaticData aData : report.getActorsData()) {
        StaticDataUtil.merge(networkData, aData);
    }//from w  ww . j a v a2s. c o  m

    HalsteadAnalyser a = new HalsteadAnalyser(networkData);
    HSSFSheet sheet = workbook.createSheet("Halstead Summary");
    // Action Actor Class Results
    Cell cell = sheet.createRow(0).createCell(0);
    HSSFRichTextString title = new HSSFRichTextString("Halstead Analysis: Network and Actor Classes");
    title.applyFont(titleFont);
    cell.setCellValue(title);

    Row row = sheet.createRow(1);
    row.createCell(0).setCellValue("Network");
    row = sheet.createRow(2);
    row.createCell(0).setCellValue("n1");
    row.createCell(1).setCellValue("n2");
    row.createCell(2).setCellValue("n");
    row.createCell(3).setCellValue("N1");
    row.createCell(4).setCellValue("N2");
    row.createCell(5).setCellValue("N");
    row.createCell(6).setCellValue("cN");
    row.createCell(7).setCellValue("V");
    row.createCell(8).setCellValue("D");
    row.createCell(9).setCellValue("E");
    row.createCell(10).setCellValue("T");
    row.createCell(11).setCellValue("B");
    row.createCell(12).setCellValue("I");
    row.createCell(13).setCellValue("NoL");
    row = sheet.createRow(3);
    row.createCell(0).setCellValue(a.getn1());
    row.createCell(1).setCellValue(a.getn2());
    row.createCell(2).setCellValue(a.getn());
    row.createCell(3).setCellValue(a.getN1());
    row.createCell(4).setCellValue(a.getN2());
    row.createCell(5).setCellValue(a.getN());
    row.createCell(6).setCellValue(a.getcN());
    row.createCell(7).setCellValue(a.getV());
    row.createCell(8).setCellValue(a.getD());
    row.createCell(9).setCellValue(a.getE());
    row.createCell(10).setCellValue(a.getT());
    row.createCell(11).setCellValue(a.getB());
    row.createCell(12).setCellValue(a.getI());
    row.createCell(13).setCellValue(networkData.getNumberOfLines());

    row = sheet.createRow(5);
    row.createCell(0).setCellValue("Actor Class");
    row.createCell(1).setCellValue("n1");
    row.createCell(2).setCellValue("n2");
    row.createCell(3).setCellValue("n");
    row.createCell(4).setCellValue("N1");
    row.createCell(5).setCellValue("N2");
    row.createCell(6).setCellValue("N");
    row.createCell(7).setCellValue("cN");
    row.createCell(8).setCellValue("V");
    row.createCell(9).setCellValue("D");
    row.createCell(10).setCellValue("E");
    row.createCell(11).setCellValue("T");
    row.createCell(12).setCellValue("B");
    row.createCell(13).setCellValue("I");
    row.createCell(14).setCellValue("NoL");

    int i = 6;
    for (ActorClassStaticData aData : report.getActorsData()) {
        a = new HalsteadAnalyser(aData);
        row = sheet.createRow(i);
        row.createCell(0).setCellValue(aData.getActorClass().getName());
        row.createCell(1).setCellValue(a.getn1());
        row.createCell(2).setCellValue(a.getn2());
        row.createCell(3).setCellValue(a.getn());
        row.createCell(4).setCellValue(a.getN1());
        row.createCell(5).setCellValue(a.getN2());
        row.createCell(6).setCellValue(a.getN());
        row.createCell(7).setCellValue(a.getcN());
        row.createCell(8).setCellValue(a.getV());
        row.createCell(9).setCellValue(a.getD());
        row.createCell(10).setCellValue(a.getE());
        row.createCell(11).setCellValue(a.getT());
        row.createCell(12).setCellValue(a.getB());
        row.createCell(13).setCellValue(a.getI());
        row.createCell(14).setCellValue(aData.getNumberOfLines());

        i++;
    }
}

From source file:co.turnus.profiling.io.XlsProfilingDataWriter.java

License:Open Source License

private void writeFifosData(HSSFWorkbook workbook, ProfilingData data) {
    HSSFSheet sheet = workbook.createSheet("Fifos Data");
    // Action Actor Class Results
    Cell cell = sheet.createRow(0).createCell(0);
    HSSFRichTextString title = new HSSFRichTextString("Communication data summary");
    title.applyFont(titleFont);/*from ww  w.  j ava2 s .c  o m*/
    cell.setCellValue(title);

    int rowIdx = 2;
    Row row = sheet.createRow(rowIdx++);
    sheet.addMergedRegion(new CellRangeAddress(2, 2, 0, 1));
    row.createCell(0).setCellValue("Source");
    sheet.addMergedRegion(new CellRangeAddress(2, 2, 2, 3));
    row.createCell(2).setCellValue("Target");
    sheet.addMergedRegion(new CellRangeAddress(2, 2, 4, 5));
    row.createCell(4).setCellValue("Type");
    sheet.addMergedRegion(new CellRangeAddress(2, 2, 6, 12));
    row.createCell(6).setCellValue("Writing (tokens)");
    sheet.addMergedRegion(new CellRangeAddress(2, 2, 13, 20));
    row.createCell(13).setCellValue("Reading (tokens)");

    // header
    row = sheet.createRow(rowIdx++);
    row.createCell(0).setCellValue("Actor");
    row.createCell(1).setCellValue("Out Port");
    row.createCell(2).setCellValue("Actor");
    row.createCell(3).setCellValue("In Port");

    // type
    row.createCell(4).setCellValue("Name");
    row.createCell(5).setCellValue("Bit:Token");

    // writing
    row.createCell(6).setCellValue("hits");
    row.createCell(7).setCellValue("misses");
    row.createCell(8).setCellValue("total");
    row.createCell(9).setCellValue("average");
    row.createCell(10).setCellValue("min");
    row.createCell(11).setCellValue("max");
    row.createCell(12).setCellValue("variance");

    // reading
    row.createCell(13).setCellValue("peeks");
    row.createCell(14).setCellValue("hits");
    row.createCell(15).setCellValue("misses");
    row.createCell(16).setCellValue("total");
    row.createCell(17).setCellValue("average");
    row.createCell(18).setCellValue("min");
    row.createCell(19).setCellValue("max");
    row.createCell(20).setCellValue("variance");

    for (FifoProfilingData fData : data.getFifosData()) {
        row = sheet.createRow(rowIdx++);
        Fifo fifo = fData.getFifo();
        // header
        row.createCell(0).setCellValue(fifo.getSourceActor().getId());
        row.createCell(1).setCellValue(fifo.getSourcePort().getName());
        row.createCell(2).setCellValue(fifo.getTargetActor().getId());
        row.createCell(3).setCellValue(fifo.getTargetPort().getName());
        // type
        row.createCell(4).setCellValue(fifo.getType().toString());
        row.createCell(5).setCellValue(fifo.getType().getBits());
        // writes
        row.createCell(6).setCellValue(fData.getWriteHit());
        row.createCell(7).setCellValue(fData.getWriteMiss());
        row.createCell(8).setCellValue(fData.getWriteTokens().getSum());
        row.createCell(9).setCellValue(fData.getWriteTokens().getMean());
        row.createCell(10).setCellValue(fData.getWriteTokens().getMin());
        row.createCell(11).setCellValue(fData.getWriteTokens().getMax());
        row.createCell(12).setCellValue(fData.getWriteTokens().getVariance());
        // reads
        row.createCell(13).setCellValue(fData.getPeeks());
        row.createCell(14).setCellValue(fData.getReadHit());
        row.createCell(15).setCellValue(fData.getWriteMiss());
        row.createCell(16).setCellValue(fData.getReadTokens().getSum());
        row.createCell(17).setCellValue(fData.getWriteTokens().getMean());
        row.createCell(18).setCellValue(fData.getWriteTokens().getMin());
        row.createCell(19).setCellValue(fData.getWriteTokens().getMax());
        row.createCell(20).setCellValue(fData.getWriteTokens().getVariance());

    }

}

From source file:com.abacus.reports.ExcelBuilder.java

@Override
protected void buildExcelDocument(Map<String, Object> map, HSSFWorkbook workbook, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    // get data model which is passed by the Spring container
    List headerlist = (List) map.get("header");
    List<Object[]> data = (List) map.get("data");
    String reportname = String.valueOf(map.get("report_name"));

    // create a new Excel sheet
    HSSFSheet sheet = workbook.createSheet(reportname);
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-disposition", "attachment; filename=" + reportname + ".xls");
    OutputStream outStream = response.getOutputStream();
    sheet.setDefaultColumnWidth(30);/*from w  ww . j  a va2  s .c om*/

    // create style for header cells
    CellStyle style = workbook.createCellStyle();
    HSSFFont font = workbook.createFont();
    HSSFPalette palette = workbook.getCustomPalette();
    HSSFColor color = palette.findSimilarColor(152, 35, 17);
    short paindex = color.getIndex();
    font.setFontName("Trebuchet MS");
    style.setFillForegroundColor(paindex);
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    font.setColor(HSSFColor.WHITE.index);
    style.setFont(font);

    // create header row
    HSSFRow header = sheet.createRow(0);
    int row = 0;
    for (Object headerlist1 : headerlist) {

        header.createCell(row).setCellValue(String.valueOf(headerlist1));
        header.getCell(row).setCellStyle(style);
        row++;
    }

    CellStyle style2 = workbook.createCellStyle();
    HSSFFont font2 = workbook.createFont();
    font2.setFontName("Trebuchet MS");
    style2.setFont(font2);

    System.out.println("data.size(): " + data.size());
    int rownum = 1;
    // create data rows         
    for (int rowCount = 0; rowCount < data.size(); rowCount++) {
        HSSFRow aRow = sheet.createRow(rownum);
        Object[] value = data.get(rowCount);
        int col = 0;
        for (Object value1 : value) {
            HSSFCell cell = aRow.createCell(col++);
            cell.setCellStyle(style2);
            if (value1 instanceof java.lang.String)
                cell.setCellValue(String.valueOf(value1));
            if (value1 instanceof java.lang.Integer)
                cell.setCellValue(Integer.parseInt(String.valueOf(value1)));
            if (value1 instanceof java.lang.Boolean)
                cell.setCellValue(Integer.parseInt(String.valueOf(value1)));
            if (value1 instanceof java.lang.Double)
                cell.setCellValue(Double.parseDouble(String.valueOf(value1)));
            if (value1 instanceof java.lang.Float)
                cell.setCellValue(Float.parseFloat(String.valueOf(value1)));
        }
        rownum++;
    }
    workbook.write(outStream);
    outStream.close();
}

From source file:com.adonis.ui.print.PrintVehiclesUI.java

public static File createXLSVehicles(String fileName, List<Vehicle> vehicles) {
    try {/* w  ww .j  a v a2s  . c  o  m*/
        HSSFWorkbook wb = new HSSFWorkbook();
        HSSFSheet sheet = wb.createSheet("Excel Sheet");
        HSSFRow rowhead = sheet.createRow((short) 0);
        rowhead.createCell((short) 0).setCellValue("vehicleNmbr");
        rowhead.createCell((short) 1).setCellValue("licenseNmbr");
        rowhead.createCell((short) 2).setCellValue("make");
        rowhead.createCell((short) 3).setCellValue("vehicleType");
        rowhead.createCell((short) 4).setCellValue("model");
        rowhead.createCell((short) 5).setCellValue("price");
        rowhead.createCell((short) 6).setCellValue("location");

        vehicles.forEach(rent -> {
            HSSFRow row = sheet.createRow((short) index);
            row.createCell((short) 0).setCellValue(rent.getVehicleNmbr());
            row.createCell((short) 1).setCellValue(rent.getLicenseNmbr());
            row.createCell((short) 2).setCellValue(rent.getMake());
            row.createCell((short) 3).setCellValue(rent.getVehicleType());
            row.createCell((short) 4).setCellValue(rent.getModel());
            row.createCell((short) 5).setCellValue(rent.getPrice());
            row.createCell((short) 6).setCellValue(rent.getLocation());
            index++;
        });
        FileOutputStream fileOut = new FileOutputStream(fileName);
        wb.write(fileOut);
        fileOut.close();
        System.out.println("Data is saved in excel file.");

    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return new File(fileName);
}

From source file:com.ah.ui.actions.admin.LicenseMgrAction.java

License:Open Source License

private void exportEntitleKeyInfo() {
    try {/*from  w ww  . j  a va  2 s  . c o  m*/
        // create a new file
        FileOutputStream out = new FileOutputStream(ORDERKEYINFO_EXPORT_FILE_PATH);
        // create a new workbook
        HSSFWorkbook wb = new HSSFWorkbook();
        // create a new sheet
        HSSFSheet s = wb.createSheet("Sheet1");
        // declare a row object reference
        HSSFRow r = null;
        // declare a cell object reference
        HSSFCell c = null;
        // row index
        int rowNum = 0;
        // cell count
        int cellcount = 0;
        if (NmsUtil.isHMForOEM()) {
            cellcount = 7;
        } else if (getIsInHomeDomain()) {
            cellcount = 8;
        } else if (NmsUtil.isHostedHMApplication()) {
            cellcount = 9;
        }
        if (cellcount == 0) {
            return;
        } else {
            for (int i = 0; i < cellcount; i++) {
                s.setColumnWidth(i, getColumnWidthByIndex(i) * 256);
            }
        }
        // create cell style
        HSSFCellStyle cs = wb.createCellStyle();
        // create font object
        HSSFFont f = wb.createFont();

        //set font to 12 point type
        f.setFontHeightInPoints((short) 12);
        f.setFontName("Calibri");

        //set cell stlye
        cs.setFont(f);
        cs.setAlignment(CellStyle.ALIGN_CENTER);
        cs.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM);

        // create cell style
        HSSFCellStyle cs1 = wb.createCellStyle();
        // create font object
        HSSFFont f1 = wb.createFont();

        //set font to 12 point type
        f1.setFontHeightInPoints((short) 12);
        f1.setFontName("Calibri");
        f1.setBoldweight(Font.BOLDWEIGHT_BOLD);

        //set cell stlye
        cs1.setFont(f1);
        cs1.setAlignment(CellStyle.ALIGN_RIGHT);
        cs1.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM);

        // create cell style
        HSSFCellStyle cs2 = wb.createCellStyle();
        cs2.setFont(f1);
        cs2.setAlignment(CellStyle.ALIGN_CENTER);
        cs2.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM);

        // create cell style
        HSSFCellStyle cs3 = wb.createCellStyle();
        cs3.setFont(f);
        cs3.setAlignment(CellStyle.ALIGN_RIGHT);
        cs3.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM);

        // create cell style
        HSSFCellStyle cs4 = wb.createCellStyle();
        cs4.setFont(f1);
        cs4.setAlignment(CellStyle.ALIGN_LEFT);
        cs4.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM);

        // create cell style
        HSSFCellStyle cs5 = wb.createCellStyle();
        // create font object
        HSSFFont f2 = wb.createFont();

        //set font to 12 point type
        f2.setFontHeightInPoints((short) 12);
        f2.setFontName("Calibri");
        f2.setBoldweight(Font.BOLDWEIGHT_BOLD);
        f2.setColor(Font.COLOR_RED);
        cs5.setFont(f2);
        cs5.setAlignment(CellStyle.ALIGN_LEFT);
        cs5.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM);

        // create cell style
        HSSFCellStyle cs6 = wb.createCellStyle();
        cs6.setFont(f);
        cs6.setAlignment(CellStyle.ALIGN_LEFT);
        cs6.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM);

        // create a row
        // row 1
        s.addMergedRegion(new CellRangeAddress(0, 0, 0, cellcount - 1));
        r = s.createRow(rowNum++);
        c = r.createCell(0);
        c.setCellValue(MgrUtil.getUserMessage("admin.license.orderkey.export.title"));
        c.setCellStyle(cs);

        // row 2
        String sysInfo = "";
        if (getIsInHomeDomain()) {
            sysInfo = "System ID: " + getSystemId();
            // HiveManager Online user
        } else if (NmsUtil.isHostedHMApplication()) {
            sysInfo = "VHM ID: " + getDomain().getVhmID();
        }
        s.addMergedRegion(new CellRangeAddress(1, 1, 0, cellcount - 1));
        r = s.createRow(rowNum++);
        c = r.createCell(0);
        c.setCellValue(sysInfo);
        c.setCellStyle(cs);

        // row 3
        s.addMergedRegion(new CellRangeAddress(2, 2, 0, cellcount - 1));
        r = s.createRow(rowNum++);
        c = r.createCell(0);
        List<?> userInfo = QueryUtil.executeQuery(
                "SELECT email, company FROM " + UserRegInfoForLs.class.getSimpleName(), null,
                new FilterParams("owner.domainName", getDomain().getDomainName()));
        if (!userInfo.isEmpty()) {
            Object[] userInfos = (Object[]) userInfo.get(0);
            c.setCellValue(MgrUtil.getUserMessage("admin.license.orderkey.export.email.company",
                    new String[] { (String) userInfos[0], (String) userInfos[1] }));
        }
        c.setCellStyle(cs);

        // row 4
        r = s.createRow(rowNum++);

        // row 5
        r = s.createRow(rowNum++);

        // row 6 cell 1
        c = r.createCell(0);
        c.setCellValue(MgrUtil.getUserMessage("admin.license.orderkey.export.device.licensed"));
        c.setCellStyle(cs1);

        // row 6 cell 2
        c = r.createCell(1);
        c.setCellValue(licenseInfo.getHiveAps());
        c.setCellStyle(cs2);

        // device management info
        Map<String, Integer> apcount = HiveAPInfoFromeDatabase
                .getManagedDeviceTypeAndNumber(getDomain().getDomainName());
        int vpnCount = 0;
        int totalCount = 0;
        if (null != apcount) {
            Object[] typeNames = apcount.keySet().toArray();
            Arrays.sort(typeNames);
            for (Object typeName : typeNames) {

                // VPN Gateway VA does not belong to device
                if (MgrUtil.getEnumString("enum.hiveAp.model.10").equals(typeName)) {
                    vpnCount = apcount.get(typeName);
                } else {
                    r = s.createRow(rowNum++);
                    c = r.createCell(0);
                    c.setCellValue((String) typeName);
                    c.setCellStyle(cs3);

                    c = r.createCell(1);
                    c.setCellValue(apcount.get(typeName));
                    c.setCellStyle(cs);
                    totalCount += apcount.get(typeName);
                }
            }

        }

        // managed device total number cell1
        r = s.createRow(rowNum++);
        c = r.createCell(0);
        c.setCellValue(MgrUtil.getUserMessage("admin.license.orderkey.export.device.total"));
        c.setCellStyle(cs1);

        // managed device total number cell2
        c = r.createCell(1);
        c.setCellValue(totalCount);
        c.setCellStyle(cs2);

        // blank row
        r = s.createRow(rowNum++);

        // licensed VPN Gateway VA cell1
        r = s.createRow(rowNum++);
        c = r.createCell(0);
        c.setCellValue(MgrUtil.getUserMessage("admin.license.orderkey.export.cvg.licensed"));
        c.setCellStyle(cs1);

        // licensed VPN Gateway VA cell2
        c = r.createCell(1);
        c.setCellValue(licenseInfo.getCvgNumber());
        c.setCellStyle(cs2);

        // managed VPN Gateway VA cell1
        r = s.createRow(rowNum++);
        c = r.createCell(0);
        c.setCellValue(MgrUtil.getUserMessage("admin.license.orderkey.export.cvg.total"));
        c.setCellStyle(cs1);

        // managed VPN Gateway VA cell 2
        c = r.createCell(1);
        c.setCellValue(vpnCount);
        c.setCellStyle(cs2);

        // entitlement key information
        preparePage();
        if (null != page && !page.isEmpty()) {
            r = s.createRow(rowNum++);
            List<OrderHistoryInfo> normalKey = new ArrayList<>();
            List<OrderHistoryInfo> invalidKey = new ArrayList<>();
            List<OrderHistoryInfo> expiredKey = new ArrayList<>();

            for (Object obj : page) {
                OrderHistoryInfo orderInfo = (OrderHistoryInfo) obj;
                if (orderInfo.getStatusFlag() == OrderHistoryInfo.ENTITLE_KEY_STATUS_NORMAL
                        && orderInfo.getCvgStatusFlag() == OrderHistoryInfo.ENTITLE_KEY_STATUS_NORMAL) {
                    normalKey.add(orderInfo);
                } else if (orderInfo.getStatusFlag() == OrderHistoryInfo.ENTITLE_KEY_STATUS_DISABLE
                        || orderInfo.getCvgStatusFlag() == OrderHistoryInfo.ENTITLE_KEY_STATUS_DISABLE) {
                    invalidKey.add(orderInfo);
                } else {
                    expiredKey.add(orderInfo);
                }
            }

            if (!normalKey.isEmpty()) {

                // normal entitle key title
                r = s.createRow(rowNum++);
                setEntitlementKeyCellValue(cellcount, cs4, null, r, null, MgrUtil.getUserMessage("order.key"));

                // normal entitle key info
                for (OrderHistoryInfo keyInfo : normalKey) {
                    r = s.createRow(rowNum++);
                    setEntitlementKeyCellValue(cellcount, cs6, cs3, r, keyInfo, null);
                }
            }

            if (!invalidKey.isEmpty()) {

                if (!normalKey.isEmpty()) {
                    r = s.createRow(rowNum++);
                    r = s.createRow(rowNum++);
                }

                // invalid entitle key title
                r = s.createRow(rowNum++);
                setEntitlementKeyCellValue(cellcount, cs5, null, r, null,
                        MgrUtil.getUserMessage("admin.license.orderkey.export.invalidkey.title"));

                // invalid entitle key info
                for (OrderHistoryInfo keyInfo : invalidKey) {
                    r = s.createRow(rowNum++);
                    setEntitlementKeyCellValue(cellcount, cs6, cs3, r, keyInfo, null);
                }
            }

            if (!expiredKey.isEmpty()) {

                if (!normalKey.isEmpty() || !invalidKey.isEmpty()) {
                    r = s.createRow(rowNum++);
                    r = s.createRow(rowNum++);
                }

                // expired entitle key title
                r = s.createRow(rowNum++);
                setEntitlementKeyCellValue(cellcount, cs5, null, r, null,
                        MgrUtil.getUserMessage("admin.license.orderkey.export.expiredkey.title"));

                // expired entitle key info
                for (OrderHistoryInfo keyInfo : expiredKey) {
                    r = s.createRow(rowNum++);
                    setEntitlementKeyCellValue(cellcount, cs6, cs3, r, keyInfo, null);
                }
            }
        }

        // write the workbook to the output stream
        // close our file (don't blow out our file handles)
        wb.write(out);
        out.close();
        generateAuditLog(HmAuditLog.STATUS_SUCCESS,
                MgrUtil.getUserMessage("hm.audit.log.export.entitlement.key"));
    } catch (Exception ex) {
        generateAuditLog(HmAuditLog.STATUS_FAILURE,
                MgrUtil.getUserMessage("hm.audit.log.export.entitlement.key"));
        log.error("exportEntitleKeyInfo()", ex.getMessage());
    }
}

From source file:com.aimluck.eip.modules.screens.ALXlsScreen.java

License:Open Source License

/**
 * // ww w .  j av a 2  s  .  c om
 * @param wb
 * @param sheet_name
 * @param headers
 *          ?
 * @param cell_enc_types
 *          ?
 * @return
 */
protected HSSFSheet createHSSFSheet(HSSFWorkbook wb, String sheet_name, String[] headers,
        short[] cell_enc_types) {

    HSSFSheet sheet = wb.createSheet(sheet_name);
    wb.setSheetName(0, sheet_name, HSSFWorkbook.ENCODING_UTF_16);

    HSSFRow row1 = sheet.createRow(0);
    int len = headers.length;
    for (int i = 0; i < len; i++) {
        HSSFCell cell_row1 = row1.createCell((short) i);
        cell_row1.setEncoding(HSSFCell.ENCODING_UTF_16);
        cell_row1.setCellValue(headers[i]);
    }

    return sheet;
}

From source file:com.anphat.list.controller.ListStaffController.java

public File exportFile(List<StaffDTO> lstStaffInfo) {
    try {/* w w w  .  j a  v  a2  s.  c  o m*/
        FileOutputStream fileOut = new FileOutputStream(PATH_EXPORT + Constants.FILE_NAME.LIST_STAFF);
        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet worksheet = workbook.createSheet("danhsachnhanvien");
        HSSFCellStyle cellStyle;
        HSSFCellStyle rowStyle;

        HSSFCellStyle cellStyleLeft = null;
        HSSFCellStyle cellStyleRight = null;
        //style left
        cellStyleLeft = workbook.createCellStyle();
        cellStyleLeft.setAlignment(HSSFCellStyle.ALIGN_LEFT);
        //phai
        cellStyleRight = workbook.createCellStyle();
        cellStyleRight.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
        cellStyleRight.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        cellStyleRight.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        cellStyleRight.setBorderRight(HSSFCellStyle.BORDER_THIN);
        cellStyleRight.setBorderTop(HSSFCellStyle.BORDER_THIN);

        //                //header bang
        HSSFRow row5 = worksheet.createRow(0);

        HSSFCell cellA1 = row5.createCell(0);
        cellA1.setCellValue(BundleUtils.getString("STT"));
        cellStyle = workbook.createCellStyle();
        cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
        cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
        cellStyle.setFillForegroundColor(HSSFColor.LIGHT_CORNFLOWER_BLUE.index);
        cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        cellStyle.setWrapText(true);
        //rowstyle
        rowStyle = workbook.createCellStyle();
        rowStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        rowStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        rowStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        rowStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        rowStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
        rowStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
        rowStyle.setFillForegroundColor(HSSFColor.WHITE.index);
        rowStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        rowStyle.setWrapText(true);

        cellA1.setCellStyle(cellStyle);

        HSSFCell cellB1 = row5.createCell(1);
        cellB1.setCellValue(BundleUtils.getString("cms.StaffInfo.code"));
        cellB1.setCellStyle(cellStyle);

        HSSFCell cellC1 = row5.createCell(2);
        cellC1.setCellValue(BundleUtils.getString("cms.StaffInfo.name"));
        cellC1.setCellStyle(cellStyle);
        HSSFCell cellD1 = row5.createCell(3);
        cellD1.setCellValue(BundleUtils.getString("cms.StaffInfo.email"));
        cellD1.setCellStyle(cellStyle);
        HSSFCell cellE1 = row5.createCell(4);
        cellE1.setCellValue(BundleUtils.getString("cms.StaffInfo.birthdate"));
        cellE1.setCellStyle(cellStyle);
        HSSFCell cellF1 = row5.createCell(5);
        cellF1.setCellValue(BundleUtils.getString("cms.StaffInfo.phoneNumber"));
        cellF1.setCellStyle(cellStyle);
        HSSFCell cellG1 = row5.createCell(6);
        cellG1.setCellValue(BundleUtils.getString("cms.StaffInfo.deptName"));
        cellG1.setCellStyle(cellStyle);
        HSSFCell cellH1 = row5.createCell(7);
        cellH1.setCellValue(BundleUtils.getString("cms.StaffInfo.staffType"));
        cellH1.setCellStyle(cellStyle);
        HSSFCell cellI1 = row5.createCell(8);
        cellI1.setCellValue(BundleUtils.getString("cms.StaffInfo.status"));
        cellI1.setCellStyle(cellStyle);
        //content bang
        if (!lstStaffInfo.isEmpty()) {
            int j = 0;
            for (StaffDTO staff : lstStaffInfo) {
                HSSFRow row = worksheet.createRow(j + 1);

                HSSFCell cellA = row.createCell(0);
                cellA.setCellValue(j + 1);
                cellA.setCellStyle(rowStyle);
                HSSFCell cellB = row.createCell(1);
                cellB.setCellValue((staff.getDeptId() == null) ? Constants.NULL : staff.getCode());
                cellB.setCellStyle(cellStyleLeft);
                HSSFCell cellC = row.createCell(2);
                cellC.setCellValue((staff.getCode() == null) ? Constants.NULL : staff.getName());
                cellC.setCellStyle(cellStyleLeft);
                HSSFCell cellD = row.createCell(3);
                cellD.setCellValue((staff.getName() == null) ? Constants.NULL : staff.getEmail());
                cellD.setCellStyle(cellStyleLeft);
                HSSFCell cellE = row.createCell(4);
                //                    cellE.setCellValue((staff.getEmail() == null) ? Constants.NULL : staff.getBirthDate());
                cellE.setCellStyle(cellStyleLeft);
                HSSFCell cellF = row.createCell(5);
                cellF.setCellValue((staff.getTelNumber() == null) ? Constants.NULL : staff.getTelNumber());
                cellF.setCellStyle(cellStyleLeft);
                HSSFCell cellG = row.createCell(6);
                //                    cellG.setCellValue((staff.getDeptName() == null) ? Constants.NULL : staff.getDeptName());
                cellG.setCellStyle(cellStyleLeft);
                HSSFCell cellH = row.createCell(7);
                cellH.setCellValue((staff.getStaffType() == null) ? Constants.NULL
                        : BundleUtils.getString(
                                "staff.type." + DataUtil.getStringEscapeHTML4(staff.getStaffType())));
                cellH.setCellStyle(cellStyleLeft);
                HSSFCell cellI = row.createCell(8);
                cellI.setCellValue((staff.getStatus() == null) ? Constants.NULL
                        : BundleUtils.getString(
                                "common.status." + DataUtil.getStringEscapeHTML4(staff.getStatus())));
                cellI.setCellStyle(cellStyleLeft);
                j++;
            }
            //Set Width
            for (int i = 0; i <= 0; i++) {
                worksheet.setColumnWidth(i, 2000);
            }
            for (int i = 1; i <= 7; i++) {
                worksheet.setColumnWidth(i, 5000);
            }
            for (int i = 8; i <= 10; i++) {
                worksheet.setColumnWidth(i, 3000);
            }
        }
        try {
            workbook.write(fileOut);
            fileOut.flush();
            fileOut.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    File file = new File(PATH_EXPORT + Constants.FILE_NAME.LIST_STAFF);
    return file;

}

From source file:com.app.ExcelView.java

License:Open Source License

/**
 * ?Excel//from   www .j a  v a 2  s. com
 * 
 * @param model
 *            ?
 * @param workbook
 *            workbook
 * @param request
 *            request
 * @param response
 *            response
 */
public void buildExcelDocument(Map<String, Object> model, HSSFWorkbook workbook, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    Assert.notEmpty(properties);
    HSSFSheet sheet;
    if (StringUtils.isNotEmpty(sheetName)) {
        sheet = workbook.createSheet(sheetName);
    } else {
        sheet = workbook.createSheet();
    }
    int rowNumber = 0;
    if (titles != null && titles.length > 0) {
        HSSFRow header = sheet.createRow(rowNumber);
        header.setHeight((short) 400);
        for (int i = 0; i < properties.length; i++) {
            HSSFCell cell = header.createCell(i);
            HSSFCellStyle cellStyle = workbook.createCellStyle();
            cellStyle.setFillForegroundColor(HSSFColor.LIGHT_CORNFLOWER_BLUE.index);
            cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
            cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
            cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
            HSSFFont font = workbook.createFont();
            font.setFontHeightInPoints((short) 11);
            font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
            cellStyle.setFont(font);
            cell.setCellStyle(cellStyle);
            if (i == 0) {
                HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
                HSSFComment comment = patriarch
                        .createComment(new HSSFClientAnchor(0, 0, 0, 0, (short) 1, 1, (short) 4, 4));
                comment.setString(new HSSFRichTextString("P" + "o" + "w" + "e" + "r" + "e" + "d" + " " + "B"
                        + "y" + " " + "A" + "P" + "P" + "T" + "E" + "A" + "M"));
                cell.setCellComment(comment);
            }
            if (titles.length > i && titles[i] != null) {
                cell.setCellValue(titles[i]);
            } else {
                cell.setCellValue(properties[i]);
            }
            if (widths != null && widths.length > i && widths[i] != null) {
                sheet.setColumnWidth(i, widths[i]);
            } else {
                sheet.autoSizeColumn(i);
            }
        }
        rowNumber++;
    }
    if (data != null) {
        for (Object item : data) {
            HSSFRow row = sheet.createRow(rowNumber);
            for (int i = 0; i < properties.length; i++) {
                HSSFCell cell = row.createCell(i);
                if (converters != null && converters.length > i && converters[i] != null) {
                    Class<?> clazz = PropertyUtils.getPropertyType(item, properties[i]);
                    ConvertUtils.register(converters[i], clazz);
                    cell.setCellValue(BeanUtils.getProperty(item, properties[i]));
                    ConvertUtils.deregister(clazz);
                    if (clazz.equals(Date.class)) {
                        DateConverter dateConverter = new DateConverter();
                        dateConverter.setPattern(DEFAULT_DATE_PATTERN);
                        ConvertUtils.register(dateConverter, Date.class);
                    }
                } else {
                    cell.setCellValue(BeanUtils.getProperty(item, properties[i]));
                }
                if (rowNumber == 0 || rowNumber == 1) {
                    if (widths != null && widths.length > i && widths[i] != null) {
                        sheet.setColumnWidth(i, widths[i]);
                    } else {
                        sheet.autoSizeColumn(i);
                    }
                }
            }
            rowNumber++;
        }
    }
    if (contents != null && contents.length > 0) {
        rowNumber++;
        for (String content : contents) {
            HSSFRow row = sheet.createRow(rowNumber);
            HSSFCell cell = row.createCell(0);
            HSSFCellStyle cellStyle = workbook.createCellStyle();
            HSSFFont font = workbook.createFont();
            font.setColor(HSSFColor.GREY_50_PERCENT.index);
            cellStyle.setFont(font);
            cell.setCellStyle(cellStyle);
            cell.setCellValue(content);
            rowNumber++;
        }
    }
    response.setContentType("application/force-download");
    if (StringUtils.isNotEmpty(filename)) {
        response.setHeader("Content-disposition",
                "attachment; filename=" + URLEncoder.encode(filename, "UTF-8"));
    } else {
        response.setHeader("Content-disposition", "attachment");
    }
}

From source file:com.assentisk.util.FilesService.java

public void generatePositionProfileXls(HttpServletRequest req, String Doc_name, List catList)
        throws SQLException, IOException {
    Integer key = 1;//from   ww  w .  j  a  v a  2s  .co m

    try {
        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = workbook.createSheet(Doc_name);
        Map<String, Object[]> data = new LinkedHashMap<String, Object[]>();
        data.put(key.toString(), new Object[] { "Control ID", "Risk", "Control Objective",
                "Control Description", "Test Steps", "Busines Process Name", "Control Category Name" });

        if (catList != null) {

            for (int i = 0; i < catList.size(); i++) {
                Map map = (Map) catList.get(i);

                short colIndex = 0;
                data.put((++key).toString(),
                        new Object[] { map.get("Control_ID"), map.get("Risk"), map.get("Control_Objective"),
                                map.get("Control_Description"), map.get("Test_Steps"),
                                map.get("businessProcess"), map.get("controlcategory") });
                Set<String> keyset = data.keySet();
                int rownum = 0;

                sheet.setColumnHidden((short) 14, true);

                for (String key2 : keyset) {
                    HSSFRow row = sheet.createRow(rownum++);
                    Object[] objArr = data.get(key2);
                    short cellnum = 0;
                    for (Object obj : objArr) {

                        if (obj instanceof String) {
                            row.createCell(cellnum++).setCellValue((String) obj);

                        } else if (obj instanceof Integer)
                            row.createCell(cellnum++).setCellValue((Integer) obj);
                        else if (obj instanceof String) {
                            row.createCell(cellnum++).setCellValue((String) obj);

                        } else if (obj instanceof String)
                            row.createCell(cellnum++).setCellValue((String) obj);
                        else if (obj instanceof String)
                            row.createCell(cellnum++).setCellValue((String) obj);
                        else if (obj instanceof String)
                            row.createCell(cellnum++).setCellValue((Integer) obj);
                        else if (obj instanceof Integer)
                            row.createCell(cellnum++).setCellValue((String) obj);
                        else if (obj instanceof String)
                            row.createCell(cellnum++).setCellValue((String) obj);
                        else if (obj instanceof String)
                            row.createCell(cellnum++).setCellValue((String) obj);
                        else if (obj instanceof String)
                            row.createCell(cellnum++).setCellValue((String) obj);
                        else if (obj instanceof String)
                            row.createCell(cellnum++).setCellValue((String) obj);
                        else if (obj instanceof String)
                            row.createCell(cellnum++).setCellValue((String) obj);
                        else if (obj instanceof String)
                            row.createCell(cellnum++).setCellValue((String) obj);
                        else if (obj instanceof String)
                            row.createCell(cellnum++).setCellValue((String) obj);
                        else if (obj instanceof String)
                            row.createCell(cellnum++).setCellValue((String) obj);
                    }

                }

            }
        }
        FileOutputStream out = new FileOutputStream(new File("" + Doc_name + ".xls"));
        workbook.write(out);
        out.close();
        System.out.println("Excel written successfully..");
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}