Example usage for org.apache.poi.hssf.usermodel HSSFSheet createRow

List of usage examples for org.apache.poi.hssf.usermodel HSSFSheet createRow

Introduction

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

Prototype

@Override
public HSSFRow createRow(int rownum) 

Source Link

Document

Create a new row within the sheet and return the high level representation

Usage

From source file:com.byd.test.actions.OrderAction.java

@RequestMapping("xopera")
public ModelAndView xopera(HttpServletRequest request, HttpServletResponse response) {
    try {/*from  w w  w . ja v a  2s .c  o  m*/
        OutputStream out = response.getOutputStream();
        response.reset();
        response.setHeader("content-disposition", "attachment;filename=" + "fileName.xls");
        response.setContentType("application/x-octetstream;charset=gb2312");
        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = null;
        String sheetName = "first sheet";
        sheet = workbook.createSheet(sheetName);
        System.out.println("*-*-----------------------");
        HSSFCell cell = sheet.createRow(1).createCell((short) 2);
        cell.setCellValue(323);
        workbook.write(out);
        out.flush();
        out.close();

    } catch (IOException ex) {
        Logger.getLogger(OrderAction.class.getName()).log(Level.SEVERE, null, ex);
    }

    String s = (String) request.getParameter("plantCode");//String a = request.getQueryString("");
    System.out.println("plantCode:  " + s);
    return new ModelAndView("myname");
}

From source file:com.carfinance.module.common.controller.DocumentDownloadController.java

/**
 * ????Excel/*from w w w  . jav  a2s  .  c o m*/
 * @param model
 * @param request
 * @param response
 */
@RequestMapping(value = "/cashierstatement", method = RequestMethod.GET)
public void cashierStatement(Model model, HttpServletRequest request, HttpServletResponse response) {
    String contrace_id_str = request.getParameter("contrace_id");

    String contrace_no = "";
    String customer_name = "";
    String customer_no = "";
    String daily_available_km = "";
    String contrace_type = "";

    VehicleContraceInfo vehicleContraceInfo = this.vehicleServiceManageService
            .getVehicleContraceInfoById(Long.valueOf(contrace_id_str));
    if (vehicleContraceInfo != null) {
        contrace_no = vehicleContraceInfo.getContrace_no();
        customer_name = vehicleContraceInfo.getCustomer_name();
        daily_available_km = vehicleContraceInfo.getDaily_available_km() + "";
    } else {
        PropertyContraceInfo propertyContraceInfo = this.vehicleServiceManageService
                .getPropertyContraceInfoById(Long.valueOf(contrace_id_str));
        if (propertyContraceInfo != null) {
            contrace_no = propertyContraceInfo.getContrace_no();
            customer_name = propertyContraceInfo.getCustomer_name();
            contrace_type = "?";
        }
    }

    List<VehicleContraceVehsInfo> vehicleContraceVehsInfoList = this.vehicleServiceManageService
            .getVehicleContraceVehsListByContraceId(Long.valueOf(contrace_id_str));

    //1.ContentType
    response.setContentType("multipart/form-data");
    //2.????(??a.pdf)
    response.setHeader("Content-Disposition", "attachment;fileName=" + contrace_no + ".xls");

    // webbookExcel
    HSSFWorkbook wb = new HSSFWorkbook();

    for (VehicleContraceVehsInfo v : vehicleContraceVehsInfoList) {
        // webbooksheet,Excelsheet
        HSSFSheet sheet = wb.createSheet(v.getLicense_plate());
        // sheet0,??poiExcel?short
        HSSFRow row = sheet.createRow((int) 0);
        // ? 
        HSSFCellStyle style = wb.createCellStyle();
        style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // ?

        HSSFCell cell = row.createCell((short) 0);
        cell.setCellValue("??");
        cell.setCellStyle(style);
        cell = row.createCell((short) 1);
        cell.setCellValue("?");
        cell.setCellStyle(style);
        cell = row.createCell((short) 2);
        cell.setCellValue("");
        cell.setCellStyle(style);
        cell = row.createCell((short) 3);
        cell.setCellValue("?");
        cell.setCellStyle(style);
        cell = row.createCell((short) 4);
        cell.setCellValue("");
        cell.setCellStyle(style);

        row = sheet.createRow(1);
        row.createCell((short) 0).setCellValue(customer_name);
        row.createCell((short) 1).setCellValue(customer_no);
        row.createCell((short) 2).setCellValue(contrace_type);
        row.createCell((short) 3).setCellValue("");
        row.createCell((short) 4).setCellValue("");

        row = sheet.createRow(2);
        HSSFCell cell2 = row.createCell((short) 0);
        cell2.setCellValue("?");
        cell2.setCellStyle(style);
        cell2 = row.createCell((short) 1);
        cell2.setCellValue("??");
        cell2.setCellStyle(style);
        cell2 = row.createCell((short) 2);
        cell2.setCellValue("");
        cell2.setCellStyle(style);
        cell2 = row.createCell((short) 3);
        cell2.setCellValue("");
        cell2.setCellStyle(style);
        cell2 = row.createCell((short) 4);
        cell2.setCellValue("??");
        cell2.setCellStyle(style);

        row = sheet.createRow(3);
        row.createCell((short) 0).setCellValue(v.getKm());
        row.createCell((short) 1).setCellValue(v.getOil_percent());
        long over_km = (v.getReturn_km() - v.getKm()) > 0 ? (v.getReturn_km() - v.getKm()) : 0;
        row.createCell((short) 2).setCellValue(over_km);
        row.createCell((short) 3).setCellValue("");
        row.createCell((short) 4).setCellValue("");

        row = sheet.createRow(4);
        HSSFCell cell4 = row.createCell((short) 0);
        cell4.setCellValue("");
        cell4.setCellStyle(style);
        cell4 = row.createCell((short) 1);
        cell4.setCellValue("?");
        cell4.setCellStyle(style);
        cell4 = row.createCell((short) 2);
        cell4.setCellValue("");
        cell4.setCellStyle(style);
        cell4 = row.createCell((short) 3);
        cell4.setCellValue("");
        cell4.setCellStyle(style);
        cell4 = row.createCell((short) 4);
        cell4.setCellValue("");
        cell4.setCellStyle(style);

        row = sheet.createRow(5);
        row.createCell((short) 0).setCellValue(v.getReturn_km());
        row.createCell((short) 1).setCellValue(v.getRevert_oil_percent());
        long over_oil = (v.getOil_percent() - v.getRevert_oil_percent()) > 0
                ? (v.getOil_percent() - v.getRevert_oil_percent())
                : 0;
        row.createCell((short) 2).setCellValue(over_oil);
        row.createCell((short) 3).setCellValue("");
        row.createCell((short) 4).setCellValue(v.getActually_price());
    }

    // ?
    try {

        String path = appProps.get("contrace.over.download.path") + contrace_no + ".xls";
        FileOutputStream fout = new FileOutputStream(path);
        wb.write(fout);
        fout.close();

        ServletOutputStream out;
        //File(?download.pdf)
        File file = new File(path);

        try {
            FileInputStream inputStream = new FileInputStream(file);
            //3.response?ServletOutputStream(out)
            out = response.getOutputStream();
            int b = 0;
            byte[] buffer = new byte[512];
            while (b != -1) {
                b = inputStream.read(buffer);
                //4.?(out)
                out.write(buffer, 0, b);
            }
            inputStream.close();
            out.close();
            out.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.cimmyt.reports.impl.ServiceReportKBioImpl.java

License:Apache License

/**
 * Method that load the sample detail into the HSSFWorkbook
 *//*from   ww  w  .j  a  v a2s  . c  o m*/
private void loadExcelList() {
    String rutaResumen = property.getKey(REPORT_PATH_KBIO, Bundle.conf);
    InputStream inputStream = getClass().getResourceAsStream(rutaResumen);
    try {
        listBook = new HSSFWorkbook(inputStream);
        HSSFSheet sheetDetails = listBook.getSheetAt(0);
        loadDetailSheet(sheetDetails);
        HSSFSheet sheetList = listBook.getSheetAt(1);
        HSSFSheet actsheetUsefull = listBook.getSheetAt(2);
        int inidatsheetList = 2;
        int inidatsheetUsefull = 1;
        String wellkbio;
        String platenameact = "";
        Integer platevoy = 0;
        Integer rowusefull = 0;
        int mod = setShipmentDetail.iterator().next().getStSampleDetail().getLabstudyid().getPlatesize();
        int plates = setShipmentDetail.size() / mod;
        //Crear hojas usefull que necesitare dependiendo del numero de platos
        for (int j = 1; j < plates; j++) {
            listBook.cloneSheet(2);
        }
        int i = 0;
        for (ShipmentDetail shipmentDetail : setShipmentDetail) {
            SampleDetail sampledet = shipmentDetail.getStSampleDetail();
            HSSFRow actrowsheetList;
            //****************    sheetList  **************************
            //
            if (sheetList.getRow(i + inidatsheetList) == null)
                sheetList.createRow(i + inidatsheetList);
            actrowsheetList = sheetList.getRow(i + inidatsheetList);
            if (actrowsheetList.getCell(0) == null)
                actrowsheetList.createCell(0);
            if (sampledet.getSamplegid() != null)
                actrowsheetList.getCell(0).setCellValue(
                        sampledet.getLabstudyid().getPrefix() + (sampledet.getLabstudyid().isUsePadded()
                                ? StrUtils.getPaddingCeros(sampledet.getSamplegid())
                                : String.valueOf(sampledet.getSamplegid())));
            if (actrowsheetList.getCell(1) == null)
                actrowsheetList.createCell(1);
            actrowsheetList.getCell(1).setCellValue(sampledet.getPlatename());
            if (actrowsheetList.getCell(2) == null)
                actrowsheetList.createCell(2);
            wellkbio = sampledet.getPlateloc();
            if (wellkbio.length() == 2)
                wellkbio = wellkbio.substring(0, 1) + "0" + wellkbio.substring(1);
            actrowsheetList.getCell(2).setCellValue(wellkbio);
            if (actrowsheetList.getCell(3) == null)
                actrowsheetList.createCell(3);
            actrowsheetList.getCell(3).setCellValue("");
            //Por especificaciones de KBIo se pone C si es un control y nada si es ADN normal
            if (sampledet.getControltype() != null)
                if (sampledet.getControltype().equals("K") || sampledet.getControltype().equals("B"))
                    actrowsheetList.getCell(3).setCellValue("C");

            if (sampledet.getSamplegid() == null)
                actrowsheetList.getCell(3).setCellValue("C");

            if (actrowsheetList.getCell(4) == null)
                actrowsheetList.createCell(4);
            actrowsheetList.getCell(4).setCellValue(sampledet.getLabstudyid().getPlatesize());

            // ********************   sheetUsefull  ***********************

            if (!platenameact.equals(sampledet.getPlatename())) {
                platenameact = sampledet.getPlatename();
                platevoy = platevoy + 1;
                actsheetUsefull = listBook.getSheetAt(platevoy + 1);
                rowusefull = inidatsheetUsefull;
            }
            HSSFRow actrowsheetUsefull;
            if (actsheetUsefull.getRow(rowusefull) == null)
                actsheetUsefull.createRow(rowusefull);
            actrowsheetUsefull = actsheetUsefull.getRow(rowusefull);

            if (actrowsheetUsefull.getCell(1) == null)
                actrowsheetUsefull.createCell(1);
            actrowsheetUsefull.getCell(1).setCellValue(wellkbio);

            if (actrowsheetUsefull.getCell(2) == null)
                actrowsheetUsefull.createCell(2);
            actrowsheetUsefull.getCell(2).setCellValue(i + 1);
            rowusefull = rowusefull + 1;
            i = i + 1;
        }
    } catch (IOException e) {
        logger.error(e.getMessage());
    }
}

From source file:com.cimmyt.reports.impl.ServiceReportKBioImpl.java

License:Apache License

private void loadListGrid() {

    String rutaResumen;/*w w  w  .  ja  v a 2  s .c o m*/
    int size = setShipmentDetail.iterator().next().getStSampleDetail().getLabstudyid().getPlatesize();
    int plates = setShipmentDetail.size() / size;

    if (size == SIZE_PLATE_96) {

        //PlateContentList.letters=PlateContentList.letters96;
        rutaResumen = property.getKey(REPORT_PATH_KBIO_G96, Bundle.conf);
        rowsplate = 8;
        colsplate = 12;
    } else {

        rowsplate = 16;
        colsplate = 24;
        rutaResumen = property.getKey(REPORT_PATH_KBIO_G384, Bundle.conf);
        //PlateContentList.letters=PlateContentList.letters384;
    }

    InputStream inputStream = null;

    String platenameac = "";
    int rowplatename;

    Integer rowItemNo;
    Integer rowinidatsamples = 4;
    Integer actualrow = 0;
    Integer actualcol = 1;
    Integer cuanhojasvoy = 1;

    try {

        inputStream = getClass().getResourceAsStream(rutaResumen);
        listBook = new HSSFWorkbook(inputStream);
        HSSFSheet sheetDetails = listBook.getSheetAt(0);
        loadDetailSheet(sheetDetails);

        //Crear las hojas que voy a necesitar dependiendo el numero de platos
        Integer cuanhojasnecesito = 1;
        if (size == SIZE_PLATE_96) {
            cuanhojasnecesito = plates / 45;
            if (plates % 45 != 0)
                cuanhojasnecesito = cuanhojasnecesito + 1;
        }

        if (size == SIZE_PLATE_384) {
            cuanhojasnecesito = plates / 26;
            if (plates % 26 != 0)
                cuanhojasnecesito = cuanhojasnecesito + 1;
        }

        for (int i = 1; i < cuanhojasnecesito; i++) {
            listBook.cloneSheet(1);
        }

        HSSFSheet sheetGridActual;

        sheetGridActual = listBook.getSheetAt(cuanhojasvoy);

        int cuanplatosvoy = 0;
        int i = 0;

        for (ShipmentDetail shipmentDetail : setShipmentDetail) {
            SampleDetail sampledetail = shipmentDetail.getStSampleDetail();
            HSSFRow actrowsheetGrid;

            if (sheetGridActual.getRow(i) == null)
                sheetGridActual.createRow(i);

            //poner nombre del plato
            if (!platenameac.equals(sampledetail.getPlatename())) {
                platenameac = sampledetail.getPlatename();

                cuanplatosvoy = cuanplatosvoy + 1;

                //si hay mas de 45 platos entonces hacer una nueva hoja 
                if (cuanplatosvoy % 46 == 0 && size == SIZE_PLATE_96) {
                    cuanhojasvoy = cuanhojasvoy + 1;
                    actualrow = 0;
                    actualcol = 1;
                    cuanplatosvoy = 1;
                    sheetGridActual = listBook.getSheetAt(cuanhojasvoy);
                }

                //si hay mas de 26 platos entonces hacer una nueva hoja 
                if (cuanplatosvoy % 26 == 0 && size == SIZE_PLATE_384) {
                    cuanhojasvoy = cuanhojasvoy + 1;
                    actualrow = 0;
                    actualcol = 1;
                    cuanplatosvoy = 1;
                    sheetGridActual = listBook.getSheetAt(cuanhojasvoy);
                }

                rowplatename = (cuanplatosvoy - 1) * (rowsplate + 2) + cuanplatosvoy;

                if (cuanplatosvoy > 8) {
                    rowplatename = rowplatename + 1;
                }

                //Indica que area se va a combinar (roiwini, rowfin, colini, colfin)

                if (sheetGridActual.getRow(rowplatename) == null)
                    sheetGridActual.createRow(rowplatename);
                actrowsheetGrid = sheetGridActual.getRow(rowplatename);

                if (actrowsheetGrid.getCell(1) == null)
                    actrowsheetGrid.createCell(1);
                actrowsheetGrid.getCell(1).setCellValue(platenameac);

                if (cuanplatosvoy == 1)
                    rowinidatsamples = 2;
                else if (cuanplatosvoy == 9 && size == SIZE_PLATE_96)
                    rowinidatsamples = rowinidatsamples + rowsplate + 4;
                else
                    rowinidatsamples = rowinidatsamples + rowsplate + 3;
            }

            //sacar la siguiente posicion

            actualrow = actualrow + 1;
            if (actualrow > rowsplate) {
                actualcol = actualcol + 1;
                actualrow = 1;
            }

            if (actualcol > colsplate) {
                actualrow = 1;
                actualcol = 1;
            }

            //PONER EL SAMPLEID
            rowItemNo = actualrow + rowinidatsamples;

            if (sheetGridActual.getRow(rowItemNo) == null)
                sheetGridActual.createRow(rowItemNo);
            actrowsheetGrid = sheetGridActual.getRow(rowItemNo);

            if (actrowsheetGrid.getCell(actualcol) == null)
                actrowsheetGrid.createCell(actualcol);

            //SI NO TIENE SAMPLEID COLOCAR "BLANK"
            if (sampledetail.getSamplegid() == null
                    || (sampledetail.getControltype() != null && sampledetail.getControltype().equals("B")))
                actrowsheetGrid.getCell(actualcol).setCellValue("BLANK");
            else
                actrowsheetGrid.getCell(actualcol).setCellValue(
                        sampledetail.getLabstudyid().getPrefix() + (sampledetail.getLabstudyid().isUsePadded()
                                ? StrUtils.getPaddingCeros(sampledetail.getSamplegid())
                                : String.valueOf(sampledetail.getSamplegid())));
            i = i + 1;
        }

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:com.cimmyt.reports.impl.ServiceReportKBioImpl.java

License:Apache License

private void loadPlateID(HSSFSheet sheetList) {
    if (mapPlate != null && !mapPlate.isEmpty()) {
        Iterator<Map.Entry<Integer, String>> it = mapPlate.entrySet().iterator();
        int inidatsheetList = 12;
        int indexRow = 0;
        while (it.hasNext()) {
            HSSFRow actrowsheetList;/*from   ww  w .  jav a 2 s . c  o  m*/
            if (sheetList.getRow(indexRow + inidatsheetList) == null)
                sheetList.createRow(indexRow + inidatsheetList);
            actrowsheetList = sheetList.getRow(indexRow + inidatsheetList);
            if (actrowsheetList.getCell(1) == null)
                actrowsheetList.createCell(1);
            Map.Entry<Integer, String> pair = it.next();
            actrowsheetList.getCell(1).setCellValue(pair.getValue());
            indexRow++;
        }
    }
}

From source file:com.cimmyt.reports.impl.ServiceReportKBioImpl.java

License:Apache License

private void loadListSampleIDGenotypingService(HSSFSheet sheetList) {
    int inidatsheetList = 15;
    String wellkbio;/* w  ww . j  a v  a2 s .  co  m*/
    int i = 0;
    int indexBlank = 1;
    for (ShipmentDetail shipmentDetail : setShipmentDetail) {
        SampleDetail sampledet = shipmentDetail.getStSampleDetail();
        HSSFRow actrowsheetList;
        //****************    sheetList  **************************
        //
        if (sheetList.getRow(i + inidatsheetList) == null)
            sheetList.createRow(i + inidatsheetList);
        actrowsheetList = sheetList.getRow(i + inidatsheetList);
        if (actrowsheetList.getCell(1) == null)
            actrowsheetList.createCell(1);
        if (sampledet.getSamplegid() != null)
            actrowsheetList.getCell(1)
                    .setCellValue(sampledet.getLabstudyid().getPrefix()
                            + (sampledet.getLabstudyid().isUsePadded()
                                    ? StrUtils.getPaddingCeros(sampledet.getSamplegid())
                                    : String.valueOf(sampledet.getSamplegid()))
                            + "-" + sampledet.getStudysampleid());
        if (actrowsheetList.getCell(2) == null)
            actrowsheetList.createCell(2);
        actrowsheetList.getCell(2)
                .setCellValue(getPlate(sampledet.getPlatename(), sampledet.getLabstudyid().getPrefix()));
        if (actrowsheetList.getCell(3) == null)
            actrowsheetList.createCell(3);
        wellkbio = sampledet.getPlateloc();
        if (wellkbio.length() == 2)
            wellkbio = wellkbio.substring(0, 1) + "0" + wellkbio.substring(1);
        actrowsheetList.getCell(3).setCellValue(wellkbio);

        if (sampledet.getPlateloc().equals("H11") || sampledet.getPlateloc().equals("H12")) {
            actrowsheetList.getCell(1).setCellValue("");
        } else {
            //Por especificaciones de KBIo se pone C si es un control y nada si es ADN normal
            if (sampledet.getControltype() != null) {
                if (!sampledet.getControltype().equals("")) {
                    actrowsheetList.getCell(1)
                            .setCellValue(getPathEmpty(indexBlank, sampledet.getStudysampleid()));
                    indexBlank++;
                }
            } else if (sampledet.getSamplegid() == null) {
                actrowsheetList.getCell(1).setCellValue(getPathEmpty(indexBlank, sampledet.getStudysampleid()));
                indexBlank++;
            }

        }
        if (actrowsheetList.getCell(7) == null)
            actrowsheetList.createCell(7);
        actrowsheetList.getCell(7).setCellValue(
                sampledet.getBreedergid() != null ? String.valueOf(sampledet.getBreedergid()) : "");
        if (actrowsheetList.getCell(8) == null)
            actrowsheetList.createCell(8);
        actrowsheetList.getCell(8)
                .setCellValue(sampledet.getNplanta() != null ? String.valueOf(sampledet.getNplanta()) : "");
        i = i + 1;
    }
}

From source file:com.cimmyt.reports.impl.ServiceReportKBioImpl.java

License:Apache License

private void validateRow(HSSFSheet sheetgrid, int indexRow) {
    if (sheetgrid.getRow(indexRow) == null)
        sheetgrid.createRow(indexRow);
}

From source file:com.cimmyt.reports.impl.ServiceReportKBioImpl.java

License:Apache License

private void loadListSampleID(HSSFSheet sheetList) {

    int inidatsheetList = 2;
    String wellkbio;/* ww w . jav  a 2s.c  om*/
    int mod = setShipmentDetail.iterator().next().getStSampleDetail().getLabstudyid().getPlatesize();
    int plates = setShipmentDetail.size() / mod;

    int i = 0;
    for (ShipmentDetail shipmentDetail : setShipmentDetail) {
        SampleDetail sampledet = shipmentDetail.getStSampleDetail();
        HSSFRow actrowsheetList;
        //****************    sheetList  **************************
        //
        if (sheetList.getRow(i + inidatsheetList) == null)
            sheetList.createRow(i + inidatsheetList);
        actrowsheetList = sheetList.getRow(i + inidatsheetList);
        if (actrowsheetList.getCell(0) == null)
            actrowsheetList.createCell(0);
        if (sampledet.getSamplegid() != null)
            actrowsheetList.getCell(0).setCellValue(
                    sampledet.getLabstudyid().getPrefix() + (sampledet.getLabstudyid().isUsePadded()
                            ? StrUtils.getPaddingCeros(sampledet.getSamplegid())
                            : String.valueOf(sampledet.getSamplegid())));
        if (actrowsheetList.getCell(1) == null)
            actrowsheetList.createCell(1);
        actrowsheetList.getCell(1).setCellValue(sampledet.getPlatename());
        if (actrowsheetList.getCell(2) == null)
            actrowsheetList.createCell(2);
        wellkbio = sampledet.getPlateloc();
        if (wellkbio.length() == 2)
            wellkbio = wellkbio.substring(0, 1) + "0" + wellkbio.substring(1);
        actrowsheetList.getCell(2).setCellValue(wellkbio);
        if (actrowsheetList.getCell(3) == null)
            actrowsheetList.createCell(3);
        actrowsheetList.getCell(3).setCellValue("");
        //Por especificaciones de KBIo se pone C si es un control y nada si es ADN normal
        if (sampledet.getControltype() != null)
            if (sampledet.getControltype().equals("K") || sampledet.getControltype().equals("B"))
                actrowsheetList.getCell(3).setCellValue("C");

        if (sampledet.getSamplegid() == null)
            actrowsheetList.getCell(3).setCellValue("C");

        if (actrowsheetList.getCell(4) == null)
            actrowsheetList.createCell(4);
        actrowsheetList.getCell(4).setCellValue(sampledet.getLabstudyid().getPlatesize());

        i = i + 1;
    }
}

From source file:com.cimmyt.reports.impl.ServiceReportLaboratoryImpl.java

License:Apache License

private HSSFWorkbook createBookPlateExcel(StudyLabReportBean beanReport) {
    HSSFWorkbook book = new HSSFWorkbook();
    // Create a new Sheet in book
    HSSFSheet sheet = book.createSheet();
    // Creates a new row for headers
    HSSFRow row = sheet.createRow(0);
    // Creates a new cell for title
    HSSFCell cell = row.createCell(0);/*from  w  w w.  jav  a2  s  . co m*/
    // Create cell contents.
    HSSFRichTextString text = new HSSFRichTextString("");
    cell.setCellValue(text);
    // Creates a new
    HSSFRow rowHeaders = sheet.createRow(2);
    styleCellNormallyHeader = styleCellNormally(book, true);
    styleCellNormally = styleCellNormally(book, false);
    styleCellControl = getStyleCeldSolidForeground(book, cellControl);
    styleCellControlDART = getStyleCeldSolidForeground(book, cellControlDART);
    styleCellControlRandom = getStyleCeldSolidForeground(book, cellControlRandom);
    styleCellControlKBIo = getStyleCeldSolidForeground(book, cellKBiocontrolRandom);
    styleCellBlank = getStyleCeldSolidForeground(book, cellBlankForegroundColor);
    if (beanReport.getMapPlateSamples().size() > 0) {
        Iterator iteratorMapFirst = beanReport.getMapPlateSamples().entrySet().iterator();
        int rowCounter = 1;
        while (iteratorMapFirst.hasNext()) {
            Map.Entry entry = (Map.Entry) iteratorMapFirst.next();
            Map<String, SampleDetail> mapInner = (Map<String, SampleDetail>) entry.getValue();
            Integer key = (Integer) entry.getKey();
            sheet.createRow(rowCounter);
            rowCounter++;
            rowCounter = createHeaderPlate(sheet, rowCounter, beanReport.getNumberColumn(),
                    styleCellNormallyHeader, beanReport.getPatternPlate() + key.toString());
            int rowCounterLabel = 0;

            for (int sizeRow = 0; sizeRow < beanReport.getNameRow().length; sizeRow++) {
                HSSFRow rowData = sheet.createRow(rowCounter);

                for (int sizeColumn = 0; sizeColumn <= beanReport.getNumberColumn(); sizeColumn++) {
                    if (sizeColumn == 0) {
                        writeCell(rowData, sizeColumn, beanReport.getNameRow()[rowCounterLabel],
                                styleCellNormallyHeader);
                        rowCounterLabel++;
                    } else {
                        SampleDetail detail = mapInner.get(beanReport.getPatternPlate() + key.toString()
                                + beanReport.getNameRow()[sizeRow] + (sizeColumn));
                        if (detail != null) {
                            HSSFCellStyle style = null;
                            String sampleName = "";
                            if (detail.getControltype() != null && !detail.getControltype().equals(""))
                                style = validateStatusSample(detail.getControltype());
                            else
                                sampleName = getFieldsReport(beanReport, detail);
                            String strDetail = getTemplateFiled(detail);
                            if (strDetail != null && !strDetail.isEmpty()) {
                                if (!sampleName.isEmpty()) {
                                    sampleName = sampleName + "\n" + strDetail;
                                } else {
                                    sampleName = sampleName + strDetail;
                                }
                            }

                            writeCell(rowData, sizeColumn, sampleName, style);
                        }
                    }
                }
                rowCounter++;
            }
        }
        return book;
    }
    return null;
}

From source file:com.cimmyt.reports.impl.ServiceReportLaboratoryImpl.java

License:Apache License

private int createHeaderPlate(HSSFSheet sheet, int rowCounter, int numberColumn,
        HSSFCellStyle styleCellNormallyHeader, String plateName) {
    HSSFRow rowData = sheet.createRow(rowCounter);
    loadDataCell(rowData, plateName, 0, styleCellNormallyHeader);
    for (int index = 1; index <= numberColumn; index++) {
        loadDataCell(rowData, String.valueOf(index), index, styleCellNormallyHeader);
    }/* www  .  ja v  a  2 s.  co  m*/

    return ++rowCounter;
}