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

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

Introduction

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

Prototype

@Override
public HSSFCellStyle createCellStyle() 

Source Link

Document

Create a new Cell style and add it to the workbook's style table.

Usage

From source file:com.ibm.ioes.utilities.MailForDisConnectProvisioning.java

public HSSFWorkbook generateExcel_ACS(ArrayList<ACSMailTemplateDto> mailDataList) {
    HSSFWorkbook wb = null;
    try {/*from   w  w  w .j  av a  2s.co  m*/
        ACSMailTemplateDto mailObjDto = null;
        wb = new HSSFWorkbook();
        HSSFSheet mailProvisionSheet = wb.createSheet("Mail Disconnect");
        HSSFCellStyle headerCellStyle = wb.createCellStyle();
        HSSFFont boldFont = wb.createFont();
        boldFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        headerCellStyle.setFont(boldFont);

        HSSFRow excelRow = null;
        HSSFCell excelCell = null;

        excelRow = mailProvisionSheet.createRow(0);
        excelRow = mailProvisionSheet.createRow(0);

        int i_cell = 0;

        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Date of Creation"));
        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Quote No./ISS Order No."));

        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Region"));

        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Parent A/C ID(Billed)"));

        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Child ID (Unbilled)"));

        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Premium ACS ID"));

        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Type of ID"));
        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Customer Name"));
        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Address"));
        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("City State"));
        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Pin"));
        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Moderator Name"));
        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Designation"));
        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Email"));
        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Phone No."));
        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Contact Person"));
        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Designation"));
        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Email"));

        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Phone No."));

        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Account Manager Name"));

        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Designation"));

        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Email ID/ Phone No"));

        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Web Conf (Y/N)"));

        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Web Conf Rental"));

        int iCount = 1;
        for (int i = 0; i < mailDataList.size(); i++) {
            mailObjDto = mailDataList.get(i);
            excelRow = mailProvisionSheet.createRow(iCount++);

            i_cell = 0;

            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(
                    new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getDateOfCreation())));
            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getOrderNo())));

            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getRegion())));

            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getParentId())));

            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getChildId())));

            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getAcsId())));
            /*excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue( new HSSFRichTextString(""+Utility.fnCheckNull(mailObjDto.getServiceType()));*/
            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getTypeOfId())));
            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(
                    new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getCustomerName())));
            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getAddress())));
            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getCity())));
            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getPinNo())));
            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(
                    new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getChairPersonName())));
            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(
                    new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getChairPersonDesignation())));
            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(
                    new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getChairPersonEmailId())));
            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(
                    new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getChairPersonPhoneNo())));
            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getBcpName())));
            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(
                    new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getBcpDesignation())));
            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getBcpEmail())));
            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getBcpPhone())));
            excelCell = excelRow.createCell(i_cell++);
            excelCell
                    .setCellValue(new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getAccMgrName())));
            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(
                    new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getAccMgrDesignation())));
            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getAccMgrphone())
                    + "/" + Utility.fnCheckNull(mailObjDto.getAccMgrEmailId())));
            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getWebConf())));
            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(
                    new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getWebConfRental())));
        }
    } catch (Exception ex) {
        Utility.LOG(true, true, "Error while fetching accounts for provisiong : " + new Date());
    }
    return wb;
}

From source file:com.ibm.ioes.utilities.MailForDisConnectProvisioning.java

public HSSFWorkbook generateExcel_VCS(ArrayList<ACSMailTemplateDto> mailDataList, String mailProvisioningFlag) {
    HSSFWorkbook wb = null;
    try {//from   w  w w. j  a v a 2 s .c om
        ACSMailTemplateDto mailObjDto = null;
        wb = new HSSFWorkbook();
        HSSFSheet mailProvisionSheet = wb.createSheet("Mail Disconnect");
        HSSFCellStyle headerCellStyle = wb.createCellStyle();
        HSSFFont boldFont = wb.createFont();
        boldFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        headerCellStyle.setFont(boldFont);

        HSSFRow excelRow = null;
        HSSFCell excelCell = null;

        excelRow = mailProvisionSheet.createRow(0);
        excelRow = mailProvisionSheet.createRow(0);

        excelCell = excelRow.createCell(0);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Date of Creation"));
        excelCell = excelRow.createCell(1);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Account name"));
        excelCell = excelRow.createCell(2);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("ISS Order no"));
        excelCell = excelRow.createCell(3);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Product"));
        excelCell = excelRow.createCell(4);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Parent ID"));
        excelCell = excelRow.createCell(5);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Child ID"));
        excelCell = excelRow.createCell(6);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("VCS ID"));
        excelCell = excelRow.createCell(7);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Bundled VCS plan"));
        excelCell = excelRow.createCell(8);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Chairperson Name"));
        excelCell = excelRow.createCell(9);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Billing Person Name"));
        excelCell = excelRow.createCell(10);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Billing Address"));
        excelCell = excelRow.createCell(11);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("ID/HW address"));
        excelCell = excelRow.createCell(12);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Status"));

        int iCount = 1;
        for (int i = 0; i < mailDataList.size(); i++) {
            mailObjDto = mailDataList.get(i);
            excelRow = mailProvisionSheet.createRow(iCount++);
            excelCell = excelRow.createCell(0);
            excelCell.setCellValue(
                    new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getDateOfCreation())));
            excelCell = excelRow.createCell(1);
            excelCell.setCellValue(
                    new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getAccountName())));
            excelCell = excelRow.createCell(2);
            excelCell.setCellValue(new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getOrderNo())));
            excelCell = excelRow.createCell(3);
            excelCell.setCellValue(
                    new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getProductName())));
            excelCell = excelRow.createCell(4);
            excelCell.setCellValue(new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getParentId())));
            excelCell = excelRow.createCell(5);
            excelCell.setCellValue(new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getChildId())));
            excelCell = excelRow.createCell(6);
            excelCell
                    .setCellValue(new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getMultipleId())));
            excelCell = excelRow.createCell(7);
            excelCell.setCellValue(
                    new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getPackageName())));
            excelCell = excelRow.createCell(8);
            excelCell.setCellValue(
                    new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getChairPersonName())));
            excelCell = excelRow.createCell(9);
            excelCell.setCellValue(new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getBcpName())));
            excelCell = excelRow.createCell(10);
            excelCell.setCellValue(
                    new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getBillingAddress())));
            excelCell = excelRow.createCell(11);
            excelCell.setCellValue(new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getHwAddress())));
            excelCell = excelRow.createCell(12);
            excelCell.setCellValue(new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getStatus())));

        }
    } catch (Exception ex) {
        Utility.LOG(true, true, "Error while fetching accounts for provisiong : " + new Date());
    }
    return wb;
}

From source file:com.ibm.ioes.utilities.MailForProvisioning.java

public HSSFWorkbook generateExcel(ArrayList<ACSMailTemplateDto> mailDataList) {
    HSSFWorkbook wb = null;
    try {/*from   www .j a va 2 s  .c  o m*/
        ACSMailTemplateDto mailObjDto = null;
        wb = new HSSFWorkbook();
        HSSFSheet mailProvisionSheet = wb.createSheet("Mail Provision");
        HSSFCellStyle headerCellStyle = wb.createCellStyle();
        HSSFFont boldFont = wb.createFont();
        boldFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        headerCellStyle.setFont(boldFont);

        HSSFRow excelRow = null;
        HSSFCell excelCell = null;

        excelRow = mailProvisionSheet.createRow(0);
        excelRow = mailProvisionSheet.createRow(0);

        int i_cell = 0;

        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Date of Creation"));
        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Quote No./ISS Order No."));

        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Region"));

        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Parent A/C ID(Billed)"));

        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Child ID (Unbilled)"));

        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Premium ACS ID"));

        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Type of ID"));
        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Customer Name"));
        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Address"));
        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("City State"));
        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Pin"));
        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Moderator Name"));
        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Designation"));
        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Email"));
        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Phone No."));
        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Contact Person"));
        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Designation"));
        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Email"));

        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Phone No."));

        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Account Manager Name"));

        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Designation"));

        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Email ID/ Phone No"));

        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Web Conf (Y/N)"));

        excelCell = excelRow.createCell(i_cell++);
        excelCell.setCellStyle(headerCellStyle);
        excelCell.setCellValue(new HSSFRichTextString("Web Conf Rental"));

        int iCount = 1;
        for (int i = 0; i < mailDataList.size(); i++) {
            mailObjDto = mailDataList.get(i);
            excelRow = mailProvisionSheet.createRow(iCount++);

            i_cell = 0;

            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(
                    new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getDateOfCreation())));
            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getOrderNo())));

            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getRegion())));

            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getParentId())));

            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getChildId())));

            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getAcsId())));
            /*excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue( new HSSFRichTextString(""+Utility.fnCheckNull(mailObjDto.getServiceType()));*/
            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getTypeOfId())));
            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(
                    new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getCustomerName())));
            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getAddress())));
            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getCity())));
            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getPinNo())));
            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(
                    new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getChairPersonName())));
            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(
                    new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getChairPersonDesignation())));
            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(
                    new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getChairPersonEmailId())));
            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(
                    new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getChairPersonPhoneNo())));
            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getBcpName())));
            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(
                    new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getBcpDesignation())));
            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getBcpEmail())));
            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getBcpPhone())));
            excelCell = excelRow.createCell(i_cell++);
            excelCell
                    .setCellValue(new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getAccMgrName())));
            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(
                    new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getAccMgrDesignation())));
            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getAccMgrphone())
                    + "/" + Utility.fnCheckNull(mailObjDto.getAccMgrEmailId())));
            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getWebConf())));
            excelCell = excelRow.createCell(i_cell++);
            excelCell.setCellValue(
                    new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getWebConfRental())));
        }
    } catch (Exception ex) {
        Utility.LOG(true, true, "Error while fetching accounts for provisiong : " + new Date());
    }
    return wb;
}

From source file:com.ibm.ioes.utilities.MailForProvisioning.java

public HSSFWorkbook generateExcel_Multiple(ArrayList<ACSMailTemplateDto> mailDataList,
        String mailProvisioningFlag) {
    HSSFWorkbook wb = null;
    try {/* w ww  .ja v a2 s. c  o m*/
        ACSMailTemplateDto mailObjDto = null;
        wb = new HSSFWorkbook();
        HSSFSheet mailProvisionSheet = wb.createSheet("Mail Provision");
        HSSFCellStyle headerCellStyle = wb.createCellStyle();
        HSSFFont boldFont = wb.createFont();
        boldFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        headerCellStyle.setFont(boldFont);

        HSSFRow excelRow = null;
        HSSFCell excelCell = null;

        excelRow = mailProvisionSheet.createRow(0);
        excelRow = mailProvisionSheet.createRow(0);

        if ("PROVISIONING_MAIL_OVCC".equals(mailProvisioningFlag)) {
            excelCell = excelRow.createCell(0);
            excelCell.setCellStyle(headerCellStyle);
            excelCell.setCellValue(new HSSFRichTextString("Date of Creation"));
            excelCell = excelRow.createCell(1);
            excelCell.setCellStyle(headerCellStyle);
            excelCell.setCellValue(new HSSFRichTextString("Account name"));
            excelCell = excelRow.createCell(2);
            excelCell.setCellStyle(headerCellStyle);
            excelCell.setCellValue(new HSSFRichTextString("ISS Order no"));
            excelCell = excelRow.createCell(3);
            excelCell.setCellStyle(headerCellStyle);
            excelCell.setCellValue(new HSSFRichTextString("Product"));
            excelCell = excelRow.createCell(4);
            excelCell.setCellStyle(headerCellStyle);
            excelCell.setCellValue(new HSSFRichTextString("Parent ID"));
            excelCell = excelRow.createCell(5);
            excelCell.setCellStyle(headerCellStyle);
            excelCell.setCellValue(new HSSFRichTextString("Child ID"));
            excelCell = excelRow.createCell(6);
            excelCell.setCellStyle(headerCellStyle);
            excelCell.setCellValue(new HSSFRichTextString("OVCC ID"));
            excelCell = excelRow.createCell(7);
            excelCell.setCellStyle(headerCellStyle);
            excelCell.setCellValue(new HSSFRichTextString("Bundled OVCC plan"));
            excelCell = excelRow.createCell(8);
            excelCell.setCellStyle(headerCellStyle);
            excelCell.setCellValue(new HSSFRichTextString("Chairperson Name"));
            excelCell = excelRow.createCell(9);
            excelCell.setCellStyle(headerCellStyle);
            excelCell.setCellValue(new HSSFRichTextString("Billing Person Name"));
            excelCell = excelRow.createCell(10);
            excelCell.setCellStyle(headerCellStyle);
            excelCell.setCellValue(new HSSFRichTextString("Billing Address"));
            excelCell = excelRow.createCell(11);
            excelCell.setCellStyle(headerCellStyle);
            excelCell.setCellValue(new HSSFRichTextString("Status"));
        } else {
            excelCell = excelRow.createCell(0);
            excelCell.setCellStyle(headerCellStyle);
            excelCell.setCellValue(new HSSFRichTextString("Date of Creation"));
            excelCell = excelRow.createCell(1);
            excelCell.setCellStyle(headerCellStyle);
            excelCell.setCellValue(new HSSFRichTextString("Account name"));
            excelCell = excelRow.createCell(2);
            excelCell.setCellStyle(headerCellStyle);
            excelCell.setCellValue(new HSSFRichTextString("ISS Order no"));
            excelCell = excelRow.createCell(3);
            excelCell.setCellStyle(headerCellStyle);
            excelCell.setCellValue(new HSSFRichTextString("Product"));
            excelCell = excelRow.createCell(4);
            excelCell.setCellStyle(headerCellStyle);
            excelCell.setCellValue(new HSSFRichTextString("Parent ID"));
            excelCell = excelRow.createCell(5);
            excelCell.setCellStyle(headerCellStyle);
            excelCell.setCellValue(new HSSFRichTextString("Child ID"));
            excelCell = excelRow.createCell(6);
            excelCell.setCellStyle(headerCellStyle);
            excelCell.setCellValue(new HSSFRichTextString("VCS ID"));
            excelCell = excelRow.createCell(7);
            excelCell.setCellStyle(headerCellStyle);
            excelCell.setCellValue(new HSSFRichTextString("Bundled VCS plan"));
            excelCell = excelRow.createCell(8);
            excelCell.setCellStyle(headerCellStyle);
            excelCell.setCellValue(new HSSFRichTextString("Chairperson Name"));
            excelCell = excelRow.createCell(9);
            excelCell.setCellStyle(headerCellStyle);
            excelCell.setCellValue(new HSSFRichTextString("Billing Person Name"));
            excelCell = excelRow.createCell(10);
            excelCell.setCellStyle(headerCellStyle);
            excelCell.setCellValue(new HSSFRichTextString("Billing Address"));
            excelCell = excelRow.createCell(11);
            excelCell.setCellStyle(headerCellStyle);
            excelCell.setCellValue(new HSSFRichTextString("ID/HW address"));
            excelCell = excelRow.createCell(12);
            excelCell.setCellStyle(headerCellStyle);
            excelCell.setCellValue(new HSSFRichTextString("Status"));
        }

        int iCount = 1;
        for (int i = 0; i < mailDataList.size(); i++) {
            mailObjDto = mailDataList.get(i);
            excelRow = mailProvisionSheet.createRow(iCount++);
            if ("PROVISIONING_MAIL_OVCC".equals(mailProvisioningFlag)) {
                excelCell = excelRow.createCell(0);
                excelCell.setCellValue(
                        new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getDateOfCreation())));
                excelCell = excelRow.createCell(1);
                excelCell.setCellValue(
                        new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getAccountName())));
                excelCell = excelRow.createCell(2);
                excelCell.setCellValue(
                        new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getOrderNo())));
                excelCell = excelRow.createCell(3);
                excelCell.setCellValue(
                        new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getProductName())));
                excelCell = excelRow.createCell(4);
                excelCell.setCellValue(
                        new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getParentId())));
                excelCell = excelRow.createCell(5);
                excelCell.setCellValue(
                        new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getChildId())));
                excelCell = excelRow.createCell(6);
                excelCell.setCellValue(
                        new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getMultipleId())));
                excelCell = excelRow.createCell(7);
                excelCell.setCellValue(
                        new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getPackageName())));
                excelCell = excelRow.createCell(8);
                excelCell.setCellValue(
                        new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getChairPersonName())));
                excelCell = excelRow.createCell(9);
                excelCell.setCellValue(
                        new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getBcpName())));
                excelCell = excelRow.createCell(10);
                excelCell.setCellValue(
                        new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getBillingAddress())));
                excelCell = excelRow.createCell(11);
                excelCell
                        .setCellValue(new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getStatus())));
            } else {
                excelCell = excelRow.createCell(0);
                excelCell.setCellValue(
                        new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getDateOfCreation())));
                excelCell = excelRow.createCell(1);
                excelCell.setCellValue(
                        new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getAccountName())));
                excelCell = excelRow.createCell(2);
                excelCell.setCellValue(
                        new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getOrderNo())));
                excelCell = excelRow.createCell(3);
                excelCell.setCellValue(
                        new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getProductName())));
                excelCell = excelRow.createCell(4);
                excelCell.setCellValue(
                        new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getParentId())));
                excelCell = excelRow.createCell(5);
                excelCell.setCellValue(
                        new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getChildId())));
                excelCell = excelRow.createCell(6);
                excelCell.setCellValue(
                        new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getMultipleId())));
                excelCell = excelRow.createCell(7);
                excelCell.setCellValue(
                        new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getPackageName())));
                excelCell = excelRow.createCell(8);
                excelCell.setCellValue(
                        new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getChairPersonName())));
                excelCell = excelRow.createCell(9);
                excelCell.setCellValue(
                        new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getBcpName())));
                excelCell = excelRow.createCell(10);
                excelCell.setCellValue(
                        new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getBillingAddress())));
                excelCell = excelRow.createCell(11);
                excelCell.setCellValue(
                        new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getHwAddress())));
                excelCell = excelRow.createCell(12);
                excelCell
                        .setCellValue(new HSSFRichTextString("" + Utility.fnCheckNull(mailObjDto.getStatus())));
            }
        }
    } catch (Exception ex) {
        Utility.LOG(true, true, "Error while fetching accounts for provisiong : " + new Date());
    }
    return wb;
}

From source file:com.ideaspymes.arthyweb.ventas.web.controllers.VentasCantadasBean.java

public void generarExcelVentasCantadas() throws IOException {

    cargaResumen();//from  ww  w  .j a v a2 s  .c om

    if (ventasCantadas == null || ventasCantadas.isEmpty()) {
        JsfUtil.addErrorMessage("No hay datos para generar");
    } else {
        Map<String, List<ResumenVentasCantadas>> map2 = new HashMap<>();

        for (ResumenVentasCantadas rc : ventasCantadas) {
            List<ResumenVentasCantadas> valueList = map2.get(rc.getTerritorio());
            if (valueList == null) {
                valueList = new ArrayList<>();
                valueList.add(rc);
                map2.put(rc.getTerritorio(), valueList);
            } else {
                valueList.add(rc);
            }
        }

        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = workbook.createSheet("Ventas Detalle");

        configAnchoCols(sheet);

        //Fonts
        Font fontSubTitulo = workbook.createFont();
        fontSubTitulo.setFontHeightInPoints((short) 8);
        fontSubTitulo.setBoldweight(Font.BOLDWEIGHT_BOLD);

        //Fonts
        Font fontTotal3 = workbook.createFont();
        fontTotal3.setFontHeightInPoints((short) 8);
        fontTotal3.setColor(HSSFColor.RED.index);
        fontTotal3.setBoldweight(Font.BOLDWEIGHT_BOLD);

        //Fonts
        Font fontTerritorioTotal3 = workbook.createFont();
        fontTerritorioTotal3.setFontHeightInPoints((short) 8);
        fontTerritorioTotal3.setColor(HSSFColor.ORANGE.index);
        fontTerritorioTotal3.setBoldweight(Font.BOLDWEIGHT_BOLD);

        //Estilos
        DataFormat format = workbook.createDataFormat();
        CellStyle styleTotal3 = workbook.createCellStyle();

        styleTotal3.setFont(fontTotal3);
        styleTotal3.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
        styleTotal3.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
        styleTotal3.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
        styleTotal3.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);
        styleTotal3.setDataFormat(format.getFormat("0.0%"));

        styleTerritorioTotal3 = workbook.createCellStyle();
        styleTerritorioTotal3.setFont(fontTerritorioTotal3);
        styleTerritorioTotal3.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
        styleTerritorioTotal3.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
        // styleTerritorioTotal3.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
        // styleTerritorioTotal3.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);

        creaCabecera(workbook, sheet);

        String[] aCols20 = null;
        String[] aCols10 = null;
        String[] aColsGrue = null;
        String indicesTotales = "";

        for (Map.Entry<String, List<ResumenVentasCantadas>> entry : map2.entrySet()) {
            ++indexRow;

            HSSFRow row = sheet.createRow((++indexRow));

            HSSFCell cellTerr = row.createCell(indexCol);
            cellTerr.setCellValue(entry.getKey().toUpperCase());
            cellTerr.setCellStyle(styleTerritorio);

            int indexInicioGrupo = indexRow + 2;

            List<ResumenVentasCantadas> detalles = entry.getValue();

            Comparator<ResumenVentasCantadas> comp = new Comparator<ResumenVentasCantadas>() {

                @Override
                public int compare(ResumenVentasCantadas o1, ResumenVentasCantadas o2) {
                    return o1.getOrden() > o2.getOrden() ? 1 : -1;
                }
            };

            Collections.sort(detalles, comp);

            for (ResumenVentasCantadas rv : detalles) {
                cols20 = "";
                cols10 = "";
                colsGrue = "";

                int indexFilaActual = ++indexRow;
                HSSFRow row1 = sheet.createRow((indexFilaActual));

                HSSFCell cellZona = row1.createCell(indexCol + 0);
                cellZona.setCellValue(rv.getZona());
                cellZona.setCellStyle(styleTitulo9);

                HSSFCell cellVendedor = row1.createCell(indexCol + 1);
                cellVendedor.setCellValue(rv.getVendedor());
                cellVendedor.setCellStyle(styleTitulo9);

                HSSFCell cellBoletas = row1.createCell(indexCol + 2);
                cellBoletas.setCellValue(rv.getCantboletas());
                cellBoletas.setCellStyle(styleCantidad);

                generarDetalles(row1, indexFilaActual, rv);

            }

            int indexFinGrupo = indexRow + 1;

            int indexTotal1 = ++indexRow;
            int indexTotal2 = ++indexRow;
            int indexTotal3 = ++indexRow;

            HSSFRow rowTotal1 = sheet.createRow(indexTotal1);
            HSSFRow rowTotal2 = sheet.createRow((indexTotal2));
            HSSFRow rowTotal3 = sheet.createRow((indexTotal3));

            aCols20 = cols20.split(",");
            aCols10 = cols10.split(",");
            aColsGrue = colsGrue.split(",");

            //TOTAL 1
            generarTotal1(rowTotal1, indexInicioGrupo, indexFinGrupo, aColsGrue, aCols20, aCols10, cellTerr);
            //TOTAL 2
            generarTotal2(rowTotal2, indexFinGrupo, aColsGrue, cellTerr);
            //TOTAL 3
            generarTotal3(rowTotal3, indexFinGrupo, styleTotal3, cellTerr, sheet);
            //++indexRow;

            indicesTotales += (indexFinGrupo + 1) + ",";
        }

        String[] aIndexTotales = indicesTotales.split(",");

        //TOTAL pais
        int indexTotalPais = ++indexRow;
        HSSFRow rowTotalPais = sheet.createRow((indexTotalPais));
        generarTotalPais(rowTotalPais, styleTotal3, sheet, aIndexTotales, aColsGrue, aCols20, aCols10);

        HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance()
                .getExternalContext().getResponse();

        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-Disposition", "attachment; filename=Ventas Cantadas.xls");
        workbook.write(response.getOutputStream());
        response.getOutputStream().flush();
        response.getOutputStream().close();
        FacesContext.getCurrentInstance().responseComplete();
        indexRow = 1;
    }

}

From source file:com.ideaspymes.arthyweb.ventas.web.controllers.VentasCantadasBean.java

public void generarExcelVentasCantadasDetalle() throws IOException {

    cargaResumenPorVendedor();//from   ww w  . j  a va 2s  . c  om

    if (ventasCantadas == null || ventasCantadas.isEmpty()) {
        JsfUtil.addErrorMessage("No hay datos para generar");
    } else {
        Map<String, List<ResumenVentasCantadas>> map2 = new HashMap<>();

        for (ResumenVentasCantadas rc : ventasCantadas) {
            List<ResumenVentasCantadas> valueList = map2.get(rc.getTerritorio());
            if (valueList == null) {
                valueList = new ArrayList<>();
                valueList.add(rc);
                map2.put(rc.getTerritorio(), valueList);
            } else {
                valueList.add(rc);
            }
        }

        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = workbook.createSheet("Ventas Detalle");

        configAnchoCols(sheet);

        //Fonts
        Font fontSubTitulo = workbook.createFont();
        fontSubTitulo.setFontHeightInPoints((short) 8);
        fontSubTitulo.setBoldweight(Font.BOLDWEIGHT_BOLD);

        //Fonts
        Font fontTotal3 = workbook.createFont();
        fontTotal3.setFontHeightInPoints((short) 8);
        fontTotal3.setColor(HSSFColor.RED.index);
        fontTotal3.setBoldweight(Font.BOLDWEIGHT_BOLD);

        //Fonts
        Font fontTerritorioTotal3 = workbook.createFont();
        fontTerritorioTotal3.setFontHeightInPoints((short) 8);
        fontTerritorioTotal3.setColor(HSSFColor.ORANGE.index);
        fontTerritorioTotal3.setBoldweight(Font.BOLDWEIGHT_BOLD);

        //Estilos
        DataFormat format = workbook.createDataFormat();
        CellStyle styleTotal3 = workbook.createCellStyle();

        styleTotal3.setFont(fontTotal3);
        styleTotal3.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
        styleTotal3.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
        styleTotal3.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
        styleTotal3.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);
        styleTotal3.setDataFormat(format.getFormat("0.0%"));

        styleTerritorioTotal3 = workbook.createCellStyle();
        styleTerritorioTotal3.setFont(fontTerritorioTotal3);
        styleTerritorioTotal3.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
        styleTerritorioTotal3.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
        // styleTerritorioTotal3.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
        // styleTerritorioTotal3.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);

        creaCabecera(workbook, sheet);

        String[] aCols20 = null;
        String[] aCols10 = null;
        String[] aColsGrue = null;
        String indicesTotales = "";

        for (Map.Entry<String, List<ResumenVentasCantadas>> entry : map2.entrySet()) {
            ++indexRow;

            HSSFRow row = sheet.createRow((++indexRow));

            HSSFCell cellTerr = row.createCell(indexCol);
            cellTerr.setCellValue(entry.getKey().toUpperCase());
            cellTerr.setCellStyle(styleTerritorio);

            int indexInicioGrupo = indexRow + 2;

            List<ResumenVentasCantadas> detalles = entry.getValue();

            Comparator<ResumenVentasCantadas> comp = new Comparator<ResumenVentasCantadas>() {

                @Override
                public int compare(ResumenVentasCantadas o1, ResumenVentasCantadas o2) {
                    return o1.getOrden() > o2.getOrden() ? 1 : -1;
                }
            };

            Collections.sort(detalles, comp);

            for (ResumenVentasCantadas rv : detalles) {
                cols20 = "";
                cols10 = "";
                colsGrue = "";

                int indexFilaActual = ++indexRow;
                HSSFRow row1 = sheet.createRow((indexFilaActual));

                HSSFCell cellZona = row1.createCell(indexCol + 0);
                cellZona.setCellValue(rv.getZona());
                cellZona.setCellStyle(styleTitulo9);

                HSSFCell cellVendedor = row1.createCell(indexCol + 1);
                cellVendedor.setCellValue(rv.getVendedor());
                cellVendedor.setCellStyle(styleTitulo9);

                HSSFCell cellBoletas = row1.createCell(indexCol + 2);
                cellBoletas.setCellValue(rv.getCantboletas());
                cellBoletas.setCellStyle(styleCantidad);

                generarDetalles(row1, indexFilaActual, rv);

            }

            int indexFinGrupo = indexRow + 1;

            int indexTotal1 = ++indexRow;
            int indexTotal2 = ++indexRow;
            int indexTotal3 = ++indexRow;

            HSSFRow rowTotal1 = sheet.createRow(indexTotal1);
            HSSFRow rowTotal2 = sheet.createRow((indexTotal2));
            HSSFRow rowTotal3 = sheet.createRow((indexTotal3));

            aCols20 = cols20.split(",");
            aCols10 = cols10.split(",");
            aColsGrue = colsGrue.split(",");

            //TOTAL 1
            generarTotal1(rowTotal1, indexInicioGrupo, indexFinGrupo, aColsGrue, aCols20, aCols10, cellTerr);
            //TOTAL 2
            generarTotal2(rowTotal2, indexFinGrupo, aColsGrue, cellTerr);
            //TOTAL 3
            generarTotal3(rowTotal3, indexFinGrupo, styleTotal3, cellTerr, sheet);
            //++indexRow;

            indicesTotales += (indexFinGrupo + 1) + ",";
        }

        String[] aIndexTotales = indicesTotales.split(",");

        //TOTAL pais
        int indexTotalPais = ++indexRow;
        HSSFRow rowTotalPais = sheet.createRow((indexTotalPais));
        generarTotalPais(rowTotalPais, styleTotal3, sheet, aIndexTotales, aColsGrue, aCols20, aCols10);

        HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance()
                .getExternalContext().getResponse();

        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-Disposition", "attachment; filename=Ventas Cantadas.xls");
        workbook.write(response.getOutputStream());
        response.getOutputStream().flush();
        response.getOutputStream().close();
        FacesContext.getCurrentInstance().responseComplete();
        indexRow = 1;
    }

}

From source file:com.ideaspymes.arthyweb.ventas.web.controllers.VentasCantadasBean.java

private void creaCabecera(HSSFWorkbook workbook, HSSFSheet sheet) {
    Font fontSubTitulo = workbook.createFont();
    fontSubTitulo.setFontHeightInPoints((short) 8);
    fontSubTitulo.setBoldweight(Font.BOLDWEIGHT_BOLD);

    Font fontSubTituloAzul = workbook.createFont();
    fontSubTituloAzul.setFontHeightInPoints((short) 8);
    fontSubTituloAzul.setColor(HSSFColor.DARK_BLUE.index);
    fontSubTituloAzul.setBoldweight(Font.BOLDWEIGHT_BOLD);

    Font fontSubTituloCaje = workbook.createFont();
    fontSubTituloCaje.setFontHeightInPoints((short) 7);
    fontSubTituloCaje.setColor(HSSFColor.DARK_BLUE.index);
    fontSubTituloCaje.setBoldweight(Font.BOLDWEIGHT_BOLD);

    Font font7 = workbook.createFont();
    font7.setFontHeightInPoints((short) 6);

    Font fontTerritorio = workbook.createFont();
    fontTerritorio.setItalic(true);/* w w  w. j av  a2 s .c  o  m*/
    fontTerritorio.setFontHeightInPoints((short) 12);
    fontTerritorio.setBoldweight(Font.BOLDWEIGHT_BOLD);

    Font fontTerritorioTotal1 = workbook.createFont();
    fontTerritorioTotal1.setItalic(true);
    fontTerritorioTotal1.setFontHeightInPoints((short) 8);
    fontTerritorioTotal1.setBoldweight(Font.BOLDWEIGHT_BOLD);

    Font fontTitulo9 = workbook.createFont();
    fontTitulo9.setFontHeightInPoints((short) 8);

    Font fontTitulo = workbook.createFont();
    fontTitulo.setFontHeightInPoints((short) 12);
    fontTitulo.setBoldweight(Font.BOLDWEIGHT_BOLD);

    styleTitulo = workbook.createCellStyle();
    styleTitulo.setFont(fontTitulo);
    styleTitulo.setBottomBorderColor(IndexedColors.BLACK.getIndex());

    styleTerritorio = workbook.createCellStyle();
    styleTerritorio.setFont(fontTerritorio);

    styleTerritorioTotal1 = workbook.createCellStyle();
    styleTerritorioTotal1.setFont(fontTerritorioTotal1);
    styleTerritorioTotal1.setBorderBottom(HSSFCellStyle.BORDER_THIN);
    styleTerritorioTotal1.setBorderTop(HSSFCellStyle.BORDER_THIN);
    //styleCantidad.setBorderRight(HSSFCellStyle.BORDER_THIN);
    styleTerritorioTotal1.setBorderLeft(HSSFCellStyle.BORDER_THIN);

    styleTitulo9 = workbook.createCellStyle();
    styleTitulo9.setFont(fontTitulo9);
    styleTitulo9.setBorderBottom(HSSFCellStyle.BORDER_THIN);
    styleTitulo9.setBorderTop(HSSFCellStyle.BORDER_THIN);
    //styleCantidad.setBorderRight(HSSFCellStyle.BORDER_THIN);
    styleTitulo9.setBorderLeft(HSSFCellStyle.BORDER_THIN);

    styleSubTitulo = workbook.createCellStyle();
    styleSubTitulo.setFont(fontSubTitulo);
    styleSubTitulo.setBottomBorderColor(IndexedColors.BLACK.getIndex());
    styleSubTitulo.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
    styleSubTitulo.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
    styleSubTitulo.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
    styleSubTitulo.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);

    styleSubTituloCaje = workbook.createCellStyle();
    styleSubTituloCaje.setFont(fontSubTituloCaje);
    styleSubTituloCaje.setBottomBorderColor(IndexedColors.BLACK.getIndex());
    styleSubTituloCaje.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
    styleSubTituloCaje.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
    styleSubTituloCaje.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
    styleSubTituloCaje.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);

    styleMergeCentrado = workbook.createCellStyle();
    styleMergeCentrado.setFont(fontSubTituloAzul);
    styleMergeCentrado.setBottomBorderColor(IndexedColors.BLACK.getIndex());
    styleMergeCentrado.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
    styleMergeCentrado.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
    styleMergeCentrado.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);
    styleMergeCentrado.setAlignment(HSSFCellStyle.ALIGN_CENTER);
    styleMergeCentrado.setWrapText(true);

    styleMergeTotal = workbook.createCellStyle();
    styleMergeTotal.setFont(fontSubTitulo);
    styleMergeTotal.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    styleMergeTotal.setFillPattern(CellStyle.SOLID_FOREGROUND);
    styleMergeTotal.setBottomBorderColor(IndexedColors.BLACK.getIndex());
    styleMergeTotal.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
    styleMergeTotal.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
    styleMergeTotal.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
    styleMergeTotal.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);
    styleMergeTotal.setAlignment(HSSFCellStyle.ALIGN_CENTER);

    DataFormat format = workbook.createDataFormat();

    styleCantidadAzul = workbook.createCellStyle();
    styleCantidadAzul.setFont(fontSubTituloAzul);
    styleCantidadAzul.setDataFormat(format.getFormat("#,##0"));
    styleCantidadAzul.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
    styleCantidadAzul.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
    styleCantidadAzul.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
    styleCantidadAzul.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);
    styleCantidadAzul.setAlignment(HSSFCellStyle.ALIGN_RIGHT);

    styleCantidadNegrita = workbook.createCellStyle();
    styleCantidadNegrita.setFont(fontSubTitulo);
    styleCantidadNegrita.setDataFormat(format.getFormat("#,##0"));
    styleCantidadNegrita.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
    styleCantidadNegrita.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
    styleCantidadNegrita.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
    styleCantidadNegrita.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);

    styleCantidadGris = workbook.createCellStyle();
    styleCantidadGris.setFont(fontSubTitulo);
    styleCantidadGris.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    styleCantidadGris.setFillPattern(CellStyle.SOLID_FOREGROUND);
    styleCantidadGris.setDataFormat(format.getFormat("#,##0"));
    styleCantidadGris.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
    styleCantidadGris.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
    styleCantidadGris.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
    styleCantidadGris.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);

    styleCantidad = workbook.createCellStyle();
    styleCantidad.setFont(fontTitulo9);
    styleCantidad.setDataFormat(format.getFormat("#,##0"));
    styleCantidad.setBorderBottom(HSSFCellStyle.BORDER_THIN);
    styleCantidad.setBorderTop(HSSFCellStyle.BORDER_THIN);
    styleCantidad.setBorderRight(HSSFCellStyle.BORDER_THIN);
    styleCantidad.setBorderLeft(HSSFCellStyle.BORDER_THIN);

    styleCantidadGris1 = workbook.createCellStyle();
    styleCantidadGris1.setFont(fontTitulo9);
    styleCantidadGris1.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    styleCantidadGris1.setFillPattern(CellStyle.SOLID_FOREGROUND);
    styleCantidadGris1.setDataFormat(format.getFormat("#,##0"));
    styleCantidadGris1.setBorderBottom(HSSFCellStyle.BORDER_THIN);
    styleCantidadGris1.setBorderTop(HSSFCellStyle.BORDER_THIN);
    styleCantidadGris1.setBorderRight(HSSFCellStyle.BORDER_THIN);
    styleCantidadGris1.setBorderLeft(HSSFCellStyle.BORDER_THIN);

    styleCantidadCaje = workbook.createCellStyle();
    styleCantidadCaje.setFont(font7);
    styleCantidadCaje.setDataFormat(format.getFormat("#,##0"));
    styleCantidadCaje.setBorderBottom(HSSFCellStyle.BORDER_THIN);
    styleCantidadCaje.setBorderTop(HSSFCellStyle.BORDER_THIN);
    styleCantidadCaje.setBorderRight(HSSFCellStyle.BORDER_THIN);
    styleCantidadCaje.setBorderLeft(HSSFCellStyle.BORDER_THIN);

    HSSFRow rowTitulo = sheet.createRow(0);
    HSSFCell cellTitulo = rowTitulo.createCell(18);
    cellTitulo.setCellValue("CONTROL DIARIO DE VENTAS");
    cellTitulo.setCellStyle(styleTitulo);

    HSSFRow rowFecha = sheet.createRow(++indexRow);
    HSSFCell cellFecha = rowFecha.createCell(18);

    // SimpleDateFormat sdf = new SimpleDateFormat("EEEE, dd 'de' MMMM 'de' yyyy", new Locale("es", "py"));
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy", new Locale("es", "py"));

    cellFecha.setCellValue("De " + sdf.format(inicio) + " al " + sdf.format(fin));
    //Calendar calender = Calendar.getInstance();
    //cellFecha.setCellValue(calender.get(getInicio()));
    cellFecha.setCellStyle(styleTitulo);

    ++indexRow;
    HSSFRow rowCabeceraMarca = sheet.createRow((++indexRow));
    HSSFRow rowCabeceraProducto = sheet.createRow((++indexRow));
    HSSFRow rowCabecerauM = sheet.createRow((++indexRow));

    rowCabeceraProducto.setHeightInPoints((2 * sheet.getDefaultRowHeightInPoints()));

    HSSFCell cell0 = rowCabecerauM.createCell(indexCol);
    cell0.setCellValue("Zona");
    cell0.setCellStyle(styleSubTitulo);

    HSSFCell cell1 = rowCabecerauM.createCell(indexCol + 1);
    cell1.setCellValue("Vendedor");
    cell1.setCellStyle(styleSubTitulo);

    HSSFCell cell2 = rowCabecerauM.createCell(indexCol + 2);
    cell2.setCellValue("Boletas");
    cell2.setCellStyle(styleSubTitulo);

    HSSFCell cell3 = rowCabeceraProducto.createCell(indexCol + 3);
    HSSFCell cell4 = rowCabeceraProducto.createCell(indexCol + 4);
    cell3.setCellValue("Palermo Red Box 20");
    cell3.setCellStyle(styleMergeCentrado);
    cell4.setCellValue("");
    cell4.setCellStyle(styleMergeCentrado);
    sheet.addMergedRegion(CellRangeAddress.valueOf("$" + CellReference.convertNumToColString(indexCol + 3) + "$"
            + indexRow + ":$" + CellReference.convertNumToColString(indexCol + 4) + "$" + indexRow));

    HSSFCell cell3g = rowCabecerauM.createCell(indexCol + 3);
    cell3g.setCellValue("Grue");
    cell3g.setCellStyle(styleMergeCentrado);

    HSSFCell cell3c = rowCabecerauM.createCell(indexCol + 4);
    cell3c.setCellValue("Caj");
    cell3c.setCellStyle(styleSubTituloCaje);

    HSSFCell cell5 = (rowCabeceraProducto).createCell(indexCol + 5);
    sheet.addMergedRegion(CellRangeAddress.valueOf("$" + CellReference.convertNumToColString(indexCol + 5) + "$"
            + indexRow + ":$" + CellReference.convertNumToColString(indexCol + 6) + "$" + indexRow));
    cell5.setCellValue("Palermo Blue Box 20");
    cell5.setCellStyle(styleMergeCentrado);

    HSSFCell cell5g = rowCabecerauM.createCell(indexCol + 5);
    cell5g.setCellValue("Grue");
    cell5g.setCellStyle(styleMergeCentrado);

    HSSFCell cell5c = rowCabecerauM.createCell(indexCol + 6);
    cell5c.setCellValue("Caj");
    cell5c.setCellStyle(styleSubTituloCaje);

    HSSFCell cell7 = (rowCabeceraProducto).createCell(indexCol + 7);
    sheet.addMergedRegion(CellRangeAddress.valueOf("$" + CellReference.convertNumToColString(indexCol + 7) + "$"
            + indexRow + ":$" + CellReference.convertNumToColString(indexCol + 8) + "$" + indexRow));
    cell7.setCellValue("Palermo Green Box 20");
    cell7.setCellStyle(styleMergeCentrado);

    HSSFCell cell7g = rowCabecerauM.createCell(indexCol + 7);
    cell7g.setCellValue("Grue");
    cell7g.setCellStyle(styleMergeCentrado);

    HSSFCell cell7c = rowCabecerauM.createCell(indexCol + 8);
    cell7c.setCellValue("Caj");
    cell7c.setCellStyle(styleSubTituloCaje);

    HSSFCell cell9 = (rowCabeceraProducto).createCell(indexCol + 9);
    sheet.addMergedRegion(CellRangeAddress.valueOf("$" + CellReference.convertNumToColString(indexCol + 9) + "$"
            + indexRow + ":$" + CellReference.convertNumToColString(indexCol + 10) + "$" + indexRow));
    cell9.setCellValue("Palermo Tres Box 20");
    cell9.setCellStyle(styleMergeCentrado);

    HSSFCell cell9g = rowCabecerauM.createCell(indexCol + 9);
    cell9g.setCellValue("Grue");
    cell9g.setCellStyle(styleMergeCentrado);

    HSSFCell cell9c = rowCabecerauM.createCell(indexCol + 10);
    cell9c.setCellValue("Caj");
    cell9c.setCellStyle(styleSubTituloCaje);

    HSSFCell cell11 = (rowCabeceraProducto).createCell(indexCol + 11);
    sheet.addMergedRegion(CellRangeAddress.valueOf("$" + CellReference.convertNumToColString(indexCol + 11)
            + "$" + indexRow + ":$" + CellReference.convertNumToColString(indexCol + 12) + "$" + indexRow));
    cell11.setCellValue("Palermo Duo Box 20");
    cell11.setCellStyle(styleMergeCentrado);

    HSSFCell cell11g = rowCabecerauM.createCell(indexCol + 11);
    cell11g.setCellValue("Grue");
    cell11g.setCellStyle(styleMergeCentrado);

    HSSFCell cell11c = rowCabecerauM.createCell(indexCol + 12);
    cell11c.setCellValue("Caj");
    cell11c.setCellStyle(styleSubTituloCaje);

    HSSFCell cell13 = rowCabeceraProducto.createCell(indexCol + 13);
    sheet.addMergedRegion(CellRangeAddress.valueOf("$" + CellReference.convertNumToColString(indexCol + 13)
            + "$" + indexRow + ":$" + CellReference.convertNumToColString(indexCol + 14) + "$" + indexRow));
    cell13.setCellValue("Palermo Red Box 10");
    cell13.setCellStyle(styleMergeCentrado);

    HSSFCell cell13g = rowCabecerauM.createCell(indexCol + 13);
    cell13g.setCellValue("Grue");
    cell13g.setCellStyle(styleMergeCentrado);

    HSSFCell cell13c = rowCabecerauM.createCell(indexCol + 14);
    cell13c.setCellValue("Caj");
    cell13c.setCellStyle(styleSubTituloCaje);

    HSSFCell cell15 = (rowCabeceraProducto).createCell(indexCol + 15);
    sheet.addMergedRegion(CellRangeAddress.valueOf("$" + CellReference.convertNumToColString(indexCol + 15)
            + "$" + indexRow + ":$" + CellReference.convertNumToColString(indexCol + 16) + "$" + indexRow));
    cell15.setCellValue("Palermo Blue Box 10");
    cell15.setCellStyle(styleMergeCentrado);

    HSSFCell cell15g = rowCabecerauM.createCell(indexCol + 15);
    cell15g.setCellValue("Grue");
    cell15g.setCellStyle(styleMergeCentrado);

    HSSFCell cell15c = rowCabecerauM.createCell(indexCol + 16);
    cell15c.setCellValue("Caj");
    cell15c.setCellStyle(styleSubTituloCaje);

    HSSFCell cell17 = (rowCabeceraProducto).createCell(indexCol + 17);
    sheet.addMergedRegion(CellRangeAddress.valueOf("$" + CellReference.convertNumToColString(indexCol + 17)
            + "$" + indexRow + ":$" + CellReference.convertNumToColString(indexCol + 18) + "$" + indexRow));
    cell17.setCellValue("Palermo Green Box 10");
    cell17.setCellStyle(styleMergeCentrado);

    HSSFCell cell17g = rowCabecerauM.createCell(indexCol + 17);
    cell17g.setCellValue("Grue");
    cell17g.setCellStyle(styleMergeCentrado);

    HSSFCell cell17c = rowCabecerauM.createCell(indexCol + 18);
    cell17c.setCellValue("Caj");
    cell17c.setCellStyle(styleSubTituloCaje);

    HSSFCell cell19 = (rowCabeceraProducto).createCell(indexCol + 19);
    sheet.addMergedRegion(CellRangeAddress.valueOf("$" + CellReference.convertNumToColString(indexCol + 19)
            + "$" + indexRow + ":$" + CellReference.convertNumToColString(indexCol + 20) + "$" + indexRow));
    cell19.setCellValue("Palermo Tres Box 10");
    cell19.setCellStyle(styleMergeCentrado);

    HSSFCell cell19g = rowCabecerauM.createCell(indexCol + 19);
    cell19g.setCellValue("Grue");
    cell19g.setCellStyle(styleMergeCentrado);

    HSSFCell cell19c = rowCabecerauM.createCell(indexCol + 20);
    cell19c.setCellValue("Caj");
    cell19c.setCellStyle(styleSubTituloCaje);

    HSSFCell cell21 = (rowCabeceraProducto).createCell(indexCol + 21);
    sheet.addMergedRegion(CellRangeAddress.valueOf("$" + CellReference.convertNumToColString(indexCol + 21)
            + "$" + indexRow + ":$" + CellReference.convertNumToColString(indexCol + 22) + "$" + indexRow));
    cell21.setCellValue("Palermo Duo Box 10");
    cell21.setCellStyle(styleMergeCentrado);

    HSSFCell cell21g = rowCabecerauM.createCell(indexCol + 21);
    cell21g.setCellValue("Grue");
    cell21g.setCellStyle(styleMergeCentrado);

    HSSFCell cell21c = rowCabecerauM.createCell(indexCol + 22);
    cell21c.setCellValue("Caj");
    cell21c.setCellStyle(styleSubTituloCaje);

    HSSFCell cell23 = (rowCabeceraProducto).createCell(indexCol + 23);
    sheet.addMergedRegion(CellRangeAddress.valueOf("$" + CellReference.convertNumToColString(indexCol + 23)
            + "$" + indexRow + ":$" + CellReference.convertNumToColString(indexCol + 24) + "$" + indexRow));
    cell23.setCellValue("San Marino TYPE Box 20");
    cell23.setCellStyle(styleMergeCentrado);

    HSSFCell cell23g = rowCabecerauM.createCell(indexCol + 23);
    cell23g.setCellValue("Grue");
    cell23g.setCellStyle(styleMergeCentrado);

    HSSFCell cell23c = rowCabecerauM.createCell(indexCol + 24);
    cell23c.setCellValue("Caj");
    cell23c.setCellStyle(styleSubTituloCaje);

    HSSFCell cell25 = (rowCabeceraProducto).createCell(indexCol + 25);
    sheet.addMergedRegion(CellRangeAddress.valueOf("$" + CellReference.convertNumToColString(indexCol + 25)
            + "$" + indexRow + ":$" + CellReference.convertNumToColString(indexCol + 26) + "$" + indexRow));
    cell25.setCellValue("San Marino TYPE Box 10");
    cell25.setCellStyle(styleMergeCentrado);

    HSSFCell cell25g = rowCabecerauM.createCell(indexCol + 25);
    cell25g.setCellValue("Grue");
    cell25g.setCellStyle(styleMergeCentrado);

    HSSFCell cell25c = rowCabecerauM.createCell(indexCol + 26);
    cell25c.setCellValue("Caj");
    cell25c.setCellStyle(styleSubTituloCaje);

    HSSFCell cell27 = (rowCabeceraProducto).createCell(indexCol + 27);
    sheet.addMergedRegion(CellRangeAddress.valueOf("$" + CellReference.convertNumToColString(indexCol + 27)
            + "$" + indexRow + ":$" + CellReference.convertNumToColString(indexCol + 28) + "$" + indexRow));
    cell27.setCellValue("San Marino TYPE Soft");
    cell27.setCellStyle(styleMergeCentrado);

    HSSFCell cell27g = rowCabecerauM.createCell(indexCol + 27);
    cell27g.setCellValue("Grue");
    cell27g.setCellStyle(styleMergeCentrado);

    HSSFCell cell27c = rowCabecerauM.createCell(indexCol + 28);
    cell27c.setCellValue("Caj");
    cell27c.setCellStyle(styleSubTituloCaje);

    HSSFCell cell29 = (rowCabeceraProducto).createCell(indexCol + 29);
    sheet.addMergedRegion(CellRangeAddress.valueOf("$" + CellReference.convertNumToColString(indexCol + 29)
            + "$" + indexRow + ":$" + CellReference.convertNumToColString(indexCol + 30) + "$" + indexRow));
    cell29.setCellValue("Kentucky Box 20");
    cell29.setCellStyle(styleMergeCentrado);

    HSSFCell cell29g = rowCabecerauM.createCell(indexCol + 29);
    cell29g.setCellValue("Grue");
    cell29g.setCellStyle(styleMergeCentrado);

    HSSFCell cell29c = rowCabecerauM.createCell(indexCol + 30);
    cell29c.setCellValue("Caj");
    cell29c.setCellStyle(styleSubTituloCaje);

    HSSFCell cell31 = (rowCabeceraProducto).createCell(indexCol + 31);
    sheet.addMergedRegion(CellRangeAddress.valueOf("$" + CellReference.convertNumToColString(indexCol + 31)
            + "$" + indexRow + ":$" + CellReference.convertNumToColString(indexCol + 32) + "$" + indexRow));
    cell31.setCellValue("Kentucky Box 10");
    cell31.setCellStyle(styleMergeCentrado);

    HSSFCell cell31g = rowCabecerauM.createCell(indexCol + 31);
    cell31g.setCellValue("Grue");
    cell31g.setCellStyle(styleMergeCentrado);

    HSSFCell cell31c = rowCabecerauM.createCell(indexCol + 32);
    cell31c.setCellValue("Caj");
    cell31c.setCellStyle(styleSubTituloCaje);

    HSSFCell cell33 = (rowCabeceraProducto).createCell(indexCol + 33);
    sheet.addMergedRegion(CellRangeAddress.valueOf("$" + CellReference.convertNumToColString(indexCol + 33)
            + "$" + indexRow + ":$" + CellReference.convertNumToColString(indexCol + 34) + "$" + indexRow));
    cell33.setCellValue("Kentucky Soft");
    cell33.setCellStyle(styleMergeCentrado);

    HSSFCell cell33g = rowCabecerauM.createCell(indexCol + 33);
    cell33g.setCellValue("Grue");
    cell33g.setCellStyle(styleMergeCentrado);

    HSSFCell cell33c = rowCabecerauM.createCell(indexCol + 34);
    cell33c.setCellValue("Caj");
    cell33c.setCellStyle(styleSubTituloCaje);

    HSSFCell cell35 = rowCabeceraProducto.createCell(indexCol + 35);
    sheet.addMergedRegion(CellRangeAddress.valueOf("$" + CellReference.convertNumToColString(indexCol + 35)
            + "$" + indexRow + ":$" + CellReference.convertNumToColString(indexCol + 36) + "$" + indexRow));
    cell35.setCellValue("Total");
    cell35.setCellStyle(styleMergeTotal);
    HSSFCell cell38 = rowCabeceraProducto.createCell(indexCol + 36);
    cell38.setCellValue("");
    cell38.setCellStyle(styleMergeTotal);

    HSSFCell cell35g = rowCabecerauM.createCell(indexCol + 35);
    cell35g.setCellValue("Gruesas");
    cell35g.setCellStyle(styleSubTitulo);

    HSSFCell cell35c = rowCabecerauM.createCell(indexCol + 36);
    cell35c.setCellValue("Caje");
    cell35c.setCellStyle(styleSubTitulo);

    HSSFCell cell37c = rowCabecerauM.createCell(indexCol + 37);
    cell37c.setCellValue("Cajas");
    cell37c.setCellStyle(styleSubTitulo);

    HSSFCell cell38g = rowCabecerauM.createCell(indexCol + 38);
    cell38g.setCellValue("+gr");
    cell38g.setCellStyle(styleSubTitulo);

    sheet.createFreezePane(2, 7);

}

From source file:com.idega.block.datareport.business.SimpleReportBusinessBean.java

License:Open Source License

public void writeSimpleExcelFile(JRDataSource reportData, String nameOfReport, String filePathAndName,
        ReportDescription description) throws IOException {
    if (nameOfReport == null || "".equals(nameOfReport)) {
        nameOfReport = NAME_OF_REPORT;/*from   www  .j  a v  a2  s.c  om*/
    }
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet(TextSoap.encodeToValidExcelSheetName(nameOfReport));
    int rowIndex = 0;

    //-- Report Name --//
    // Create a row and put some cells in it. Rows are 0 based.
    HSSFRow row = sheet.createRow((short) rowIndex++);
    // Create a cell and put a value in it.
    HSSFCell cell = row.createCell((short) 0);

    // Create a new font and alter it.
    HSSFFont font = wb.createFont();
    font.setFontHeightInPoints((short) 24);
    font.setFontName(REPORT_FONT);
    font.setItalic(true);
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

    // Fonts are set into a style so create a new one to use.
    HSSFCellStyle style = wb.createCellStyle();
    style.setFont(font);

    // Create a cell and put a value in it.
    cell.setCellValue(nameOfReport);
    cell.setCellStyle(style);

    //-- Report Parameters --//
    rowIndex++;
    HSSFRow row1 = null;
    String parameterString = "";
    List labels = description.getListOfHeaderParameterLabelKeys();
    List parameters = description.getListOfHeaderParameterKeys();
    Iterator labelIter = labels.iterator();
    Iterator parameterIter = parameters.iterator();
    boolean newLineForeEachParameter = description.doCreateNewLineForEachParameter();
    while (labelIter.hasNext() && parameterIter.hasNext()) {
        String label = description.getParameterOrLabelName((String) labelIter.next());
        String parameter = description.getParameterOrLabelName((String) parameterIter.next());
        if (newLineForeEachParameter) {
            row1 = sheet.createRow((short) rowIndex++);
            row1.createCell((short) 0).setCellValue(label + " " + parameter);
        } else {
            parameterString += label + " " + parameter + "      ";
        }
    }
    if (!newLineForeEachParameter) {
        row1 = sheet.createRow((short) rowIndex++);
        row1.createCell((short) 0).setCellValue(parameterString);
    }
    rowIndex++;

    //-- Report ColumnHeader --//
    List fields = description.getListOfFields();
    HSSFRow headerRow = sheet.createRow((short) rowIndex++);

    HSSFCellStyle headerCellStyle = wb.createCellStyle();

    headerCellStyle.setWrapText(true);
    headerCellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP);
    headerCellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);

    HSSFFont headerCellFont = wb.createFont();
    //headerCellFont.setFontHeightInPoints((short)12);
    headerCellFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    headerCellStyle.setFont(headerCellFont);

    int colIndex = 0;
    int columnWithUnit = 256; // the unit is 1/256 of a character
    int numberOfCharactersPerLineInLongTextFields = 60;
    int numberOfCharactersPerLineInRatherLongTextFields = 35;
    int numberOfCharactersPerLineInUndifinedTextFields = 20;

    for (Iterator iter = fields.iterator(); iter.hasNext(); colIndex++) {
        ReportableField field = (ReportableField) iter.next();
        HSSFCell headerCell = headerRow.createCell((short) colIndex);
        headerCell.setCellValue(description.getColumnName(field));
        headerCell.setCellStyle(headerCellStyle);

        //column width
        int fieldsMaxChar = field.getMaxNumberOfCharacters();
        int colWith = numberOfCharactersPerLineInRatherLongTextFields * columnWithUnit; //default, can be rather long text
        if (fieldsMaxChar > 0 && fieldsMaxChar < numberOfCharactersPerLineInRatherLongTextFields) {
            colWith = (fieldsMaxChar + 1) * columnWithUnit; // short fields
        } else if (fieldsMaxChar > 500) { // when the field is set to be able to contain very long text
            colWith = numberOfCharactersPerLineInLongTextFields * columnWithUnit; //can be very long text
        } else if (fieldsMaxChar < 0) {
            colWith = numberOfCharactersPerLineInUndifinedTextFields * columnWithUnit;
        }
        sheet.setColumnWidth((short) colIndex, (short) colWith);

    }

    //-- Report ColumnDetail --//
    try {
        HSSFCellStyle dataCellStyle = wb.createCellStyle();
        dataCellStyle.setWrapText(true);
        dataCellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP);
        sheet.createFreezePane(0, rowIndex);

        while (reportData.next()) {
            HSSFRow dataRow = sheet.createRow((short) rowIndex++);
            colIndex = 0;
            for (Iterator iter = fields.iterator(); iter.hasNext(); colIndex++) {
                ReportableField field = (ReportableField) iter.next();
                HSSFCell dataCell = dataRow.createCell((short) colIndex);
                Object fieldValue = reportData.getFieldValue(field);
                if (fieldValue != null) {
                    dataCell.setCellValue(String.valueOf(fieldValue));
                }
                dataCell.setCellStyle(dataCellStyle);
            }
        }
    } catch (JRException e) {
        //-- Exception fetching data --//
        HSSFRow exceptionRow = sheet.createRow((short) rowIndex++);
        HSSFCell exceptionCell = exceptionRow.createCell((short) 0);

        // Create a new font and alter it.
        HSSFFont exceptionFont = wb.createFont();
        exceptionFont.setFontName(REPORT_FONT);
        exceptionFont.setItalic(true);

        // Fonts are set into a style so create a new one to use.
        HSSFCellStyle exceptionStyle = wb.createCellStyle();
        exceptionStyle.setFont(exceptionFont);

        // Create a cell and put a value in it.
        exceptionCell.setCellValue("Error occurred while getting data. Check log for more details.");
        exceptionCell.setCellStyle(exceptionStyle);

        e.printStackTrace();
    }

    // Write the output to a file
    FileOutputStream fileOut = new FileOutputStream(filePathAndName);
    wb.write(fileOut);
    fileOut.close();
}

From source file:com.insoul.ti.controller.ContestProjectEntryController.java

@RequestMapping("/download")
public ModelAndView download(HttpServletResponse response) throws Exception {
    HSSFWorkbook workbook = new HSSFWorkbook();// Excel
    HSSFSheet sheet = workbook.createSheet();// ExcelSheet
    sheet.createFreezePane(1, 2);// 
    // /*from  w  ww .  j a v a  2  s .  c  o  m*/
    sheet.setColumnWidth(0, 1000);
    sheet.setColumnWidth(1, 3500);
    sheet.setColumnWidth(2, 3500);
    sheet.setColumnWidth(3, 6500);
    sheet.setColumnWidth(4, 6500);
    sheet.setColumnWidth(5, 6500);
    sheet.setColumnWidth(6, 6500);
    sheet.setColumnWidth(7, 2500);
    // Sheet?
    //        HSSFCellStyle sheetStyle = workbook.createCellStyle();
    // 
    //        sheetStyle.setFillBackgroundColor(HSSFColor.GREY_25_PERCENT.index);
    // ?
    //        sheetStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
    // ?
    //        sheetStyle.setFillPattern(HSSFCellStyle.FINE_DOTS);
    // ?
    //        for (int i = 0; i <= 14; i++) {
    //            sheet.setDefaultColumnStyle((short) i, sheetStyle);
    //        }
    // 
    HSSFFont headfont = workbook.createFont();
    headfont.setFontName("");
    headfont.setFontHeightInPoints((short) 22);// ?
    headfont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// 
    // ??
    HSSFCellStyle headstyle = workbook.createCellStyle();
    headstyle.setFont(headfont);
    headstyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);// ?
    headstyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 
    headstyle.setLocked(true);
    headstyle.setWrapText(true);// ?
    // ??
    HSSFFont columnHeadFont = workbook.createFont();
    columnHeadFont.setFontName("");
    columnHeadFont.setFontHeightInPoints((short) 10);
    columnHeadFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    // ?
    HSSFCellStyle columnHeadStyle = workbook.createCellStyle();
    columnHeadStyle.setFont(columnHeadFont);
    columnHeadStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);// ?
    columnHeadStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 
    columnHeadStyle.setLocked(true);
    columnHeadStyle.setWrapText(true);
    columnHeadStyle.setLeftBorderColor(HSSFColor.BLACK.index);// 
    columnHeadStyle.setBorderLeft((short) 1);// ?
    columnHeadStyle.setRightBorderColor(HSSFColor.BLACK.index);// ?
    columnHeadStyle.setBorderRight((short) 1);// ?
    columnHeadStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); // ?
    columnHeadStyle.setBottomBorderColor(HSSFColor.BLACK.index); // ?
    // ????
    columnHeadStyle.setFillForegroundColor(HSSFColor.WHITE.index);

    HSSFFont font = workbook.createFont();
    font.setFontName("");
    font.setFontHeightInPoints((short) 10);
    // ??
    HSSFCellStyle style = workbook.createCellStyle();
    style.setFont(font);
    style.setAlignment(HSSFCellStyle.ALIGN_LEFT);// ?
    style.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP);// 
    style.setWrapText(true);
    style.setLeftBorderColor(HSSFColor.BLACK.index);
    style.setBorderLeft((short) 1);
    style.setRightBorderColor(HSSFColor.BLACK.index);
    style.setBorderRight((short) 1);
    style.setBorderBottom(HSSFCellStyle.BORDER_THIN); // ?
    style.setBottomBorderColor(HSSFColor.BLACK.index); // ?
    style.setFillForegroundColor(HSSFColor.WHITE.index);// ?
    // ??
    HSSFCellStyle centerstyle = workbook.createCellStyle();
    centerstyle.setFont(font);
    centerstyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);// ?
    centerstyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 
    centerstyle.setWrapText(true);
    centerstyle.setLeftBorderColor(HSSFColor.BLACK.index);
    centerstyle.setBorderLeft((short) 1);
    centerstyle.setRightBorderColor(HSSFColor.BLACK.index);
    centerstyle.setBorderRight((short) 1);
    centerstyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); // ?
    centerstyle.setBottomBorderColor(HSSFColor.BLACK.index); // ?
    centerstyle.setFillForegroundColor(HSSFColor.WHITE.index);// ?
    try {
        // 
        HSSFRow row0 = sheet.createRow(0);
        // 
        row0.setHeight((short) 900);
        // 
        HSSFCell cell0 = row0.createCell(0);
        cell0.setCellValue(new HSSFRichTextString("???"));
        cell0.setCellStyle(headstyle);
        /**
         * ?? ??0 ??0 ??0 ??0
         */
        CellRangeAddress range = new CellRangeAddress(0, 0, 0, 14);
        sheet.addMergedRegion(range);
        // 
        HSSFRow row1 = sheet.createRow(1);
        row1.setHeight((short) 750);
        HSSFCell cell = row1.createCell(0);
        cell.setCellValue(new HSSFRichTextString("??"));
        cell.setCellStyle(columnHeadStyle);
        cell = row1.createCell(1);
        cell.setCellValue(new HSSFRichTextString(""));
        cell.setCellStyle(columnHeadStyle);
        cell = row1.createCell(2);
        cell.setCellValue(new HSSFRichTextString("??"));
        cell.setCellStyle(columnHeadStyle);
        cell = row1.createCell(3);
        cell.setCellValue(new HSSFRichTextString(""));
        cell.setCellStyle(columnHeadStyle);
        cell = row1.createCell(4);
        cell.setCellValue(new HSSFRichTextString("??"));
        cell.setCellStyle(columnHeadStyle);
        cell = row1.createCell(5);
        cell.setCellValue(new HSSFRichTextString(""));
        cell.setCellStyle(columnHeadStyle);
        cell = row1.createCell(6);
        cell.setCellValue(new HSSFRichTextString("?"));
        cell.setCellStyle(columnHeadStyle);
        cell = row1.createCell(7);
        cell.setCellValue(new HSSFRichTextString(""));
        cell.setCellStyle(columnHeadStyle);
        cell = row1.createCell(8);
        cell.setCellValue(new HSSFRichTextString(""));
        cell.setCellStyle(columnHeadStyle);
        cell = row1.createCell(9);
        cell.setCellValue(new HSSFRichTextString("??"));
        cell.setCellStyle(columnHeadStyle);
        cell = row1.createCell(10);
        cell.setCellValue(new HSSFRichTextString("??"));
        cell.setCellStyle(columnHeadStyle);
        cell = row1.createCell(11);
        cell.setCellValue(new HSSFRichTextString(""));
        cell.setCellStyle(columnHeadStyle);
        cell = row1.createCell(12);
        cell.setCellValue(new HSSFRichTextString("??"));
        cell.setCellStyle(columnHeadStyle);
        cell = row1.createCell(13);
        cell.setCellValue(new HSSFRichTextString("?"));
        cell.setCellStyle(columnHeadStyle);
        cell = row1.createCell(14);
        cell.setCellValue(new HSSFRichTextString("??"));
        cell.setCellStyle(columnHeadStyle);
        List<ContestEntry> projectList = contestEntryDAO.findAll();
        int m = 2;
        int len = projectList.size();
        for (int i = 0; i < len; i++) {
            ContestEntry c = projectList.get(i);
            HSSFRow row = sheet.createRow(m + i);
            cell = row.createCell(0);
            cell.setCellValue(new HSSFRichTextString(c.getId() + ""));
            cell.setCellStyle(style);
            cell = row.createCell(1);
            cell.setCellValue(new HSSFRichTextString(c.getLocation()));
            cell.setCellStyle(style);
            cell = row.createCell(2);
            cell.setCellValue(new HSSFRichTextString(c.getInstance()));
            cell.setCellStyle(style);
            cell = row.createCell(3);
            cell.setCellValue(new HSSFRichTextString(c.getIndustry()));
            cell.setCellStyle(style);
            cell = row.createCell(4);
            cell.setCellValue(new HSSFRichTextString(c.getLegalFormation()));
            cell.setCellStyle(style);
            cell = row.createCell(5);
            cell.setCellValue(new HSSFRichTextString(c.getRegtime()));
            cell.setCellStyle(style);
            cell = row.createCell(6);
            cell.setCellValue(new HSSFRichTextString(c.getEmployqty() + ""));
            cell.setCellStyle(style);
            cell = row.createCell(7);
            cell.setCellValue(new HSSFRichTextString(c.getLegalPerson()));
            cell.setCellStyle(style);
            cell = row.createCell(8);
            cell.setCellValue(new HSSFRichTextString(c.getUserCategory()));
            cell.setCellStyle(style);
            cell = row.createCell(9);
            cell.setCellValue(new HSSFRichTextString(c.getContact()));
            cell.setCellStyle(style);
            cell = row.createCell(10);
            cell.setCellValue(new HSSFRichTextString(c.getIdNumber()));
            cell.setCellStyle(style);
            cell = row.createCell(11);
            cell.setCellValue(new HSSFRichTextString(c.getBankName()));
            cell.setCellStyle(style);
            cell = row.createCell(12);
            cell.setCellValue(new HSSFRichTextString(c.getBankUserName()));
            cell.setCellStyle(style);
            cell = row.createCell(13);
            cell.setCellValue(new HSSFRichTextString(c.getBankAccount()));
            cell.setCellStyle(style);
            cell = row.createCell(14);
            cell.setCellValue(new HSSFRichTextString(c.getSupportMoney()));
            cell.setCellStyle(style);
        }
        String filename = System.nanoTime() + ".xls";// Excel??
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-disposition", "attachment;filename=" + filename);
        OutputStream ouputStream = response.getOutputStream();
        workbook.write(ouputStream);
        ouputStream.flush();
        ouputStream.close();
    } catch (Exception e) {
        log.error("download excel Error.", e);
    }
    return null;
}

From source file:com.isoftstone.web.dao.Car_dao.java

/**
 * ?excel,?excel// w w  w  .j ava  2s .  c  om
 * @param carlist
 * @param path
 * @return ?excel
 */
public boolean addToExcel(List<Car_inf> carlist, String path) {

    System.out.println("excel\n");
    // webbookExcel  
    HSSFWorkbook wb = new HSSFWorkbook();
    // webbooksheet,Excelsheet  
    HSSFSheet sheet = wb.createSheet("");
    // sheet0,poiExcelshort  
    HSSFRow row = sheet.createRow((int) 0);
    //    
    HSSFCellStyle style = wb.createCellStyle();
    style.setAlignment(HSSFCellStyle.ALIGN_CENTER); //   

    HSSFCell cell = row.createCell((short) 0);
    cell.setCellValue("id");
    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);
    cell = row.createCell((short) 5);
    cell.setCellValue("");
    cell.setCellStyle(style);

    for (int i = 0; i < carlist.size(); i++) {
        row = sheet.createRow((int) i + 1);
        Car_inf car = (Car_inf) carlist.get(i);
        //   
        String logon = car.getLogon().toString();
        String dated = car.getDated().toString();
        row.createCell((short) 0).setCellValue(car.getId());
        row.createCell((short) 1).setCellValue(car.getBrand());
        row.createCell((short) 2).setCellValue(car.getSeat());
        row.createCell((short) 3).setCellValue(logon);
        row.createCell((short) 4).setCellValue(dated);
        row.createCell((short) 5).setCellValue(car.getD_license());
        row.createCell((short) 6).setCellValue(car.getC_license());
    }
    //   
    try {
        System.out.println("true\n");
        String name = path + "?.xls";
        FileOutputStream fout = new FileOutputStream(name);
        wb.write(fout);
        fout.close();
        System.out.println("\n");
        return true;
    } catch (Exception e) {
        e.printStackTrace();
    }

    return false;
}