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

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

Introduction

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

Prototype

@Override
public HSSFRow getRow(int rowIndex) 

Source Link

Document

Returns the logical row (not physical) 0-based.

Usage

From source file:com.ibm.ioes.bulkupload.utilities.ErrorLogServiceImpl.java

public String getResultExcel(String filePath, int fileID) throws IOESException {
    //logger.info(" Entered into getErrorExcel method of " + this.getClass().getSimpleName());

    int colCount, ctr = 0;
    String fileName;/*from   ww  w.j a  v a2s . c om*/
    HSSFWorkbook wb;
    HSSFSheet ws;
    HSSFRow wr;
    HSSFCell wc;
    ArrayList errVal = new ArrayList();
    ErrorFileDaoImpl objDao = new ErrorFileDaoImpl();
    ErrorLogDto dtoObj;

    try {
        ResourceBundle bundle = ResourceBundle.getBundle("ApplicationResources");

        fileName = filePath.substring((filePath.lastIndexOf("/") + 1), filePath.length());
        String newFile = bundle.getString("excel.success") + "/" + fileName;
        FileOutputStream fileOut = new FileOutputStream(newFile);
        wb = new HSSFWorkbook(new FileInputStream(filePath));

        errVal = objDao.getResultLog(fileID);
        System.out.println(errVal.toString());
        System.out.println(wb.getNumberOfSheets());
        for (int s = 0; s < wb.getNumberOfSheets(); s++) {

            ws = wb.getSheetAt(s);
            wr = ws.getRow(1);
            colCount = wr.getLastCellNum();
            wc = wr.createCell(colCount);
            wc.setCellValue("RESULT LOG" + "_" + "ORDERNO");

            for (int r = 2; r <= ws.getLastRowNum(); r++) {
                if ((ctr < errVal.size())) {
                    dtoObj = (ErrorLogDto) errVal.get(ctr);
                    wr = ws.getRow(r);
                    if (wr != null) {
                        int chk = 0;
                        for (int col = 0; col < colCount; col++) {
                            wc = wr.getCell(col);
                            if (wc != null) {
                                if (!(wc.toString().trim().equals(""))) {
                                    chk = 1;
                                }
                            }
                        }
                        if (chk == 1) {
                            wc = wr.createCell(colCount);
                            System.out.println(dtoObj.getResultLogValue());
                            if (dtoObj.getResultLogValue() == null) {
                                wc.setCellValue("SUCCESS");
                            } else {
                                if (dtoObj.getOrderNo() != null)
                                    wc.setCellValue(dtoObj.getResultLogValue().toString() + "_("
                                            + dtoObj.getOrderNo().toString() + ")");
                            }

                            ctr++;
                        }
                    }
                }
            }
        }
        wb.write(fileOut);
        fileOut.close();
        filePath = newFile;
    } catch (IOESException ex) {
        logger.error(ex.getMessage() + "::BULKUPLOAD_ERROR:: Exception occured in getResultExcel method of "
                + this.getClass().getSimpleName());
        throw new IOESException("SQL Exception : " + ex.getMessage(), ex);
    } catch (IOException ioExp) {
        //logger.error(ioExp.getMessage() + " Exception occured in getErrorExcel method of " + this.getClass().getSimpleName());
        //throw new IOESException("SQL Exception : "+ ioExp.getMessage(), ioExp);
        Utility.LOG(true, false, ioExp, "::BULKUPLOAD_ERROR:: Exception occured in getResultExcel method of "
                + this.getClass().getSimpleName());
        return filePath = "NOTFOUND";
    }
    return filePath;
}

From source file:com.ibm.ioes.bulkupload.utilities.ErrorLogServiceImpl.java

public String getFilledTemplate(String filePath, int templateId, int flag, String logicalLSI)
        throws IOESException, ParseException {
    //logger.info(" Entered into getErrorExcel method of " + this.getClass().getSimpleName());

    String fileName;//from   w ww. ja  v  a 2  s.  c  o  m
    HSSFWorkbook wb;
    HSSFSheet ws;
    HSSFRow wr;
    HSSFCell wc;
    ArrayList filledTemplateData = new ArrayList();
    ArrayList<ViewOrderDto> filledTemplateDataLineDetails = new ArrayList<ViewOrderDto>();
    ArrayList<ViewOrderDto> filledTemplateDataChargeDetails = new ArrayList<ViewOrderDto>();
    ErrorFileDaoImpl objDao = new ErrorFileDaoImpl();
    ViewOrderModel objviewmodel = new ViewOrderModel();
    //ErrorLogDto dtoObj ;
    TransactionTemplateDto dtoObj;
    ViewOrderDto dtoObj1;
    DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
    int totalRowsOfSheet = 0;
    ViewOrderDto objdto = null;
    String str = null;
    BillingTriggerValidation validateDto = null;
    try {
        ResourceBundle bundle = ResourceBundle.getBundle("ApplicationResources");

        fileName = filePath.substring((filePath.lastIndexOf("/") + 1), filePath.length());
        String newFile = bundle.getString("excel.filledTemplate") + "/" + fileName;
        FileOutputStream fileOut = new FileOutputStream(newFile);
        wb = new HSSFWorkbook(new FileInputStream(filePath));
        HSSFCellStyle whiteFG_yellow = wb.createCellStyle();

        HSSFColor yellow = setColor(wb, (byte) 0xFF, (byte) 0xFF, (byte) 0x00);
        //whiteFG_yellow.setFillBackgroundColor(HSSFColor.YELLOW.index);
        whiteFG_yellow.setFillBackgroundColor(yellow.getIndex());

        HSSFCellStyle whiteFG_green = wb.createCellStyle();
        HSSFColor green = setColor(wb, (byte) 0x00, (byte) 0xFF, (byte) 0x00);
        //whiteFG_green.setFillBackgroundColor(HSSFColor.GREEN.index);
        whiteFG_green.setFillBackgroundColor(green.getIndex());

        //System.out.println(filledTemplateData.toString());
        //System.out.println(wb.getNumberOfSheets());

        for (int s = 0; s < wb.getNumberOfSheets(); s++) {
            ws = wb.getSheetAt(s);
            if (s == 0 && (templateId == 1 || templateId == 22 || templateId == 21 || templateId == 41)) {
                int ctr = 0, totalRowsOfSheetMain = 0, totalRowsOfSheetAtt = 0;
                totalRowsOfSheetMain = objDao.getTotalRowsOfSheet(s + 1, templateId, flag, logicalLSI);
                filledTemplateData = objDao.getFilledTemplate(s + 1, templateId, flag, logicalLSI);
                for (int r = 2; r <= (totalRowsOfSheetMain + 1); r++) {
                    dtoObj = (TransactionTemplateDto) filledTemplateData.get(ctr);
                    wr = ws.createRow(r);
                    if (wr != null) {
                        wr.createCell(1).setCellValue(dtoObj.getOrderNo());
                        wr.createCell(2).setCellValue(new HSSFRichTextString((dtoObj.getAccountID())));
                        wr.createCell(3).setCellValue(new HSSFRichTextString((dtoObj.getSource())));
                        wr.createCell(4).setCellValue(new HSSFRichTextString((dtoObj.getCurrencyID())));
                        wr.createCell(5).setCellValue(new HSSFRichTextString((dtoObj.getOpportunityId())));
                        wr.createCell(6).setCellValue(new HSSFRichTextString((dtoObj.getQuoteNo())));
                        wr.createCell(7).setCellValue(new HSSFRichTextString((dtoObj.getProjectMangerID())));
                        wr.createCell(8).setCellValue(new HSSFRichTextString((dtoObj.getZoneId())));
                    }
                    ctr++;
                }
                totalRowsOfSheetAtt = objDao.getTotalRowsOfSheet(11, templateId, flag, logicalLSI);
                filledTemplateData = objDao.getFilledTemplate(11, templateId, flag, logicalLSI);
                ctr = 0;
                for (int r = 2; r <= (totalRowsOfSheetMain + 1); r++) {
                    wr = ws.getRow(r);
                    dtoObj = (TransactionTemplateDto) filledTemplateData.get(ctr);
                    if (wr != null) {
                        wr.createCell(9).setCellValue(new HSSFRichTextString((dtoObj.getRFSDate())));
                        wr.createCell(10).setCellValue(new HSSFRichTextString((dtoObj.getActMngrPhoneNo())));
                        wr.createCell(11).setCellValue(new HSSFRichTextString((dtoObj.getActMngrEmailID())));
                        wr.createCell(12).setCellValue(new HSSFRichTextString((dtoObj.getIRUOrderYN())));
                        wr.createCell(13).setCellValue(new HSSFRichTextString((dtoObj.getFreePeriodYN())));
                        wr.createCell(14).setCellValue(new HSSFRichTextString((dtoObj.getOrdExclusiveTax())));
                        wr.createCell(15).setCellValue(new HSSFRichTextString((dtoObj.getCAFDate())));
                    }
                    ctr++;
                }
            }
            //GAM Sheet
            if (s == 1 && (templateId == 1 || templateId == 22 || templateId == 21 || templateId == 41)) {
                //to do nothing
            }
            //Contact Sheet
            if (s == 2 && (templateId == 1 || templateId == 22 || templateId == 21 || templateId == 41)) {
                int ctr = 0, rownum = 1;
                totalRowsOfSheet = objDao.getTotalRowsOfSheet(s + 1, templateId, flag, logicalLSI);
                filledTemplateData = objDao.getFilledTemplate(s + 1, templateId, flag, logicalLSI);

                for (int r = 2; r <= (totalRowsOfSheet + 1); r++) {
                    dtoObj = (TransactionTemplateDto) filledTemplateData.get(ctr);
                    wr = ws.createRow(r);
                    if (wr != null) {
                        wr.createCell(1).setCellValue(rownum);
                        wr.createCell(2).setCellValue(dtoObj.getOrderNo());
                        wr.createCell(3).setCellValue(dtoObj.getContactType());
                        wr.createCell(4).setCellValue(new HSSFRichTextString((dtoObj.getSalutation())));
                        wr.createCell(5).setCellValue(new HSSFRichTextString((dtoObj.getFirstName())));
                        wr.createCell(6).setCellValue(new HSSFRichTextString((dtoObj.getLastName())));
                        wr.createCell(7).setCellValue(new HSSFRichTextString((dtoObj.getEmail())));
                        wr.createCell(8).setCellValue(new HSSFRichTextString((dtoObj.getCellno())));
                        wr.createCell(9).setCellValue(new HSSFRichTextString((dtoObj.getFaxno())));
                        wr.createCell(10).setCellValue(rownum);
                        wr.createCell(11).setCellValue(new HSSFRichTextString((dtoObj.getAddress1())));
                        wr.createCell(12).setCellValue(new HSSFRichTextString((dtoObj.getAddress2())));
                        wr.createCell(13).setCellValue(new HSSFRichTextString((dtoObj.getAddress3())));
                        wr.createCell(14).setCellValue(new HSSFRichTextString((dtoObj.getCountrycode())));
                        wr.createCell(15).setCellValue(new HSSFRichTextString((dtoObj.getStateid())));
                        wr.createCell(16).setCellValue(new HSSFRichTextString((dtoObj.getCityid())));
                        wr.createCell(17).setCellValue(new HSSFRichTextString((dtoObj.getPincode())));
                    }
                    ctr++;
                    rownum++;
                }
            }
            if (s == 3 && (templateId == 1 || templateId == 22 || templateId == 21)) {
                int ctr = 0, rownum = 1;
                if (templateId == 21) {
                    totalRowsOfSheet = objDao.getTotalRowsOfSheet(s + 1, templateId, flag, logicalLSI);
                    filledTemplateData = objDao.getFilledTemplate(s + 1, templateId, flag, logicalLSI);
                    for (int r = 2; r <= (totalRowsOfSheet + 1); r++) {
                        dtoObj = (TransactionTemplateDto) filledTemplateData.get(ctr);
                        wr = ws.createRow(r);
                        if (wr != null) {
                            wr.createCell(1).setCellValue(rownum);
                            wr.createCell(2).setCellValue(dtoObj.getOrderNo());
                            wr.createCell(3).setCellValue(dtoObj.getLogicalsiNo());
                            wr.createCell(4).setCellValue(dtoObj.getServiceid());
                            wr.createCell(5).setCellValue(new HSSFRichTextString((dtoObj.getServiceName())));
                            wr.createCell(6).setCellValue(dtoObj.getLineItemID());
                            wr.createCell(7).setCellValue(new HSSFRichTextString((dtoObj.getLineItemName())));

                        }
                        ctr++;
                        rownum++;
                    }
                } else {
                    totalRowsOfSheet = objDao.getTotalRowsOfSheet(s + 1, templateId, flag, logicalLSI);
                    filledTemplateData = objDao.getFilledTemplate(s + 1, templateId, flag, logicalLSI);
                    for (int r = 2; r <= (totalRowsOfSheet + 1); r++) {
                        dtoObj = (TransactionTemplateDto) filledTemplateData.get(ctr);
                        wr = ws.createRow(r);
                        if (wr != null) {
                            wr.createCell(1).setCellValue(rownum);
                            wr.createCell(2).setCellValue(dtoObj.getOrderNo());
                            wr.createCell(3).setCellValue(dtoObj.getLogicalsiNo());
                            wr.createCell(4).setCellValue(dtoObj.getServiceid());
                            wr.createCell(5).setCellValue(dtoObj.getLineItemID());
                        }
                        ctr++;
                        rownum++;
                    }
                }
            }
            if (s == 3 && templateId == 41) {
                /*int  ctr=0,rownum=1;
                totalRowsOfSheet=objDao.getTotalRowsOfSheet(s+1,templateId,flag,logicalLSI);   
                filledTemplateData = objDao.getFilledTemplate(s+1,templateId,flag,logicalLSI);   
                for(int r = 2; r <= (totalRowsOfSheet+1); r++)
                {
                   dtoObj = (TransactionTemplateDto)filledTemplateData.get(ctr);               
                   wr=ws.createRow(r);
                   if(wr!=null)
                   {         
                      wr.createCell(1).setCellValue(rownum);
                      wr.createCell(2).setCellValue(dtoObj.getOrderNo());
                      wr.createCell(3).setCellValue(new HSSFRichTextString((dtoObj.getCustPONumber())));
                      wr.createCell(4).setCellValue(new HSSFRichTextString((dtoObj.getCustPODate())));                     
                      wr.createCell(5).setCellValue(new HSSFRichTextString((dtoObj.getIsDefaultPO())));
                      wr.createCell(6).setCellValue(new HSSFRichTextString((dtoObj.getLegalEntity())));
                      wr.createCell(7).setCellValue(new HSSFRichTextString((dtoObj.getTotalPOAmount())));
                      wr.createCell(8).setCellValue(new HSSFRichTextString((dtoObj.getPeriodInMonths())));
                      wr.createCell(9).setCellValue(new HSSFRichTextString((dtoObj.getContractStartDate())));
                      wr.createCell(10).setCellValue(new HSSFRichTextString((dtoObj.getContractEndDate())));
                      wr.createCell(11).setCellValue(new HSSFRichTextString((dtoObj.getPoRemarks())));
                      wr.createCell(12).setCellValue(new HSSFRichTextString((dtoObj.getPoEmailId())));
                   }
                   ctr++;rownum++;
                }*/
            }
            if (s == 4 && templateId == 41) {
                int ctr = 0, rownum = 1;
                totalRowsOfSheet = objDao.getTotalRowsOfSheet(s + 1, templateId, flag, logicalLSI);
                filledTemplateData = objDao.getFilledTemplate(s + 1, templateId, flag, logicalLSI);
                for (int r = 2; r <= (totalRowsOfSheet + 1); r++) {
                    dtoObj = (TransactionTemplateDto) filledTemplateData.get(ctr);
                    wr = ws.createRow(r);
                    if (wr != null) {
                        wr.createCell(1).setCellValue(rownum);
                        wr.createCell(2).setCellValue(dtoObj.getOrderNo());
                        wr.createCell(3).setCellValue(dtoObj.getLogicalsiNo());
                        wr.createCell(4).setCellValue(dtoObj.getServiceid());
                        wr.createCell(5).setCellValue(dtoObj.getLineItemID());
                        wr.createCell(6).setCellValue(dtoObj.getChargeID());
                        wr.createCell(7).setCellValue(dtoObj.getChargeAmount());
                        wr.createCell(8).setCellValue(new HSSFRichTextString((dtoObj.getChargeFrequency())));
                        wr.createCell(9).setCellValue(new HSSFRichTextString((dtoObj.getStrChargeType())));
                        wr.createCell(10).setCellValue(new HSSFRichTextString((dtoObj.getStrChargeName())));
                        wr.createCell(11).setCellValue(dtoObj.getFrequncyAmount());
                        wr.createCell(12).setCellValue(new HSSFRichTextString((dtoObj.getAnnotation())));
                    }
                    ctr++;
                    rownum++;
                }
            }
            if (s == 5 && templateId == 41) {
                int ctr = 0, rownum = 1;
                totalRowsOfSheet = objDao.getTotalRowsOfSheet(s + 1, templateId, flag, logicalLSI);
                filledTemplateData = objDao.getFilledTemplate(s + 1, templateId, flag, logicalLSI);
                for (int r = 2; r <= (totalRowsOfSheet + 1); r++) {
                    dtoObj = (TransactionTemplateDto) filledTemplateData.get(ctr);
                    wr = ws.createRow(r);
                    if (wr != null) {
                        wr.createCell(1).setCellValue(rownum);
                        wr.createCell(2).setCellValue(new HSSFRichTextString(""));
                        wr.createCell(3).setCellValue(dtoObj.getLineItemID());
                        wr.createCell(4).setCellValue(dtoObj.getCreditPeriodID());
                        wr.createCell(5).setCellValue(new HSSFRichTextString((dtoObj.getCreditPeriodName())));
                        wr.createCell(6).setCellValue(dtoObj.getLegealEntityID());
                        wr.createCell(7).setCellValue(new HSSFRichTextString((dtoObj.getLegalEntityName())));
                        wr.createCell(8).setCellValue(dtoObj.getLicenseCompanyID());
                        wr.createCell(9).setCellValue(new HSSFRichTextString((dtoObj.getLicenseCompanyName())));
                        wr.createCell(10).setCellValue(dtoObj.getBillingModeID());
                        wr.createCell(11).setCellValue(new HSSFRichTextString((dtoObj.getBillingModeName())));
                        wr.createCell(12).setCellValue(dtoObj.getBillingFormatID());
                        wr.createCell(13).setCellValue(new HSSFRichTextString((dtoObj.getBillingFormatName())));
                        wr.createCell(14).setCellValue(dtoObj.getBillingTypeID());
                        wr.createCell(15).setCellValue(new HSSFRichTextString((dtoObj.getBillingTypeName())));
                        wr.createCell(16).setCellValue(dtoObj.getTaxationID());
                        wr.createCell(17).setCellValue(new HSSFRichTextString(dtoObj.getTaxationName()));
                        wr.createCell(18).setCellValue(dtoObj.getBillingLevelID());
                        wr.createCell(19).setCellValue(new HSSFRichTextString(dtoObj.getBillingLevelName()));
                        wr.createCell(20).setCellValue(dtoObj.getNoticePeriod());
                        wr.createCell(21).setCellValue(new HSSFRichTextString(dtoObj.getPenaltyClause()));
                        wr.createCell(22).setCellValue(dtoObj.getCommitPeriod());
                        wr.createCell(23).setCellValue(dtoObj.getIsNfa());
                        wr.createCell(24).setCellValue(dtoObj.getBcpID());
                        wr.createCell(25).setCellValue(new HSSFRichTextString(dtoObj.getBcpName()));
                        wr.createCell(26).setCellValue(new HSSFRichTextString(dtoObj.getStandardReasonId()));
                        wr.createCell(27).setCellValue(new HSSFRichTextString(dtoObj.getStandardReasonName()));

                    }
                    ctr++;
                    rownum++;
                }
            }

            // billing trigger bulkupload  sheet 1 start

            if (s == 0 && templateId == 61) {
                int ctr = 0, rownum = 1;

                filledTemplateDataLineDetails = objviewmodel.getFilledTemplateforBillingLineSectionBulkUpload();
                for (int r = 2; r <= (filledTemplateDataLineDetails.size() + 1); r++) {
                    dtoObj1 = (ViewOrderDto) filledTemplateDataLineDetails.get(ctr);
                    wr = ws.createRow(r);
                    if (wr != null) {
                        HSSFCell cell0 = wr.createCell(0);
                        cell0.setCellValue(rownum);

                        HSSFCell cell1 = wr.createCell(1);
                        cell1.setCellValue(new HSSFRichTextString(dtoObj1.getLineNumber()));
                        HSSFCellStyle sty1 = ws.getRow(1).getCell(1).getCellStyle();

                        wr.createCell(2).setCellValue(new HSSFRichTextString(dtoObj1.getLineName()));
                        wr.createCell(3).setCellValue(new HSSFRichTextString(dtoObj1.getLogicalSino()));
                        wr.createCell(4).setCellValue(new HSSFRichTextString(dtoObj1.getCustLogicalSino()));
                        wr.createCell(5).setCellValue(dtoObj1.getOrderno());
                        wr.createCell(6).setCellValue(new HSSFRichTextString(dtoObj1.getOrdertype()));
                        wr.createCell(7).setCellValue(new HSSFRichTextString(dtoObj1.getOrder_subtype()));
                        wr.createCell(8).setCellValue(new HSSFRichTextString(dtoObj1.getSiid()));
                        wr.createCell(9).setCellValue(new HSSFRichTextString(dtoObj1.getAccountid()));
                        wr.createCell(10).setCellValue(new HSSFRichTextString(dtoObj1.getFx_status()));
                        wr.createCell(11).setCellValue(new HSSFRichTextString(dtoObj1.getLine_status()));
                        wr.createCell(12).setCellValue(new HSSFRichTextString(dtoObj1.getChallen_No()));
                        wr.createCell(13).setCellValue(new HSSFRichTextString(dtoObj1.getChallen_date()));
                        validateDto = dtoObj1.getBillingTriggerAllowDenyLogic();

                        HSSFCell cell14 = wr.createCell(14);
                        cell14.setCellValue(new HSSFRichTextString(dtoObj1.getLocNo()));
                        HSSFCellStyle sty = ws.getRow(1).getCell(14).getCellStyle();
                        if ("allow".equals(validateDto.getLocNoForEdit())) {
                            cell14.setCellStyle(sty);

                        } else {
                            cell14.setCellStyle(sty1);
                        }

                        HSSFCell cell15 = wr.createCell(15);
                        if (!(dtoObj1.getLocDate() == null || "".equals(dtoObj1.getLocDate()))) {
                            cell15.setCellValue(new HSSFRichTextString(
                                    Utility.showDate_Report4(df.parse(dtoObj1.getLocDate()))));
                        } else {
                            cell15.setCellValue(new HSSFRichTextString(dtoObj1.getLocDate()));
                        }
                        if ("allow".equals(validateDto.getLocDateForEdit())) {
                            cell15.setCellStyle(sty);
                        } else {
                            cell15.setCellStyle(sty1);
                        }

                        HSSFCell cell16 = wr.createCell(16);
                        if (!(dtoObj1.getLocRecDate() == null || "".equals(dtoObj1.getLocRecDate()))) {
                            cell16.setCellValue(new HSSFRichTextString(
                                    Utility.showDate_Report4(df.parse(dtoObj1.getLocRecDate()))));
                        } else {
                            cell16.setCellValue(new HSSFRichTextString(dtoObj1.getLocRecDate()));
                        }

                        if ("allow".equals(validateDto.getLocRecDateForEdit())) {
                            cell16.setCellStyle(sty);
                        } else {
                            cell16.setCellStyle(sty1);
                        }

                        HSSFCell cell17 = wr.createCell(17);
                        if (!(dtoObj1.getBillingTriggerDate() == null
                                || "".equals(dtoObj1.getBillingTriggerDate()))) {
                            cell17.setCellValue(new HSSFRichTextString(
                                    Utility.showDate_Report4(df.parse(dtoObj1.getBillingTriggerDate()))));
                        } else {
                            cell17.setCellValue(new HSSFRichTextString(dtoObj1.getBillingTriggerDate()));
                        }

                        if ("allow".equals(validateDto.getBtdForEdit())) {
                            cell17.setCellStyle(sty);
                        } else {
                            cell17.setCellStyle(sty1);
                        }

                        wr.createCell(18)
                                .setCellValue(new HSSFRichTextString(dtoObj1.getBillingTriggerProcess()));

                    }
                    ctr++;
                    rownum++;
                }
            }

            // billing trigger bulkupload  sheet 1 end

            //billing trigger bulkupload  sheet 2 start
            if (s == 1 && templateId == 61) {
                int ctr = 0, rownum = 1;
                if (filledTemplateDataLineDetails.size() > 0) {

                    filledTemplateDataChargeDetails = objviewmodel
                            .getFilledTemplateforBillingChargeSectionBulkUpload();
                    for (int r = 2; r <= (filledTemplateDataChargeDetails.size() + 1); r++) {
                        dtoObj1 = (ViewOrderDto) filledTemplateDataChargeDetails.get(ctr);
                        wr = ws.createRow(r);
                        if (wr != null) {
                            wr.createCell(0).setCellValue(rownum);
                            HSSFCell cell1 = wr.createCell(1);
                            cell1.setCellValue(dtoObj1.getChargeInfoId());
                            HSSFCellStyle sty1 = ws.getRow(1).getCell(1).getCellStyle();
                            wr.createCell(2).setCellValue(new HSSFRichTextString(dtoObj1.getLineNumber()));
                            wr.createCell(3).setCellValue(new HSSFRichTextString(dtoObj1.getChargeType()));
                            wr.createCell(4).setCellValue(new HSSFRichTextString(dtoObj1.getChargeName()));
                            wr.createCell(5).setCellValue(dtoObj1.getChargePeriod());
                            wr.createCell(6).setCellValue(dtoObj1.getChargeAmt());
                            wr.createCell(7).setCellValue(new HSSFRichTextString(dtoObj1.getChargeStatus()));
                            HSSFCell cell8 = wr.createCell(8);
                            HSSFCellStyle sty8 = ws.getRow(1).getCell(8).getCellStyle();
                            if (!(dtoObj1.getDisconnectiondate() == null
                                    || "".equals(dtoObj1.getDisconnectiondate()))) {
                                cell8.setCellValue(new HSSFRichTextString(
                                        Utility.showDate_Report4(df.parse(dtoObj1.getDisconnectiondate()))));
                            } else {
                                cell8.setCellValue(new HSSFRichTextString(dtoObj1.getDisconnectiondate()));
                            }
                            if ("Changed".equalsIgnoreCase(dtoObj1.getChargeStatus())) {
                                cell8.setCellStyle(sty8);

                            }

                            wr.createCell(9)
                                    .setCellValue(new HSSFRichTextString(dtoObj1.getChargeCreatedOnOrder()));
                            wr.createCell(10)
                                    .setCellValue(new HSSFRichTextString(dtoObj1.getChargeEndedOnOrder()));
                            wr.createCell(11).setCellValue(new HSSFRichTextString(dtoObj1.getBillPeriod()));
                            wr.createCell(12).setCellValue(new HSSFRichTextString(dtoObj1.getStartdatelogic()));
                            wr.createCell(13).setCellValue(dtoObj1.getStart_date_days());
                            wr.createCell(14).setCellValue(dtoObj1.getStart_date_month());
                            wr.createCell(15).setCellValue(new HSSFRichTextString(dtoObj1.getEnddatelogic()));
                            wr.createCell(16).setCellValue(dtoObj1.getEnd_date_days());
                            wr.createCell(17).setCellValue(dtoObj1.getEnd_date_month());
                            wr.createCell(18)
                                    .setCellValue(new HSSFRichTextString(dtoObj1.getChargeEndDate_String()));
                            wr.createCell(19).setCellValue(new HSSFRichTextString(dtoObj1.getAnnualRate()));
                            wr.createCell(20).setCellValue(new HSSFRichTextString(dtoObj1.getAnnotation()));
                            wr.createCell(21).setCellValue(new HSSFRichTextString(dtoObj1.getStartTokenNo()));
                            wr.createCell(22).setCellValue(new HSSFRichTextString(dtoObj1.getStartFxStatus()));
                            wr.createCell(23).setCellValue(new HSSFRichTextString(dtoObj1.getStartFxNo()));
                            wr.createCell(24).setCellValue(new HSSFRichTextString(dtoObj1.getEndTokenNo()));
                            wr.createCell(25).setCellValue(new HSSFRichTextString(dtoObj1.getEndFxStatus()));
                            wr.createCell(26).setCellValue(new HSSFRichTextString(dtoObj1.getEndFxNo()));
                            wr.createCell(27)
                                    .setCellValue(new HSSFRichTextString(dtoObj1.getChargeStartStatus()));
                            wr.createCell(28)
                                    .setCellValue(new HSSFRichTextString(dtoObj1.getChargeEndStatus()));
                            wr.createCell(29)
                                    .setCellValue(new HSSFRichTextString(dtoObj1.getChargefrequency()));
                            wr.createCell(30).setCellValue(new HSSFRichTextString(dtoObj1.getFxViewId()));
                        }
                        ctr++;
                        rownum++;
                    }
                }
            }
            //         billing trigger bulkupload  sheet 2 end   
        }
        wb.write(fileOut);
        fileOut.close();
        filePath = newFile;
    } catch (IOESException ex) {
        logger.error(ex.getMessage() + "::BULKUPLOAD_ERROR:: Exception occured in getFilledTemplate method of "
                + this.getClass().getSimpleName());
        throw new IOESException("SQL Exception : " + ex.getMessage(), ex);
    } catch (IOException ioExp) {
        //logger.error(ioExp.getMessage() + " Exception occured in getErrorExcel method of " + this.getClass().getSimpleName());
        //throw new IOESException("SQL Exception : "+ ioExp.getMessage(), ioExp);
        Utility.LOG(true, false, ioExp, "::BULKUPLOAD_ERROR:: Exception occured in getFilledTemplate method of "
                + this.getClass().getSimpleName());
        return filePath = "NOTFOUND";
    }
    return filePath;
}

From source file:com.ibm.ioes.bulkupload.utilities.ErrorLogServiceImpl.java

public String getResultErrorMixLog(String filePath, int fileID) throws IOESException {
    //logger.info(" Entered into getErrorExcel method of " + this.getClass().getSimpleName());

    int colCount, ctr = 0;
    String fileName;/*from  w w  w .  j  av a 2s. co  m*/
    HSSFWorkbook wb;
    HSSFSheet ws;
    HSSFRow wr;
    HSSFCell wc;
    ArrayList errVal = new ArrayList();
    ErrorFileDaoImpl objDao = new ErrorFileDaoImpl();
    ErrorLogDto dtoObj;

    try {
        ResourceBundle bundle = ResourceBundle.getBundle("ApplicationResources");

        fileName = filePath.substring((filePath.lastIndexOf("/") + 1), filePath.length());
        String newFile = bundle.getString("excel.success") + "/" + fileName;
        FileOutputStream fileOut = new FileOutputStream(newFile);
        wb = new HSSFWorkbook(new FileInputStream(filePath));

        errVal = objDao.getResultErrorMixLog(fileID);
        System.out.println(errVal.toString());
        System.out.println(wb.getNumberOfSheets());

        HSSFCellStyle styleErr = wb.createCellStyle();
        HSSFCellStyle styleSuccess = wb.createCellStyle();
        HSSFFont fontSuccess = wb.createFont();
        HSSFFont fontErr = wb.createFont();

        for (int s = 0; s < wb.getNumberOfSheets(); s++) {

            ws = wb.getSheetAt(s);
            wr = ws.getRow(1);
            colCount = wr.getLastCellNum();
            wc = wr.createCell(colCount);
            wc.setCellValue("RESULT LOG" + "_" + "ORDERNO");

            for (int r = 2; r <= ws.getLastRowNum(); r++) {
                if ((ctr < errVal.size())) {
                    dtoObj = (ErrorLogDto) errVal.get(ctr);
                    wr = ws.getRow(r);
                    if (wr != null) {
                        int chk = 0;
                        for (int col = 0; col < colCount; col++) {
                            wc = wr.getCell(col);
                            if (wc != null) {
                                if (!(wc.toString().trim().equals(""))) {
                                    chk = 1;
                                }
                            }
                        }
                        if (chk == 1) {
                            wc = wr.createCell(colCount);
                            if ((dtoObj.getResultLogValue() == null || dtoObj.getResultLogValue().length() == 0)
                                    && dtoObj.getErrorLogValue() != null) {
                                fontErr.setColor(HSSFColor.RED.index);
                                styleErr.setFont(fontErr);
                                wc.setCellStyle(styleErr);
                                wc.setCellValue(dtoObj.getErrorLogValue().toString());
                            } else {
                                fontSuccess.setColor(HSSFColor.BLACK.index);
                                styleSuccess.setFont(fontSuccess);
                                wc.setCellStyle(styleSuccess);
                                wc.setCellValue(dtoObj.getResultLogValue().toString());
                            }

                            ctr++;
                        }
                    }
                }
            }
        }
        wb.write(fileOut);
        fileOut.close();
        filePath = newFile;
    } catch (IOESException ex) {
        logger.error(ex.getMessage() + " Exception occured in getResultExcel method of "
                + this.getClass().getSimpleName());
        throw new IOESException("SQL Exception : " + ex.getMessage(), ex);
    } catch (IOException ioExp) {
        //logger.error(ioExp.getMessage() + " Exception occured in getErrorExcel method of " + this.getClass().getSimpleName());
        //throw new IOESException("SQL Exception : "+ ioExp.getMessage(), ioExp);
        return filePath = "NOTFOUND";
    }
    return filePath;
}

From source file:com.inet.web.service.mail.utils.ImportUtil.java

License:Open Source License

/**
 * Read content from given file/*from   ww w . j av a 2  s. c o  m*/
 * @param fileInputStream
 * @return list of account 
 * @throws BiffException
 * @throws IOException
 */
public static List<AccountImportInfo> readEmail(InputStream fileInputStream) throws Exception {
    try {
        POIFSFileSystem document = new POIFSFileSystem(fileInputStream);
        HSSFWorkbook workbook = new HSSFWorkbook(document);

        // Getting Default Sheet  0
        HSSFSheet sheet = workbook.getSheetAt(0);
        HSSFRow rowData = null;
        String pwd = StringService.EMPTY_STRING;
        List<AccountImportInfo> infos = new ArrayList<AccountImportInfo>();
        for (int i = 1;; i++) {
            // Get Individual Row
            rowData = sheet.getRow(i);
            if (rowData == null)
                break;

            // read data
            AccountImportInfo info = new AccountImportInfo();
            info.setNumber(getLong(rowData, SEQUENCE));
            info.setFullName(standardized(getString(rowData, FULLNAME)));
            info.setAccount(getString(rowData, EMAIL));
            info.setLastName(standardized(getString(rowData, LASTNAME)));
            info.setMiddleName(standardized(getString(rowData, MIDDLENAME)));
            info.setFirstName(standardized(getString(rowData, FIRSTNAME)));

            pwd = getString(rowData, PASSWORD);
            if (!StringService.hasLength(pwd)) {
                pwd = info.getAccount();
                info.setPassword(MailCommonUtils.getName(pwd));
            } else {
                info.setPassword(pwd);
            }

            info.setPosition(getString(rowData, POSITION));
            info.setTelephone(getString(rowData, TELEPHONE));
            info.setMobile(getString(rowData, MOBILE));
            info.setQuota(getLong(rowData, QUOTA));
            infos.add(info);
            info.toString();
        }
        return infos;
    } catch (Exception ex) {
        ex.printStackTrace();
        throw ex;
    }
}

From source file:com.ivstars.astrology.util.LocationProvider.java

License:Open Source License

public Location[] listLocations(String province) {
    HSSFSheet sheet = wb.getSheet(province);
    int begin = sheet.getFirstRowNum();
    int end = sheet.getLastRowNum();
    Location[] locs = new Location[end - begin + 1];
    for (int i = begin; i <= end; i++) {
        locs[i - begin] = createLocation(sheet.getRow(i), province);
    }//from www  .ja  va  2 s.  c  o m
    return locs;
}

From source file:com.kahlon.guard.controller.DocumentManager.java

public void postProcessXLS(Object document) {
    HSSFWorkbook wb = (HSSFWorkbook) document;
    HSSFSheet sheet = wb.getSheetAt(0);
    HSSFRow header = sheet.getRow(0);

    HSSFCellStyle cellStyle = wb.createCellStyle();
    cellStyle.setFillForegroundColor(HSSFColor.BLUE.index);

    cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    HSSFFont font = wb.createFont();/*from w  ww.  ja  v  a 2  s .co  m*/
    font.setColor(HSSFColor.WHITE.index);
    cellStyle.setFont(font);
    for (int i = 0; i < header.getPhysicalNumberOfCells(); i++) {
        HSSFCell cell = header.getCell(i);
        cell.setCellStyle(cellStyle);
    }
}

From source file:com.kcs.action.ForwardContractAction.java

@Override
@SuppressWarnings("empty-statement")
public String export() throws Exception {
    list = getService().findByCriteria(DateUtil.convertDateFromJsp(getDataSetDate()));

    getLogger().debug("exportExcel : begin...");
    setFileName("Forward contract Report.xls");
    DateFormat dateFormat = new SimpleDateFormat("dd MMM yyyy");
    HSSFWorkbook myWorkBook = new HSSFWorkbook();
    HSSFCellStyle style = myWorkBook.createCellStyle();
    HSSFCellStyle styleFont = myWorkBook.createCellStyle();
    HSSFFont fontB = myWorkBook.createFont();
    fontB.setBoldweight(Font.BOLDWEIGHT_BOLD);
    styleFont.setFont(fontB);/*w  ww  . j a  v a 2s  .  c o m*/

    list = sortSheet(list);
    List<String> listSheet = countSheet(list);

    for (int iListSheet = 0; iListSheet < listSheet.size(); iListSheet++) {
        List<ForwardContract> sheetObject = getSheetByAtSheet(list, listSheet.get(iListSheet));
        HSSFSheet FW1 = myWorkBook.createSheet(listSheet.get(iListSheet));
        List<String> currencyList = getCurrency(sheetObject);

        //------------------------- ROW 1 -----------------------------//
        Row FW1_row_0 = FW1.createRow(0);

        FW1_row_0.createCell(0).setCellValue(" FORWARD CONTRACT");
        CellUtil.setAlignment(FW1_row_0.getCell(0), myWorkBook, CellStyle.ALIGN_CENTER);

        HSSFCellStyle styleRow1 = myWorkBook.createCellStyle();

        styleRow1.setBorderRight(HSSFCellStyle.BORDER_THIN);
        styleRow1.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        styleRow1.setFont(fontB);

        FW1_row_0.getCell(0).setCellStyle(styleRow1);

        FW1_row_0.createCell(1)
                .setCellValue(" ? ?()");
        FW1_row_0.getCell(1).setCellStyle(styleRow1);

        // FW1_row_0.getCell(8).setCellStyle(styleFont);

        //------------------------- ROW 2 -----------------------------//
        Row FW1_row_1 = FW1.createRow(1);

        FW1_row_1.createCell(0).setCellValue("FW");
        //        FW1_row_1.getCell(0).setCellStyle(styleBR);

        //     FW1.addMergedRegion(new CellRangeAddress(1,1,7,8));

        FW1.autoSizeColumn(0);
        FW1.autoSizeColumn(7);
        FW1.autoSizeColumn(8);

        Row FW1_row_2 = FW1.createRow(2);
        FW1_row_2.createCell(0).setCellValue("?");
        //CellUtil.setAlignment(FW1_row_2.getCell(0), myWorkBook, CellStyle.ALIGN_RIGHT);
        HSSFCellStyle style2 = myWorkBook.createCellStyle();

        style2.setBorderRight(HSSFCellStyle.BORDER_THIN);
        style2.setAlignment(HSSFCellStyle.ALIGN_RIGHT);

        FW1_row_2.getCell(0).setCellStyle(style2);

        Row FW1_row_3 = FW1.createRow(3);
        FW1_row_3.createCell(0).setCellValue("?");

        HSSFCellStyle style3 = myWorkBook.createCellStyle();
        style3.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        style3.setBorderRight(HSSFCellStyle.BORDER_THIN);
        style3.setAlignment(HSSFCellStyle.ALIGN_LEFT);

        FW1_row_3.getCell(0).setCellStyle(style3);

        FW1.createRow(4).createCell(0).setCellValue("?");
        FW1.createRow(5).createCell(0).setCellValue("? (129027)");
        FW1.createRow(6).createCell(0).setCellValue(
                "???");
        FW1.createRow(7).createCell(0).setCellValue("  ?");
        FW1.createRow(8).createCell(0).setCellValue("  - ?? (129030)");
        FW1.createRow(9).createCell(0)
                .setCellValue("  - ??? (129031)");
        FW1.createRow(10).createCell(0).setCellValue("  ??");
        FW1.createRow(11).createCell(0).setCellValue("  ");
        FW1.createRow(12).createCell(0).setCellValue("  - ?? (129034)");
        FW1.createRow(13).createCell(0)
                .setCellValue("  - ??? (129035)");
        FW1.createRow(14).createCell(0).setCellValue("  ???");
        FW1.createRow(15).createCell(0).setCellValue("  - ?? (129037)");
        FW1.createRow(16).createCell(0)
                .setCellValue("  - ??? (129038) ");
        FW1.createRow(17).createCell(0)
                .setCellValue("  ?");
        FW1.createRow(18).createCell(0).setCellValue("  - ?? (129040)");
        FW1.createRow(19).createCell(0)
                .setCellValue("  - ??? (129041) ");
        FW1.createRow(20).createCell(0)
                .setCellValue("  ??");
        FW1.createRow(21).createCell(0).setCellValue("  - ?? (129043)");
        FW1.createRow(22).createCell(0)
                .setCellValue("  - ??? (129044)");
        FW1.createRow(23).createCell(0)
                .setCellValue("  ?");
        FW1.createRow(24).createCell(0).setCellValue("  - ?? (129046)");
        FW1.createRow(25).createCell(0)
                .setCellValue("  - ??? (129047) ");
        FW1.createRow(26).createCell(0).setCellValue("????");
        FW1.createRow(27).createCell(0).setCellValue("  ??");
        FW1.createRow(28).createCell(0).setCellValue("  - ?? (129050)");
        FW1.createRow(29).createCell(0)
                .setCellValue("  - ??? (129051)");
        FW1.createRow(30).createCell(0)
                .setCellValue("  ");
        FW1.createRow(31).createCell(0).setCellValue("  - ?? (129053)");
        FW1.createRow(32).createCell(0)
                .setCellValue("  - ??? (129054)");
        FW1.createRow(33).createCell(0).setCellValue("  ?  ");
        FW1.createRow(34).createCell(0).setCellValue("  - ?? (129056) ");
        FW1.createRow(35).createCell(0)
                .setCellValue("  - ??? (129057)  ");
        FW1.createRow(36).createCell(0).setCellValue("   ");
        FW1.createRow(37).createCell(0).setCellValue("  - ?? (129059) ");
        FW1.createRow(38).createCell(0)
                .setCellValue("  - ??? (129060)  ");
        FW1.createRow(39).createCell(0).setCellValue("? (129061) ");
        FW1.createRow(40).createCell(0)
                .setCellValue("? (129062) ");
        //    FW1.getRow(40).getCell(0).setCellStyle(styleBR);

        FW1.getRow(4).getCell(0).setCellStyle(styleFont);
        FW1.getRow(5).getCell(0).setCellStyle(styleFont);
        FW1.getRow(6).getCell(0).setCellStyle(styleFont);
        FW1.getRow(7).getCell(0).setCellStyle(styleFont);
        FW1.getRow(11).getCell(0).setCellStyle(styleFont);
        FW1.getRow(14).getCell(0).setCellStyle(styleFont);
        FW1.getRow(17).getCell(0).setCellStyle(styleFont);
        FW1.getRow(20).getCell(0).setCellStyle(styleFont);
        FW1.getRow(23).getCell(0).setCellStyle(styleFont);
        FW1.getRow(26).getCell(0).setCellStyle(styleFont);
        FW1.getRow(30).getCell(0).setCellStyle(styleFont);
        FW1.getRow(33).getCell(0).setCellStyle(styleFont);
        FW1.getRow(36).getCell(0).setCellStyle(styleFont);
        FW1.getRow(39).getCell(0).setCellStyle(styleFont);
        FW1.getRow(40).getCell(0).setCellStyle(styleFont);

        int cellCurrency = 1;

        for (int iCurrencyList = 0; iCurrencyList < currencyList.size(); iCurrencyList++) {

            style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
            style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
            style.setBorderRight(HSSFCellStyle.BORDER_THIN);

            String currencyName = currencyList.get(iCurrencyList);
            FW1_row_2.createCell(cellCurrency).setCellValue(currencyName);
            FW1_row_3.createCell(cellCurrency).setCellValue("");
            FW1_row_2.getCell(cellCurrency).setCellStyle(style);
            FW1_row_2.createCell(cellCurrency + 1).setCellStyle(style);

            FW1_row_3.getCell(cellCurrency).setCellStyle(style);

            List<ForwardContract> tmpGroupCCY = getGroupByCCY(sheetObject, currencyName);

            for (ForwardContract objCCY : tmpGroupCCY) {
                FW1.getRow(5).createCell(cellCurrency).setCellValue(objCCY.getSELL_AMT_129027() + "");

                if ("????"
                        .equals(objCCY.getTRANS_TYPE())) {
                    if ("New Forward".equals(objCCY.getLIST_ITEM().trim())) {
                        FW1.getRow(8).createCell(cellCurrency)
                                .setCellValue(convertNewForward(objCCY.getSELL_AMT_129029(), true));
                        FW1.getRow(12).createCell(cellCurrency)
                                .setCellValue(convertNewForward(objCCY.getSELL_AMT_129033(), true));
                        FW1.getRow(15).createCell(cellCurrency)
                                .setCellValue(convertNewForward(objCCY.getSELL_AMT_129036(), true));
                        FW1.getRow(18).createCell(cellCurrency)
                                .setCellValue(convertNewForward(objCCY.getSELL_AMT_129039(), true));
                        FW1.getRow(21).createCell(cellCurrency)
                                .setCellValue(convertNewForward(objCCY.getSELL_AMT_129042(), true));
                        FW1.getRow(24).createCell(cellCurrency)
                                .setCellValue(convertNewForward(objCCY.getSELL_AMT_129045(), true));

                        FW1.getRow(8).createCell(cellCurrency + 1)
                                .setCellValue(convertNewForward(objCCY.getBUY_AMT_129029(), true));
                        FW1.getRow(12).createCell(cellCurrency + 1)
                                .setCellValue(convertNewForward(objCCY.getBUY_AMT_129033(), true));
                        FW1.getRow(15).createCell(cellCurrency + 1)
                                .setCellValue(convertNewForward(objCCY.getBUY_AMT_129036(), true));
                        FW1.getRow(18).createCell(cellCurrency + 1)
                                .setCellValue(convertNewForward(objCCY.getBUY_AMT_129039(), true));
                        FW1.getRow(21).createCell(cellCurrency + 1)
                                .setCellValue(convertNewForward(objCCY.getBUY_AMT_129042(), true));
                        FW1.getRow(24).createCell(cellCurrency + 1)
                                .setCellValue(convertNewForward(objCCY.getBUY_AMT_129045(), true));
                    } else if ("Utilize Forward".equals(objCCY.getLIST_ITEM().trim())) {

                        FW1.getRow(9).createCell(cellCurrency)
                                .setCellValue(convertNewForward(objCCY.getSELL_AMT_129029(), false));
                        FW1.getRow(13).createCell(cellCurrency)
                                .setCellValue(convertNewForward(objCCY.getSELL_AMT_129033(), false));
                        FW1.getRow(16).createCell(cellCurrency)
                                .setCellValue(convertNewForward(objCCY.getSELL_AMT_129036(), false));
                        FW1.getRow(19).createCell(cellCurrency)
                                .setCellValue(convertNewForward(objCCY.getSELL_AMT_129039(), false));
                        FW1.getRow(22).createCell(cellCurrency)
                                .setCellValue(convertNewForward(objCCY.getSELL_AMT_129042(), false));
                        FW1.getRow(25).createCell(cellCurrency)
                                .setCellValue(convertNewForward(objCCY.getSELL_AMT_129045(), false));

                        FW1.getRow(9).createCell(cellCurrency + 1)
                                .setCellValue(convertNewForward(objCCY.getBUY_AMT_129029(), false));
                        FW1.getRow(13).createCell(cellCurrency + 1)
                                .setCellValue(convertNewForward(objCCY.getBUY_AMT_129033(), false));
                        FW1.getRow(16).createCell(cellCurrency + 1)
                                .setCellValue(convertNewForward(objCCY.getBUY_AMT_129036(), false));
                        FW1.getRow(19).createCell(cellCurrency + 1)
                                .setCellValue(convertNewForward(objCCY.getBUY_AMT_129039(), false));
                        FW1.getRow(22).createCell(cellCurrency + 1)
                                .setCellValue(convertNewForward(objCCY.getBUY_AMT_129042(), false));
                        FW1.getRow(25).createCell(cellCurrency + 1)
                                .setCellValue(convertNewForward(objCCY.getBUY_AMT_129045(), false));

                    }
                } else if ("????"
                        .equals(objCCY.getTRANS_TYPE().trim())) {
                    if ("New Forward".equals(objCCY.getLIST_ITEM())) {
                        FW1.getRow(28).createCell(cellCurrency)
                                .setCellValue(convertNewForward(objCCY.getSELL_AMT_129049(), true));
                        FW1.getRow(31).createCell(cellCurrency)
                                .setCellValue(convertNewForward(objCCY.getSELL_AMT_129052(), true));
                        FW1.getRow(34).createCell(cellCurrency)
                                .setCellValue(convertNewForward(objCCY.getSELL_AMT_129055(), true));
                        FW1.getRow(37).createCell(cellCurrency)
                                .setCellValue(convertNewForward(objCCY.getSELL_AMT_129058(), true));

                        FW1.getRow(28).createCell(cellCurrency + 1)
                                .setCellValue(convertNewForward(objCCY.getBUY_AMT_129049(), true));
                        FW1.getRow(31).createCell(cellCurrency + 1)
                                .setCellValue(convertNewForward(objCCY.getBUY_AMT_129052(), true));
                        FW1.getRow(34).createCell(cellCurrency + 1)
                                .setCellValue(convertNewForward(objCCY.getBUY_AMT_129055(), true));
                        FW1.getRow(37).createCell(cellCurrency + 1)
                                .setCellValue(convertNewForward(objCCY.getBUY_AMT_129058(), true));

                    } else if ("Utilize Forward".equals(objCCY.getLIST_ITEM().trim())) {

                        FW1.getRow(29).createCell(cellCurrency)
                                .setCellValue(convertNewForward(objCCY.getSELL_AMT_129049(), false));
                        FW1.getRow(32).createCell(cellCurrency)
                                .setCellValue(convertNewForward(objCCY.getSELL_AMT_129052(), false));
                        FW1.getRow(35).createCell(cellCurrency)
                                .setCellValue(convertNewForward(objCCY.getSELL_AMT_129055(), false));
                        FW1.getRow(38).createCell(cellCurrency)
                                .setCellValue(convertNewForward(objCCY.getSELL_AMT_129058(), false));

                        FW1.getRow(29).createCell(cellCurrency + 1)
                                .setCellValue(convertNewForward(objCCY.getBUY_AMT_129049(), false));
                        FW1.getRow(32).createCell(cellCurrency + 1)
                                .setCellValue(convertNewForward(objCCY.getBUY_AMT_129052(), false));
                        FW1.getRow(35).createCell(cellCurrency + 1)
                                .setCellValue(convertNewForward(objCCY.getBUY_AMT_129055(), false));
                        FW1.getRow(38).createCell(cellCurrency + 1)
                                .setCellValue(convertNewForward(objCCY.getBUY_AMT_129058(), false));

                    }
                } else if ("?".equals(objCCY.getTRANS_TYPE())) {

                }

                FW1.getRow(39).createCell(cellCurrency)
                        .setCellValue(convertNewForward(objCCY.getSELL_AMT_129061(), false));
                FW1.getRow(40).createCell(cellCurrency)
                        .setCellValue(convertNewForward(objCCY.getSELL_AMT_129062(), false));

                FW1.getRow(39).createCell(cellCurrency + 1)
                        .setCellValue(convertNewForward(objCCY.getBUY_AMT_129061(), false));
                FW1.getRow(40).createCell(cellCurrency + 1)
                        .setCellValue(convertNewForward(objCCY.getBUY_AMT_129062(), false));

            }
            //   
            // FW1.getRow(createRow++).createCell(cellCurrency).setCellValue(tmpGroup.getSELL_AMT_129033()+"");

            CellUtil.setAlignment(FW1_row_2.getCell(cellCurrency), myWorkBook, CellStyle.ALIGN_CENTER);
            FW1_row_2.getCell(cellCurrency).setCellStyle(style);
            FW1.addMergedRegion(new CellRangeAddress(2, 2, cellCurrency, ++cellCurrency));

            FW1_row_3.createCell(cellCurrency).setCellValue("");
            HSSFCellStyle styleTop = style;
            styleTop.setBorderTop(HSSFCellStyle.BORDER_THIN);
            FW1_row_3.getCell(cellCurrency).setCellStyle(styleTop);

            cellCurrency++;
        }
        System.out.println("cellCurrency ++++ " + cellCurrency);
        int finishM = cellCurrency - 3;

        int noOfColumns = FW1.getRow(2).getLastCellNum();
        int noOfRow = FW1.getLastRowNum();

        //          HSSFPalette palette = myWorkBook.getCustomPalette();
        //          HSSFColor hssfColor = null;
        //
        //
        //    palette.setColorAtIndex(HSSFColor.WHITE.index, (byte) 255, (byte) 255, (byte) 255);
        //    hssfColor = palette.getColor(HSSFColor.WHITE.index);
        //    
        //    
        //
        //    HSSFCellStyle styleBG = myWorkBook.createCellStyle();
        //    styleBG.setFillForegroundColor(hssfColor.getIndex());
        //    styleBG.setFillPattern(CellStyle.SOLID_FOREGROUND);  

        for (int i = 0; i < noOfRow; i++) {

            for (int j = 0; j < noOfColumns; j++) {
                FW1.autoSizeColumn(i);
                //  row.getCell(j).setCellStyle(styleBG);
            }
        }

        for (int i = 4; i < noOfRow + 1; i++) {

            for (int j = 1; j < noOfColumns; j++) {
                HSSFCellStyle style6 = myWorkBook.createCellStyle();
                try {

                    if (j == 1) {
                        style6.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                        style6.setBorderRight(HSSFCellStyle.BORDER_THIN);
                        style6.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                    } else {
                        style6.setBorderRight(HSSFCellStyle.BORDER_THIN);
                        style6.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                    }

                    if (i == noOfRow) {
                        style6.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                    }

                    FW1.getRow(i).getCell(j).setCellStyle(style6);
                } catch (Exception e) {

                    FW1.getRow(i).createCell(j).setCellStyle(style6);
                }
            }
        }

        HSSFFont fontBold = myWorkBook.createFont();
        fontBold.setBoldweight(Font.BOLDWEIGHT_BOLD);

        HSSFCellStyle borderRightCenterFontBold = myWorkBook.createCellStyle();

        borderRightCenterFontBold.setBorderRight(HSSFCellStyle.BORDER_THIN);
        borderRightCenterFontBold.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        borderRightCenterFontBold.setFont(fontBold);

        HSSFCellStyle borderRightBottomCenterFontBold = borderRightCenterFontBold;
        borderRightBottomCenterFontBold.setBorderBottom(HSSFCellStyle.BORDER_THIN);

        HSSFCellStyle styleR = myWorkBook.createCellStyle();
        styleR.setBorderRight(HSSFCellStyle.BORDER_THIN);

        //  Forward contract
        // FW1.getRow(0).getCell(0).setCellStyle(borderRightCenterFontBold);
        // FW1.getRow(0).getCell(1).setCellStyle(borderRightCenterFontBold);
        FW1.addMergedRegion(new CellRangeAddress(0, 1, 1, finishM));

        FW1_row_0.createCell(finishM + 1)
                .setCellValue(" " + dateFormat.format(new Date()) + "");

        HSSFCellStyle style4 = myWorkBook.createCellStyle();

        style4.setBorderRight(HSSFCellStyle.BORDER_THIN);
        style4.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        style4.setAlignment(HSSFCellStyle.ALIGN_LEFT);
        FW1_row_0.getCell(finishM + 1).setCellStyle(style4);
        FW1_row_0.getCell(finishM + 1).setCellStyle(styleFont);

        FW1.addMergedRegion(new CellRangeAddress(0, 0, finishM + 1, finishM + 2));
        FW1_row_1.createCell(finishM + 1).setCellValue(
                ":");

        FW1.addMergedRegion(new CellRangeAddress(1, 1, finishM + 1, finishM + 2));

        FW1_row_1.getCell(finishM + 1).setCellStyle(style4);
        FW1_row_1.getCell(finishM + 1).setCellStyle(styleFont);

        FW1_row_0.createCell(finishM + 2).setCellStyle(styleR);
        FW1_row_1.createCell(finishM + 2).setCellStyle(styleR);

        FW1.getRow(1).getCell(0).setCellStyle(borderRightCenterFontBold);
        //        FW1.getRow(1).getCell(1).setCellStyle(borderRightBottomCenterFontBold);
        HSSFCellStyle borderBottom = myWorkBook.createCellStyle();
        borderBottom.setBorderRight(HSSFCellStyle.BORDER_THIN);
        borderBottom.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        borderBottom.setAlignment(HSSFCellStyle.ALIGN_LEFT);
        borderBottom.setFont(fontBold);

        FW1.getRow(40).getCell(0).setCellStyle(borderBottom);

        HSSFPatriarch patriarch = (HSSFPatriarch) FW1.createDrawingPatriarch();

        /* Here is the thing: the line will go from top left in cell (0,0) to down left 
        of cell (0,1) */
        //  int dx1, int dy1, int dx2, int dy2, short col1, int row1, short col2, int row2)
        HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 255, (short) 0, 2, (short) 1, 3);

        HSSFSimpleShape shape = patriarch.createSimpleShape(anchor);
        shape.setShapeType(HSSFSimpleShape.OBJECT_TYPE_LINE);
        shape.setLineStyleColor(10, 10, 10);
        shape.setFillColor(90, 10, 200);
        shape.setLineWidth(HSSFShape.LINEWIDTH_ONE_PT);
        shape.setLineStyle(HSSFShape.LINESTYLE_SOLID);

        //  createFreezePane(int colSplit, int rowSplit, int leftmostColumn, int topRow);    
        //  FW1.createFreezePane(0,4);

    }

    ByteArrayOutputStream boas = new ByteArrayOutputStream();
    myWorkBook.write(boas);
    setExcelStream(new ByteArrayInputStream(boas.toByteArray()));

    getLogger().debug("exportExcel : end...");
    return "excel";
}

From source file:com.knowgate.misc.CSVParser.java

License:Open Source License

public void parseSheet(HSSFSheet oSheet, String sFileDescriptor) {
      HSSFCell oCel;// ww  w.ja va2 s.com
      HSSFRow oRow = oSheet.getRow(0);
      int iRow;
      char cDelim;
      SimpleDateFormat oFmt4 = new SimpleDateFormat("yyyy-MM-dd");
      String[] aFileDescriptor;
      int iFileDescLen;

      if (isVoid(sFileDescriptor)) {
          iRow = 1;
          cDelim = '\t';
          sFileDescriptor = "";
          short iCel = (short) 0;
          oCel = oRow.getCell(iCel);
          while (oCel != null) {
              if (isVoid(oCel.getStringCellValue()))
                  break;
              sFileDescriptor += (sFileDescriptor.length() == 0 ? "" : "\t") + oCel.getStringCellValue();
              oCel = oRow.getCell(++iCel);
          } // wend
          aFileDescriptor = Gadgets.split(sFileDescriptor, cDelim);
          iFileDescLen = aFileDescriptor.length;
      } else {
          iRow = 1;
          cDelim = extractDelimiter(sFileDescriptor);
          aFileDescriptor = Gadgets.split(sFileDescriptor, cDelim);
          iFileDescLen = aFileDescriptor.length;
          for (int c = 0; c < iFileDescLen; c++) {
              oCel = oRow.getCell(c);
              if (null == oCel) {
                  iRow = 0;
                  break;
              } else if (!aFileDescriptor[c].equalsIgnoreCase(oCel.getStringCellValue())) {
                  iRow = 0;
                  break;
              }
          } //next
      } // fi

      StringBuffer oData = new StringBuffer(1024 * 1024);
      while (!isEmptyRow(oSheet.getRow(iRow), iFileDescLen) && iRow <= 65535) {
          oRow = oSheet.getRow(iRow);
          if (oRow.getCell(0) != null)
              oData.append(oRow.getCell(0).getStringCellValue());
          for (int c = 1; c < iFileDescLen; c++) {
              oData.append(cDelim);
              if (oRow.getCell(c) != null) {
                  int iCelType = oRow.getCell(c).getCellType();
                  switch (iCelType) {
                  case HSSFCell.CELL_TYPE_BLANK:
                      break;
                  case HSSFCell.CELL_TYPE_STRING:
                      oData.append(oRow.getCell(c).getStringCellValue().replace(cDelim, ' ').replace('\n', ' '));
                      break;
                  case HSSFCell.CELL_TYPE_NUMERIC:
                      switch (oRow.getCell(c).getCellStyle().getDataFormat()) {
                      case (short) 15: // m/d/yy
                      case (short) 16: // d-mmm-yy
                          oData.append(oFmt4.format(oRow.getCell(c).getDateCellValue()));
                          break;
                      default:
                          oData.append(String.valueOf(oRow.getCell(c).getNumericCellValue()));
                      }
                      break;
                  } // end switch                  
              } // fi 
          } // next
          oData.append('\n');
          iRow++;
      } // wend
      parseData(oData.toString().toCharArray(), sFileDescriptor);
  }

From source file:com.krawler.esp.fileparser.excel.MsExcelParser.java

License:Open Source License

public String extractText(String filepath) throws Exception {

    InputStream input = new BufferedInputStream(new FileInputStream(filepath));
    String resultText = "";
    HSSFWorkbook wb = new HSSFWorkbook(input);
    if (wb == null) {
        return resultText;
    }/*www . jav a  2  s.c  o m*/

    HSSFSheet sheet;
    HSSFRow row;
    HSSFCell cell;
    int sNum = 0;
    int rNum = 0;
    int cNum = 0;

    sNum = wb.getNumberOfSheets();

    for (int i = 0; i < sNum; i++) {
        if ((sheet = wb.getSheetAt(i)) == null) {
            continue;
        }
        rNum = sheet.getLastRowNum();

        for (int j = 0; j <= rNum; j++) {
            if ((row = sheet.getRow(j)) == null) {
                continue;
            }
            cNum = row.getLastCellNum();

            for (int k = 0; k < cNum; k++) {
                try {
                    if ((cell = row.getCell((short) k)) != null) {
                        /*
                         * if(HSSFDateUtil.isCellDateFormatted(cell) ==
                         * true) { resultText +=
                         * cell.getDateCellValue().toString() + " "; } else
                         */
                        if (cell.getCellType() == HSSFCell.CELL_TYPE_BLANK) {
                            resultText += "           ";

                        } else if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
                            resultText += cell.getRichStringCellValue().toString() + " ";
                        } else if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
                            Double d = new Double(cell.getNumericCellValue());
                            resultText += d.toString() + " ";
                        }

                        /*
                         * else if(cell.getCellType() ==
                         * HSSFCell.CELL_TYPE_FORMULA){ resultText +=
                         * cell.getCellFormula() + " "; }
                         */
                    }
                } catch (Exception ex) {

                }
            }
            resultText += "\n";
        }
    }
    if (input != null) {
        input.close();
    }
    return resultText;
}

From source file:com.krawler.esp.fileparser.excel.MsExcelParser.java

License:Open Source License

public String getFormatedJSON(String filepath) throws Exception {
    InputStream input = new BufferedInputStream(new FileInputStream(filepath));
    JSONObject jobj = new JSONObject();
    HSSFWorkbook wb = new HSSFWorkbook(input);
    if (wb == null) {
        return ("\"data\":[]");
    }/*from w ww.  j  av a  2 s .co m*/
    HSSFSheet sheet;
    HSSFRow row;
    HSSFCell cell;
    int sNum = 0;
    int rNum = 0;
    int cNum = 0;

    sNum = wb.getNumberOfSheets();

    for (int i = 0; i < sNum; i++) {
        if ((sheet = wb.getSheetAt(i)) == null) {
            continue;
        }
        rNum = sheet.getLastRowNum();

        for (int j = 0; j <= rNum; j++) {
            if ((row = sheet.getRow(j)) == null) {
                continue;
            }
            cNum = row.getLastCellNum();
            JSONObject temp = new JSONObject();
            for (int k = 0; k < cNum; k++) {
                try {
                    if ((cell = row.getCell((short) k)) != null) {

                        if (cell.getCellType() == HSSFCell.CELL_TYPE_BLANK) {
                            temp.put("cell" + cell.getCellNum(), "");

                        } else if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
                            temp.put("cell" + cell.getCellNum(), cell.getRichStringCellValue().toString());
                        } else if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
                            Double d = new Double(cell.getNumericCellValue());
                            temp.put("cell" + cell.getCellNum(), d.toString());
                        }
                    }

                } catch (Exception ex) {

                }
            }
            jobj.append("data", temp);
            temp = null;
        }
    }
    if (input != null) {
        input.close();
    }
    return jobj.toString();
}