Example usage for org.apache.poi.ss.usermodel CellStyle setBorderBottom

List of usage examples for org.apache.poi.ss.usermodel CellStyle setBorderBottom

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel CellStyle setBorderBottom.

Prototype

void setBorderBottom(BorderStyle border);

Source Link

Document

set the type of border to use for the bottom border of the cell

Usage

From source file:ro.dabuno.office.integration.LoadCalculator.java

/**
 * cell styles used for formatting calendar sheets
 *//* w  ww  .  ja  v a  2  s  .  c om*/
private static Map<String, CellStyle> createStyles(Workbook wb) {
    Map<String, CellStyle> styles = new HashMap<String, CellStyle>();

    CellStyle style;
    Font titleFont = wb.createFont();
    titleFont.setFontHeightInPoints((short) 14);
    titleFont.setFontName("Trebuchet MS");
    style = wb.createCellStyle();
    style.setFont(titleFont);
    style.setBorderBottom(BorderStyle.DOTTED);
    style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    styles.put("title", style);

    Font itemFont = wb.createFont();
    itemFont.setFontHeightInPoints((short) 9);
    itemFont.setFontName("Trebuchet MS");
    style = wb.createCellStyle();
    style.setAlignment(HorizontalAlignment.LEFT);
    style.setFont(itemFont);
    styles.put("item_left", style);

    style = wb.createCellStyle();
    style.setAlignment(HorizontalAlignment.RIGHT);
    style.setFont(itemFont);
    styles.put("item_right", style);

    style = wb.createCellStyle();
    style.setAlignment(HorizontalAlignment.RIGHT);
    style.setFont(itemFont);
    style.setBorderRight(BorderStyle.DOTTED);
    style.setRightBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderBottom(BorderStyle.DOTTED);
    style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderLeft(BorderStyle.DOTTED);
    style.setLeftBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderTop(BorderStyle.DOTTED);
    style.setTopBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setDataFormat(
            wb.createDataFormat().getFormat("_($* #,##0.00_);_($* (#,##0.00);_($* \"-\"??_);_(@_)"));
    styles.put("input_$", style);

    style = wb.createCellStyle();
    style.setAlignment(HorizontalAlignment.RIGHT);
    style.setFont(itemFont);
    style.setBorderRight(BorderStyle.DOTTED);
    style.setRightBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderBottom(BorderStyle.DOTTED);
    style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderLeft(BorderStyle.DOTTED);
    style.setLeftBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderTop(BorderStyle.DOTTED);
    style.setTopBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setDataFormat(wb.createDataFormat().getFormat("0.000%"));
    styles.put("input_%", style);

    style = wb.createCellStyle();
    style.setAlignment(HorizontalAlignment.RIGHT);
    style.setFont(itemFont);
    style.setBorderRight(BorderStyle.DOTTED);
    style.setRightBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderBottom(BorderStyle.DOTTED);
    style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderLeft(BorderStyle.DOTTED);
    style.setLeftBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderTop(BorderStyle.DOTTED);
    style.setTopBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setDataFormat(wb.createDataFormat().getFormat("0"));
    styles.put("input_i", style);

    style = wb.createCellStyle();
    style.setAlignment(HorizontalAlignment.CENTER);
    style.setFont(itemFont);
    style.setDataFormat(wb.createDataFormat().getFormat("m/d/yy"));
    styles.put("input_d", style);

    style = wb.createCellStyle();
    style.setAlignment(HorizontalAlignment.RIGHT);
    style.setFont(itemFont);
    style.setBorderRight(BorderStyle.DOTTED);
    style.setRightBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderBottom(BorderStyle.DOTTED);
    style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderLeft(BorderStyle.DOTTED);
    style.setLeftBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderTop(BorderStyle.DOTTED);
    style.setTopBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setDataFormat(wb.createDataFormat().getFormat("$##,##0.00"));
    style.setBorderBottom(BorderStyle.DOTTED);
    style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    styles.put("formula_$", style);

    style = wb.createCellStyle();
    style.setAlignment(HorizontalAlignment.RIGHT);
    style.setFont(itemFont);
    style.setBorderRight(BorderStyle.DOTTED);
    style.setRightBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderBottom(BorderStyle.DOTTED);
    style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderLeft(BorderStyle.DOTTED);
    style.setLeftBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderTop(BorderStyle.DOTTED);
    style.setTopBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setDataFormat(wb.createDataFormat().getFormat("0"));
    style.setBorderBottom(BorderStyle.DOTTED);
    style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    styles.put("formula_i", style);

    return styles;
}

From source file:ru.wmbdiff.ExportIntoExcel.java

License:Apache License

public void export(File file, WMBDiffNoRootTreeTableModel model) {
    logger.info("export begin");
    Workbook workbook = new HSSFWorkbook();
    Sheet sheet = workbook.createSheet("WMBDiff");
    int rowNum = 0;
    //Create Header
    CellStyle style;
    Font headerFont = workbook.createFont();
    headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    headerFont.setColor(IndexedColors.WHITE.getIndex());
    headerFont.setFontHeightInPoints((short) 10);
    style = workbook.createCellStyle();//from   ww  w  .  j a v  a 2s . co m
    style.setBorderRight(CellStyle.BORDER_THIN);
    style.setRightBorderColor(IndexedColors.WHITE.getIndex());
    style.setBorderBottom(CellStyle.BORDER_THIN);
    style.setBottomBorderColor(IndexedColors.WHITE.getIndex());
    style.setBorderLeft(CellStyle.BORDER_THIN);
    style.setLeftBorderColor(IndexedColors.WHITE.getIndex());
    style.setBorderTop(CellStyle.BORDER_THIN);
    style.setTopBorderColor(IndexedColors.WHITE.getIndex());
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setFillForegroundColor(IndexedColors.AQUA.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setFont(headerFont);

    Row row = sheet.createRow(rowNum++);
    Cell cell;
    cell = row.createCell(0);
    cell.setCellValue("Result");
    cell.setCellStyle(style);
    cell = row.createCell(1);
    cell.setCellValue("Broker");
    cell.setCellStyle(style);
    cell = row.createCell(2);
    cell.setCellValue("Execution Group");
    cell.setCellStyle(style);
    cell = row.createCell(3);
    cell.setCellValue("Name");
    cell.setCellStyle(style);
    cell = row.createCell(4);
    cell.setCellValue("Type");
    cell.setCellStyle(style);
    cell = row.createCell(5);
    cell.setCellValue("Last Modification");
    cell.setCellStyle(style);
    cell = row.createCell(6);
    cell.setCellValue("Deployment Date");
    cell.setCellStyle(style);
    cell = row.createCell(7);
    cell.setCellValue("Bar File");
    cell.setCellStyle(style);
    cell = row.createCell(8);
    cell.setCellValue("Result Description");
    cell.setCellStyle(style);
    sheet.createFreezePane(0, 1);

    List<DiffExecutionGroup> dEG = model.getDiffExecutionGroupList();
    ListIterator<DiffExecutionGroup> litr = dEG.listIterator();
    while (litr.hasNext()) {
        DiffExecutionGroup element = litr.next();
        element.getDiffResultList();
        ListIterator<DiffDeployedObjectResult> litr2 = element.getDiffResultList().listIterator();
        while (litr2.hasNext()) {
            DiffDeployedObjectResult res = litr2.next();
            switch (res.getResult()) {
            case ONLY_IN_A:
                createRow(rowNum++, sheet, res.getAObject(), "A", res.getResultDesc());
                break;
            case ONLY_IN_B:
                createRow(rowNum++, sheet, res.getBObject(), "B", res.getResultDesc());
                break;
            case EQUAL:
                createRow(rowNum++, sheet, res.getAObject(), "=", res.getResultDesc());
                createRow(rowNum++, sheet, res.getBObject(), "=", res.getResultDesc());
                sheet.groupRow(rowNum - 2, rowNum - 2);
                break;
            case DIFF:
                createRow(rowNum++, sheet, res.getAObject(), "!=", res.getResultDesc());
                createRow(rowNum++, sheet, res.getBObject(), "!=", res.getResultDesc());
                sheet.groupRow(rowNum - 2, rowNum - 2);
                break;
            }
            ;

        }
        ;
    }
    ;
    //Adjust column width to fit the contents
    for (int i = 0; i < 9; i++)
        sheet.autoSizeColumn(i);
    //set Filter
    sheet.setAutoFilter(new CellRangeAddress(0, rowNum - 1, 0, 8));
    try {
        FileOutputStream out = new FileOutputStream(file);
        workbook.write(out);
        workbook.close();
        out.close();
    } catch (Exception e) {
        logger.error("export", e);
    }
    logger.info("export end");
}

From source file:Sales.MainMenu.java

private void submitToPublishingPDFButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_submitToPublishingPDFButtonActionPerformed

    String validityFrom = validityFromDatePicker.getJFormattedTextField().getText();
    String validityTo = validityToDatePicker.getJFormattedTextField().getText();
    String kkluNumber = kkluNumberTextField.getText();
    String pol = pPolTextField.getText();
    String pod = pPodTextField.getText();
    String commClass = pCommodityClassComboBox.getSelectedItem().toString();
    String handlingInstructions = pHandlingInstructions.getSelectedItem().toString();
    String commDesc = pCommodityDescriptionTextField.getText();
    String oft = pOftTextField.getText();
    String oftUnit = pOftComboBox.getSelectedItem().toString();
    String baf = null;/*from ww  w  . j  a v a2 s  . com*/
    String bafText = pBafTextField.getText();
    Boolean bafIncluded = pBafIncludedCheckBox.isSelected();
    String eca = null;
    String ecaText = pEcaTextField.getText();
    String ecaUnit = pEcaComboBox.getSelectedItem().toString();
    Boolean ecaIncluded = pEcaIncludedCheckBox.isSelected();
    String thc = null;
    String thcText = "$" + pThcTextField.getText();
    String thcUnit = pThcComboBox.getSelectedItem().toString();
    Boolean thcIncluded = pThcIncludedCheckBox.isSelected();
    Boolean thcSubjectToTariff = thcSubjectToTariffCheckBox.isSelected();
    String wfg = null;
    String wfgText = pWfgTextField.getText();
    String wfgUnit = pWfgComboBox.getSelectedItem().toString();
    Boolean wfgIncluded = pWfgIncludedCheckBox.isSelected();
    Boolean wfgSubjectToTariff = wfgSubjectToTariffCheckBox.isSelected();
    String docFee = pDocFeeComboBox.getSelectedItem().toString();
    Boolean docFeeIncluded = pDocFeeIncludedCheckBox.isSelected();
    String comments = pCommentsTextArea.getText();
    Boolean warRisk = pWarRiskCheckBox.isSelected();
    String quoteID = pQuoteNumberTextField.getText();
    String bookingNumber = pBookingNumberTextField.getText();
    String storage = null;
    String storageText = storageTextField.getText();
    String storageUnit = storageUnitComboBox.getSelectedItem().toString();
    Boolean storageIncluded = storageIncludedCheckBox.isSelected();
    Boolean storageSubjectToTariff = storageSubjectToTariffCheckBox.isSelected();
    Boolean bafSubjectToTariff = bafSubjectToTariffCheckBox.isSelected();
    Boolean ecaSubjectToTariff = ecaSubjectToTariffCheckBox.isSelected();

    String TIME_STAMP = new SimpleDateFormat("MM/dd/yyyy HH:mm").format(Calendar.getInstance().getTime());

    if (bafIncluded != true && bafSubjectToTariff != true) {
        baf = bafText;
    } else if (bafIncluded == true) {
        baf = "Included";
    } else if (bafSubjectToTariff == true) {
        baf = "Subject to Tariff";
    }

    if (ecaIncluded != true && ecaSubjectToTariff != true) {
        eca = ecaText;
    } else if (ecaIncluded == true) {
        eca = "Included";
    } else if (ecaSubjectToTariff == true) {
        eca = "Subject to Tariff";
    } else if (ecaSubjectToTariff == true) {
        eca = "Subject to Tariff";
    }

    if (thcSubjectToTariff == true) {
        thc = "Subject to Tariff";
    } else if (thcSubjectToTariff != true && thcIncluded != true) {
        thc = thcText;
    } else if (thcSubjectToTariff != true && thcIncluded == true) {
        thc = "Included";
    } else if (thcIncluded == true && thcSubjectToTariff == true) {
        JOptionPane.showMessageDialog(null, "You can only select one");
    }

    if (wfgSubjectToTariff == true) {
        wfg = "Subject to Tariff";
        wfgUnit = "N/A";
    } else if (wfgSubjectToTariff != true && wfgIncluded != true) {
        wfg = wfgText;
    } else if (wfgSubjectToTariff != true && wfgIncluded == true) {
        wfg = "Included";
    } else if (wfgIncluded == true && wfgSubjectToTariff == true) {
        JOptionPane.showMessageDialog(null, "You can only select one");
    }

    if (storageSubjectToTariff == true) {
        storage = "Subject to Tariff";
        storageUnit = "N/A";
    } else if (storageSubjectToTariff != true && storageIncluded != true) {
        storage = storageText;
    } else if (storageIncluded == true && storageSubjectToTariff != true) {
        storage = "Included";
    } else if (storageIncluded == true && storageSubjectToTariff == true) {
        JOptionPane.showMessageDialog(null, "You can only select one");
    }

    String sql = "INSERT INTO spotrates (validityFrom, validityTo, tariffNumber, pol, pod, bookingNumber, commClass, handlingInstructions, commDesc, oft, oftUnit, baf, bafIncluded, bafPerTariff, ecaBaf, ecaBafUnit, ecaIncluded, ecaPerTariff, thc, thcUnit,thcIncluded, thcPerTariff, wfg, wfgUnit, wfgIncluded, wfgPerTariff, storage, storageUnit, storageIncluded, storagePerTariff, docFee, docFeeIncluded, comments, quoteID, warRisk) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

    try {
        PreparedStatement ps = CONN.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
        ps.setString(1, validityFrom);
        ps.setString(2, validityTo);
        ps.setString(3, kkluNumber);
        ps.setString(4, pol);
        ps.setString(5, pod);
        ps.setString(6, bookingNumber);
        ps.setString(7, commClass);
        ps.setString(8, handlingInstructions);
        ps.setString(9, commDesc);
        ps.setString(10, oft);
        ps.setString(11, oftUnit);
        ps.setString(12, baf);
        ps.setBoolean(13, bafIncluded);
        ps.setBoolean(14, bafSubjectToTariff);
        ps.setString(15, eca);
        ps.setString(16, ecaUnit);
        ps.setBoolean(17, ecaIncluded);
        ps.setBoolean(18, ecaSubjectToTariff);
        ps.setString(19, thc);
        ps.setString(20, thcUnit);
        ps.setBoolean(21, thcIncluded);
        ps.setBoolean(22, thcSubjectToTariff);
        ps.setString(23, wfg);
        ps.setString(24, wfgUnit);
        ps.setBoolean(25, wfgIncluded);
        ps.setBoolean(26, wfgSubjectToTariff);
        ps.setString(27, storage);
        ps.setString(28, storageUnit);
        ps.setBoolean(29, storageIncluded);
        ps.setBoolean(30, storageSubjectToTariff);
        ps.setString(31, docFee);
        ps.setBoolean(32, docFeeIncluded);
        ps.setString(33, comments);
        ps.setString(34, quoteID);
        ps.setBoolean(35, warRisk);
        // Execute the update
        ps.executeUpdate();

        //Return the auto-generated key
        ResultSet keys = ps.getGeneratedKeys();
        int lastKey = 1;
        while (keys.next()) {
            lastKey = keys.getInt(1);
        }
        int pid = lastKey;

        Double oft1 = (Double) (Double.parseDouble(oft));
        String eca1 = "";
        switch (eca) {
        case "Included":
            eca1 = "Included";
            break;
        case "Subject to Tariff":
            eca1 = "Subject to Tariff";
            break;
        default:
            eca1 = eca;
            break;
        }
        String baf1;
        switch (baf) {
        case "Included":
            baf1 = "Included";
            break;
        case "Subject To Tariff":
            baf1 = "Subject to Tariff";
            break;
        default:
            baf1 = baf;
            break;
        }

        String thc1;

        switch (thc) {
        case "Included":
            thc1 = thc;
            break;
        case "Subject to Tariff":
            thc1 = "Subject to Tariff";
            break;
        default:
            thc1 = "$" + thc + " per " + thcUnit;
            break;
        }

        switch (thcUnit) {
        case "FAS":
            thc1 = thcUnit;
            break;
        case "Subject to local charges":
            thc1 = thcUnit;
        default:
            break;
        }

        String wfg1;
        switch (wfg) {
        case "Included":
            wfg1 = wfg;
            break;
        case "Subject to Tariff":
            wfg1 = "Subject to Tariff";
            break;
        default:
            wfg1 = "$" + wfg + " per " + wfgUnit;
            break;
        }

        switch (wfgUnit) {
        case "FAS":
            wfg1 = wfgUnit;
            break;
        case "Subject to local charges":
            wfg1 = wfgUnit;
        default:
            break;
        }

        /*
         ***************************************
         ***************************************
         ***************************************
         */
        String filename = USER_HOME_FOLDER + "\\Desktop\\Publishing\\" + pol + " To " + pod + "; " + commDesc
                + " PID" + lastKey + ".xls";
        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = workbook.createSheet("KKLU" + kkluNumber);

        sheet.setColumnWidth(0, 650);
        sheet.setColumnWidth(1, 5742);
        sheet.setColumnWidth(2, 5920);
        sheet.setColumnWidth(3, 3668);
        sheet.setColumnWidth(4, 5711);

        //Bold Font
        HSSFFont font = workbook.createFont();
        font.setBold(true);
        CellStyle style = workbook.createCellStyle();
        style.setFont(font);

        //Currency cell type
        CellStyle currency = workbook.createCellStyle();
        currency.setDataFormat((short) 7);

        //Percentage cell type
        CellStyle percentage = workbook.createCellStyle();
        percentage.setDataFormat((short) 0xa);

        sheet.setDisplayGridlines(false);

        //Black medium sized border around cell
        CellStyle blackBorder = workbook.createCellStyle();
        blackBorder.setBorderBottom(CellStyle.BORDER_MEDIUM);
        blackBorder.setBottomBorderColor(IndexedColors.BLACK.getIndex());
        blackBorder.setBorderLeft(CellStyle.BORDER_MEDIUM);
        blackBorder.setLeftBorderColor(IndexedColors.BLACK.getIndex());
        blackBorder.setBorderRight(CellStyle.BORDER_MEDIUM);
        blackBorder.setRightBorderColor(IndexedColors.BLACK.getIndex());
        blackBorder.setBorderTop(CellStyle.BORDER_MEDIUM);
        blackBorder.setTopBorderColor(IndexedColors.BLACK.getIndex());

        //Red font
        CellStyle redFontStyle = workbook.createCellStyle();
        HSSFFont redFont = workbook.createFont();
        redFont.setColor(HSSFColor.RED.index);
        redFontStyle.setFont(redFont);

        HSSFRow rowhead = sheet.createRow((short) 0);
        rowhead.createCell(3).setCellValue(validityFrom);

        HSSFRow row1 = sheet.createRow((short) 1);
        Cell cell = row1.createCell(1);
        cell.setCellValue("FILING REQUEST TO RICLFILE");
        cell.setCellStyle(style);

        sheet.addMergedRegion(new CellRangeAddress(1, 1, 1, 3));

        sheet.setPrintGridlines(false);

        HSSFRow row2 = sheet.createRow((short) 2);
        row2.createCell(0).setCellValue("A)");
        row2.createCell(1).setCellValue("Tariff Number(KKLU):");
        row2.createCell(2).setCellValue(kkluNumber);

        HSSFRow space0 = sheet.createRow((short) 3);

        HSSFRow row4 = sheet.createRow((short) 4);
        row4.createCell(0).setCellValue("B)");
        row4.createCell(1).setCellValue("Commodity:");
        row4.createCell(2).setCellValue(commDesc);

        HSSFRow space2 = sheet.createRow((short) 5);

        HSSFRow row5 = sheet.createRow((short) 6);
        row5.createCell(0).setCellValue("C)");
        row5.createCell(1).setCellValue("POL:");
        row5.createCell(2).setCellValue(pol);

        HSSFRow space3 = sheet.createRow((short) 7);

        HSSFRow row6 = sheet.createRow((short) 8);
        row6.createCell(0).setCellValue("D)");
        row6.createCell(1).setCellValue("POD:");
        row6.createCell(2).setCellValue(pod);

        HSSFRow space4 = sheet.createRow((short) 9);

        HSSFRow row7 = sheet.createRow((short) 10);
        row7.createCell(0).setCellValue("E)");
        row7.createCell(1).setCellValue("Rate:");
        Cell rate = row7.createCell(2);
        rate.setCellValue(oft1);
        rate.setCellStyle(currency);

        HSSFRow space5 = sheet.createRow((short) 11);

        HSSFRow row8 = sheet.createRow((short) 12);
        row8.createCell(0).setCellValue("F)");
        row8.createCell(1).setCellValue("Rate Basis:");
        row8.createCell(2).setCellValue(oftUnit);

        HSSFRow space6 = sheet.createRow((short) 13);

        HSSFRow row9 = sheet.createRow((short) 14);
        row9.createCell(0).setCellValue("G)");
        row9.createCell(1).setCellValue("BAF:");
        Cell Baf = row9.createCell(2);
        switch (baf1) {
        case "Included":
            Baf.setCellValue("Included");
            break;
        case "Subject to Tariff":
            Baf.setCellValue("Subject to Tariff");
            break;
        default:
            Baf.setCellValue(baf1);
            Baf.setCellStyle(percentage);
            break;
        }

        HSSFRow space7 = sheet.createRow((short) 15);

        HSSFRow row10 = sheet.createRow((short) 16);
        row10.createCell(0).setCellValue("H)");
        row10.createCell(1).setCellValue("ECA BAF:");
        Cell ecaBaf = row10.createCell(2);
        switch (eca) {
        case "Included":
            ecaBaf.setCellValue("Included");
            break;
        case "Subject to Tariff":
            ecaBaf.setCellValue("Subject to Tariff");
            break;
        default:
            ecaBaf.setCellValue(eca1 + " per " + ecaUnit);
            ecaBaf.setCellStyle(currency);
            break;
        }

        HSSFRow space8 = sheet.createRow((short) 17);

        HSSFRow row11 = sheet.createRow((short) 18);
        row11.createCell(0).setCellValue("I)");
        row11.createCell(1).setCellValue("THC/WFG:");
        row11.createCell(2).setCellValue(thc1 + " / " + wfg1);

        HSSFRow space = sheet.createRow((short) 19);

        HSSFRow row12 = sheet.createRow((short) 20);
        row12.createCell(0).setCellValue("J)");
        row12.createCell(1).setCellValue("Storage:");
        row12.createCell(2).setCellValue(storage);

        HSSFRow space10 = sheet.createRow((short) 21);

        HSSFRow row13 = sheet.createRow((short) 22);
        row13.createCell(0).setCellValue("K)");
        row13.createCell(1).setCellValue("Doc Fee:");
        row13.createCell(2).setCellValue(docFee);

        HSSFRow space11 = sheet.createRow((short) 23);

        HSSFRow row14 = sheet.createRow((short) 24);
        row14.createCell(0).setCellValue("L)");
        row14.createCell(1).setCellValue("War Risk:");

        HSSFRow space12 = sheet.createRow((short) 25);

        if (warRisk == true) {
            String warRiskPercentage = "3%";
            row14.createCell(2).setCellValue(warRiskPercentage);
        } else if (warRisk != true) {
            String warRiskPercentage = "N/A";
            row14.createCell(2).setCellValue(warRiskPercentage);
        }

        HSSFRow row15 = sheet.createRow((short) 26);
        row15.createCell(0).setCellValue("M)");
        row15.createCell(1).setCellValue("Validity");
        row15.createCell(2).setCellValue("Effective: " + validityFrom);

        HSSFRow row16 = sheet.createRow((short) 27);
        row16.createCell(2).setCellValue("Expiration: " + validityTo);

        HSSFRow space13 = sheet.createRow((short) 28);

        HSSFRow row17 = sheet.createRow((short) 29);
        row17.createCell(0).setCellValue("N)");
        row17.createCell(1).setCellValue("Remarks");
        row17.createCell(2).setCellValue(comments);

        HSSFRow space14 = sheet.createRow((short) 30);

        HSSFRow row18 = sheet.createRow((short) 31);
        row18.createCell(0).setCellValue("O)");
        row18.createCell(1).setCellValue("Booking #:");
        row18.createCell(2).setCellValue(bookingNumber);

        HSSFRow space15 = sheet.createRow((short) 32);

        HSSFRow row19 = sheet.createRow((short) 33);
        row19.createCell(0).setCellValue("P)");
        row19.createCell(1).setCellValue("RQS #:");
        row19.createCell(2).setCellValue(quoteID);

        HSSFRow space16 = sheet.createRow((short) 34);

        HSSFRow row20 = sheet.createRow((short) 35);
        row20.createCell(0).setCellValue("Q)");
        row20.createCell(1).setCellValue("PID #:");
        row20.createCell(2).setCellValue(pid);

        HSSFRow space17 = sheet.createRow((short) 36);

        HSSFRow space18 = sheet.createRow((short) 37);

        HSSFRow row21 = sheet.createRow((short) 38);
        row21.createCell(0).setCellValue("");
        row21.createCell(1).setCellValue("For RICLFILE Use Only");

        HSSFRow space19 = sheet.createRow((short) 39);

        HSSFRow row22 = sheet.createRow((short) 40);
        Cell comm = row22.createCell(1);
        comm.setCellValue("Commodity #:");
        comm.setCellStyle(redFontStyle);
        row22.createCell(2).setCellValue("");
        Cell desc = row22.createCell(3);
        desc.setCellValue("Description:");
        desc.setCellStyle(redFontStyle);
        row22.createCell(4).setCellValue("");

        HSSFRow space20 = sheet.createRow((short) 41);

        HSSFRow row24 = sheet.createRow((short) 42);
        Cell TLI = row24.createCell(1);
        TLI.setCellValue("TLI #:");
        TLI.setCellStyle(redFontStyle);
        row24.createCell(2).setCellValue("");

        HSSFRow space21 = sheet.createRow((short) 43);

        HSSFRow row26 = sheet.createRow((short) 44);
        Cell exp = row26.createCell(1);
        exp.setCellValue("Expiration: ");
        exp.setCellStyle(redFontStyle);
        row26.createCell(2).setCellValue("");

        try (FileOutputStream fileOut = new FileOutputStream(filename)) {
            workbook.write(fileOut);
        }
        System.out.print("Your excel file has been generate");

        String spotRateId = String.valueOf(lastKey);

        JOptionPane.showMessageDialog(null,
                "The spot filing (PID" + spotRateId + ") for " + quoteID + " has been succsefully generated.");
        pQuoteIDTextField.setText("");
        validityFromDatePicker.getJFormattedTextField().setText("");
        validityToDatePicker.getJFormattedTextField().setText("");
        kkluNumberTextField.setText("");
        pPolTextField.setText("");
        pPodTextField.setText("");
        pCommodityClassComboBox.setSelectedIndex(0);
        pHandlingInstructions.setSelectedIndex(0);
        pCommodityDescriptionTextField.setText("");
        pOftTextField.setText("");
        pOftComboBox.setSelectedItem("");
        bafSubjectToTariffCheckBox.setSelected(false);
        pBafTextField.setText("");
        pBafIncludedCheckBox.setSelected(false);
        pEcaTextField.setText("");
        pEcaComboBox.setSelectedIndex(0);
        pEcaIncludedCheckBox.setSelected(false);
        ecaSubjectToTariffCheckBox.setSelected(false);
        pThcTextField.setText("");
        pThcComboBox.setSelectedIndex(0);
        pThcIncludedCheckBox.setSelected(false);
        thcSubjectToTariffCheckBox.setSelected(false);
        pWfgTextField.setText("");
        pWfgComboBox.setSelectedIndex(0);
        pWfgIncludedCheckBox.setSelected(false);
        wfgSubjectToTariffCheckBox.setSelected(false);
        pDocFeeComboBox.setSelectedIndex(0);
        pWarRiskCheckBox.setSelected(false);
        storageSubjectToTariffCheckBox.setSelected(false);
        pCommentsTextArea.setText("");
        pBookingNumberTextField.setText("");
        pQuoteNumberTextField.setText("");
        pIDTextField.setText("");

    } catch (SQLException | IOException e) {
        JOptionPane.showMessageDialog(null, "Error: " + e.getMessage());
        System.out.println(e.getMessage());
    }
}

From source file:Sales.MainMenu.java

private void saveChangesPublishingPDFButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveChangesPublishingPDFButtonActionPerformed
    // Save spot rate changes

    String validityFrom = validityFromDatePicker.getJFormattedTextField().getText();
    String validityTo = validityToDatePicker.getJFormattedTextField().getText();
    String kkluNumber = kkluNumberTextField.getText();
    String pol = pPolTextField.getText();
    String pod = pPodTextField.getText();
    String commClass = pCommodityClassComboBox.getSelectedItem().toString();
    String handlingInstructions = pHandlingInstructions.getSelectedItem().toString();
    String commDesc = pCommodityDescriptionTextField.getText();
    String oft = pOftTextField.getText();
    String oftUnit = pOftComboBox.getSelectedItem().toString();
    String baf = null;//from  ww  w  . java2s . c  om
    String bafText = pBafTextField.getText();
    Boolean bafIncluded = pBafIncludedCheckBox.isSelected();
    String eca = null;
    String ecaText = pEcaTextField.getText();
    String ecaUnit = pEcaComboBox.getSelectedItem().toString();
    Boolean ecaIncluded = pEcaIncludedCheckBox.isSelected();
    String thc = null;
    String thcText = "$" + pThcTextField.getText();
    String thcUnit = pThcComboBox.getSelectedItem().toString();
    Boolean thcIncluded = pThcIncludedCheckBox.isSelected();
    Boolean thcSubjectToTariff = thcSubjectToTariffCheckBox.isSelected();
    String wfg = null;
    String wfgText = pWfgTextField.getText();
    String wfgUnit = pWfgComboBox.getSelectedItem().toString();
    Boolean wfgIncluded = pWfgIncludedCheckBox.isSelected();
    Boolean wfgSubjectToTariff = wfgSubjectToTariffCheckBox.isSelected();
    String docFee = pDocFeeComboBox.getSelectedItem().toString();
    Boolean docFeeIncluded = pDocFeeIncludedCheckBox.isSelected();
    String comments = pCommentsTextArea.getText();
    Boolean warRisk = pWarRiskCheckBox.isSelected();
    String quoteID = pQuoteNumberTextField.getText();
    String bookingNumber = pBookingNumberTextField.getText();
    String storage = null;
    String storageText = storageTextField.getText();
    String storageUnit = storageUnitComboBox.getSelectedItem().toString();
    Boolean storageIncluded = storageIncludedCheckBox.isSelected();
    Boolean storageSubjectToTariff = storageSubjectToTariffCheckBox.isSelected();
    Boolean bafSubjectToTariff = bafSubjectToTariffCheckBox.isSelected();
    Boolean ecaSubjectToTariff = ecaSubjectToTariffCheckBox.isSelected();
    String ID = pQuoteIDTextField.getText();

    String timeStamp = new SimpleDateFormat("MM/dd/yyyy HH:mm").format(Calendar.getInstance().getTime());

    if (bafIncluded != true && bafSubjectToTariff != true) {
        baf = bafText;
    } else if (bafIncluded == true) {
        baf = "Included";
    } else if (bafSubjectToTariff == true) {
        baf = "Subject to Tariff";
    }

    if (ecaIncluded != true && ecaSubjectToTariff != true) {
        eca = ecaText;
    } else if (ecaIncluded == true) {
        eca = "Included";
    } else if (ecaSubjectToTariff == true) {
        eca = "Subject to Tariff";
    } else if (ecaSubjectToTariff == true) {
        eca = "Subject to Tariff";
    }

    if (thcSubjectToTariff == true) {
        thc = "Subject to Tariff";
    } else if (thcSubjectToTariff != true && thcIncluded != true) {
        thc = thcText;
    } else if (thcSubjectToTariff != true && thcIncluded == true) {
        thc = "Included";
    } else if (thcIncluded == true && thcSubjectToTariff == true) {
        JOptionPane.showMessageDialog(null, "You can only select one");
    }

    if (wfgSubjectToTariff == true) {
        wfg = "Subject to Tariff";
        wfgUnit = "N/A";
    } else if (wfgSubjectToTariff != true && wfgIncluded != true) {
        wfg = wfgText;
    } else if (wfgSubjectToTariff != true && wfgIncluded == true) {
        wfg = "Included";
    } else if (wfgIncluded == true && wfgSubjectToTariff == true) {
        JOptionPane.showMessageDialog(null, "You can only select one");
    }

    if (storageSubjectToTariff == true) {
        storage = "Subject to Tariff";
        storageUnit = "N/A";
    } else if (storageSubjectToTariff != true && storageIncluded != true) {
        storage = storageText;
    } else if (storageIncluded == true && storageSubjectToTariff != true) {
        storage = "Included";
    } else if (storageIncluded == true && storageSubjectToTariff == true) {
        JOptionPane.showMessageDialog(null, "You can only select one");
    }

    String sql = "UPDATE spotrates SET validityFrom=?, validityTo=?, tariffNumber=?, pol=?, pod=?, bookingNumber=?, commClass=?, handlingInstructions=?, commDesc=?, oft=?, oftUnit=?, baf=?,bafIncluded=?, bafPerTariff=?, ecaBaf=?, ecaBafUnit=?, ecaIncluded=?, ecaPerTariff=?, thc=?, thcUnit=?, thcIncluded=?, thcPerTariff=?, wfg=?, wfgUnit=?, wfgIncluded=?, wfgPerTariff=?, storage=?, storageUnit=?, storageIncluded=?, storagePerTariff=?, docFee=?, docFeeIncluded=?, comments=?, quoteID=?, warRisk=? WHERE ID=?";

    try {
        PreparedStatement ps = CONN.prepareStatement(sql);
        ps.setString(1, validityFrom);
        ps.setString(2, validityTo);
        ps.setString(3, kkluNumber);
        ps.setString(4, pol);
        ps.setString(5, pod);
        ps.setString(6, bookingNumber);
        ps.setString(7, commClass);
        ps.setString(8, handlingInstructions);
        ps.setString(9, commDesc);
        ps.setString(10, oft);
        ps.setString(11, oftUnit);
        ps.setString(12, baf);
        ps.setBoolean(13, bafIncluded);
        ps.setBoolean(14, bafSubjectToTariff);
        ps.setString(15, eca);
        ps.setString(16, ecaUnit);
        ps.setBoolean(17, ecaIncluded);
        ps.setBoolean(18, ecaSubjectToTariff);
        ps.setString(19, thc);
        ps.setString(20, thcUnit);
        ps.setBoolean(21, thcIncluded);
        ps.setBoolean(22, thcSubjectToTariff);
        ps.setString(23, wfg);
        ps.setString(24, wfgUnit);
        ps.setBoolean(25, wfgIncluded);
        ps.setBoolean(26, wfgSubjectToTariff);
        ps.setString(27, storage);
        ps.setString(28, storageUnit);
        ps.setBoolean(29, storageIncluded);
        ps.setBoolean(30, storageSubjectToTariff);
        ps.setString(31, docFee);
        ps.setBoolean(32, docFeeIncluded);
        ps.setString(33, comments);
        ps.setString(34, quoteID);
        ps.setBoolean(35, warRisk);
        ps.setString(40, ID);

        ps.executeUpdate();

        String addBookingNumber = "UPDATE allquotes SET bookingNumber='" + bookingNumber + "', publishingID='"
                + ID + "' WHERE ID='" + quoteID + "';";
        PreparedStatement psAddBookingNumber = CONN.prepareStatement(addBookingNumber);
        psAddBookingNumber.executeUpdate(addBookingNumber);

        Double oft1 = (Double) (Double.parseDouble(oft));
        String eca1 = "";
        switch (eca) {
        case "Included":
            eca1 = "Included";
            break;
        case "Subject to Tariff":
            eca1 = "Subject to Tariff";
            break;
        default:
            eca1 = "$" + eca + " " + ecaUnit;
            break;
        }
        String baf1;
        switch (baf) {
        case "Included":
            baf1 = "Included";
            break;
        case "Subject To Tariff":
            baf1 = "Subject to Tariff";
            break;
        default:
            baf1 = baf + "%";
            break;
        }

        String thc1;

        switch (thc) {
        case "Included":
            thc1 = thc;
            break;
        case "Subject to Tariff":
            thc1 = "Subject to Tariff";
            break;
        default:
            thc1 = "$" + thc + " per " + thcUnit;
            break;
        }

        switch (thcUnit) {
        case "FAS":
            thc1 = thcUnit;
            break;
        case "Subject to local charges":
            thc1 = thcUnit;
        default:
            break;
        }

        String wfg1;
        switch (wfg) {
        case "Included":
            wfg1 = wfg;
            break;
        case "Subject to Tariff":
            wfg1 = "Subject to Tariff";
            break;
        default:
            wfg1 = "$" + wfg + " per " + wfgUnit;
            break;
        }

        switch (wfgUnit) {
        case "FAS":
            wfg1 = wfgUnit;
            break;
        case "Subject to local charges":
            wfg1 = wfgUnit;
        default:
            break;
        }

        /*
         ***************************************
         ***************************************
         ***************************************
         */
        String filename = USER_HOME_FOLDER + "\\Desktop\\Publishing\\" + pol + " To " + pod + "; " + commDesc
                + " PID" + ID + ".xls";
        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = workbook.createSheet("KKLU" + kkluNumber);

        sheet.setColumnWidth(0, 650);
        sheet.setColumnWidth(1, 5742);
        sheet.setColumnWidth(2, 5920);
        sheet.setColumnWidth(3, 3668);
        sheet.setColumnWidth(4, 5711);

        //Bold Font
        HSSFFont font = workbook.createFont();
        font.setBold(true);
        CellStyle style = workbook.createCellStyle();
        style.setFont(font);

        //Currency cell type
        CellStyle currency = workbook.createCellStyle();
        currency.setDataFormat((short) 7);

        //Percentage cell type
        CellStyle percentage = workbook.createCellStyle();
        percentage.setDataFormat((short) 0xa);

        sheet.setDisplayGridlines(false);

        //Black medium sized border around cell
        CellStyle blackBorder = workbook.createCellStyle();
        blackBorder.setBorderBottom(CellStyle.BORDER_MEDIUM);
        blackBorder.setBottomBorderColor(IndexedColors.BLACK.getIndex());
        blackBorder.setBorderLeft(CellStyle.BORDER_MEDIUM);
        blackBorder.setLeftBorderColor(IndexedColors.BLACK.getIndex());
        blackBorder.setBorderRight(CellStyle.BORDER_MEDIUM);
        blackBorder.setRightBorderColor(IndexedColors.BLACK.getIndex());
        blackBorder.setBorderTop(CellStyle.BORDER_MEDIUM);
        blackBorder.setTopBorderColor(IndexedColors.BLACK.getIndex());

        //Red font
        CellStyle redFontStyle = workbook.createCellStyle();
        HSSFFont redFont = workbook.createFont();
        redFont.setColor(HSSFColor.RED.index);
        redFontStyle.setFont(redFont);

        HSSFRow rowhead = sheet.createRow((short) 0);
        rowhead.createCell(3).setCellValue(validityFrom);

        HSSFRow row1 = sheet.createRow((short) 1);
        Cell cell = row1.createCell(1);
        cell.setCellValue("FILING REQUEST TO RICLFILE");
        cell.setCellStyle(style);

        sheet.addMergedRegion(new CellRangeAddress(1, 1, 1, 3));

        sheet.setPrintGridlines(false);

        HSSFRow row2 = sheet.createRow((short) 2);
        row2.createCell(0).setCellValue("A)");
        row2.createCell(1).setCellValue("Tariff Number(KKLU):");
        row2.createCell(2).setCellValue(kkluNumber);

        HSSFRow space0 = sheet.createRow((short) 3);

        HSSFRow row4 = sheet.createRow((short) 4);
        row4.createCell(0).setCellValue("B)");
        row4.createCell(1).setCellValue("Commodity:");
        row4.createCell(2).setCellValue(commDesc);

        HSSFRow space2 = sheet.createRow((short) 5);

        HSSFRow row5 = sheet.createRow((short) 6);
        row5.createCell(0).setCellValue("C)");
        row5.createCell(1).setCellValue("POL:");
        row5.createCell(2).setCellValue(pol);

        HSSFRow space3 = sheet.createRow((short) 7);

        HSSFRow row6 = sheet.createRow((short) 8);
        row6.createCell(0).setCellValue("D)");
        row6.createCell(1).setCellValue("POD:");
        row6.createCell(2).setCellValue(pod);

        HSSFRow space4 = sheet.createRow((short) 9);

        HSSFRow row7 = sheet.createRow((short) 10);
        row7.createCell(0).setCellValue("E)");
        row7.createCell(1).setCellValue("Rate:");
        Cell rate = row7.createCell(2);
        rate.setCellValue(oft1);
        rate.setCellStyle(currency);

        HSSFRow space5 = sheet.createRow((short) 11);

        HSSFRow row8 = sheet.createRow((short) 12);
        row8.createCell(0).setCellValue("F)");
        row8.createCell(1).setCellValue("Rate Basis:");
        row8.createCell(2).setCellValue(oftUnit);

        HSSFRow space6 = sheet.createRow((short) 13);

        HSSFRow row9 = sheet.createRow((short) 14);
        row9.createCell(0).setCellValue("G)");
        row9.createCell(1).setCellValue("BAF:");
        Cell Baf = row9.createCell(2);
        switch (baf1) {
        case "Included":
            Baf.setCellValue("Included");
            break;
        case "Subject to Tariff":
            Baf.setCellValue("Subject to Tariff");
            break;
        default:
            Baf.setCellValue(baf1);
            break;
        }

        HSSFRow space7 = sheet.createRow((short) 15);

        HSSFRow row10 = sheet.createRow((short) 16);
        row10.createCell(0).setCellValue("H)");
        row10.createCell(1).setCellValue("ECA BAF:");
        Cell ecaBaf = row10.createCell(2);
        switch (eca) {
        case "Included":
            ecaBaf.setCellValue("Included");
            break;
        case "Subject to Tariff":
            ecaBaf.setCellValue("Subject to Tariff");
            break;
        default:
            ecaBaf.setCellValue("$" + eca1 + " per " + ecaUnit);
            ecaBaf.setCellStyle(currency);
            break;
        }

        HSSFRow space8 = sheet.createRow((short) 17);

        HSSFRow row11 = sheet.createRow((short) 18);
        row11.createCell(0).setCellValue("I)");
        row11.createCell(1).setCellValue("THC/WFG:");
        row11.createCell(2).setCellValue(thc1 + " / " + wfg1);

        HSSFRow space = sheet.createRow((short) 19);

        HSSFRow row12 = sheet.createRow((short) 20);
        row12.createCell(0).setCellValue("J)");
        row12.createCell(1).setCellValue("Storage:");
        row12.createCell(2).setCellValue(storage);

        HSSFRow space10 = sheet.createRow((short) 21);

        HSSFRow row13 = sheet.createRow((short) 22);
        row13.createCell(0).setCellValue("K)");
        row13.createCell(1).setCellValue("Doc Fee:");
        row13.createCell(2).setCellValue(docFee);

        HSSFRow space11 = sheet.createRow((short) 23);

        HSSFRow row14 = sheet.createRow((short) 24);
        row14.createCell(0).setCellValue("L)");
        row14.createCell(1).setCellValue("War Risk:");

        HSSFRow space12 = sheet.createRow((short) 25);

        if (warRisk == true) {
            String warRiskPercentage = "3%";
            row14.createCell(2).setCellValue(warRiskPercentage);
        } else if (warRisk != true) {
            String warRiskPercentage = "N/A";
            row14.createCell(2).setCellValue(warRiskPercentage);
        }

        HSSFRow row15 = sheet.createRow((short) 26);
        row15.createCell(0).setCellValue("M)");
        row15.createCell(1).setCellValue("Validity");
        row15.createCell(2).setCellValue("Effective: " + validityFrom);

        HSSFRow row16 = sheet.createRow((short) 27);
        row16.createCell(2).setCellValue("Expiration: " + validityTo);

        HSSFRow space13 = sheet.createRow((short) 28);

        HSSFRow row17 = sheet.createRow((short) 29);
        row17.createCell(0).setCellValue("N)");
        row17.createCell(1).setCellValue("Remarks");
        row17.createCell(2).setCellValue(comments);

        HSSFRow space14 = sheet.createRow((short) 30);

        HSSFRow row18 = sheet.createRow((short) 31);
        row18.createCell(0).setCellValue("O)");
        row18.createCell(1).setCellValue("Booking #:");
        row18.createCell(2).setCellValue(bookingNumber);

        HSSFRow space15 = sheet.createRow((short) 32);

        HSSFRow row19 = sheet.createRow((short) 33);
        row19.createCell(0).setCellValue("P)");
        row19.createCell(1).setCellValue("RQS #:");
        row19.createCell(2).setCellValue(quoteID);

        HSSFRow space16 = sheet.createRow((short) 34);

        HSSFRow row20 = sheet.createRow((short) 35);
        row20.createCell(0).setCellValue("Q)");
        row20.createCell(1).setCellValue("PID #:");
        row20.createCell(2).setCellValue(ID);

        HSSFRow space17 = sheet.createRow((short) 36);

        HSSFRow space18 = sheet.createRow((short) 37);

        HSSFRow row21 = sheet.createRow((short) 38);
        row21.createCell(0).setCellValue("");
        row21.createCell(1).setCellValue("For RICLFILE Use Only");

        HSSFRow space19 = sheet.createRow((short) 39);

        HSSFRow row22 = sheet.createRow((short) 40);
        Cell comm = row22.createCell(1);
        comm.setCellValue("Commodity #:");
        comm.setCellStyle(redFontStyle);
        row22.createCell(2).setCellValue("");
        Cell desc = row22.createCell(3);
        desc.setCellValue("Description:");
        desc.setCellStyle(redFontStyle);
        row22.createCell(4).setCellValue("");

        HSSFRow space20 = sheet.createRow((short) 41);

        HSSFRow row24 = sheet.createRow((short) 42);
        Cell TLI = row24.createCell(1);
        TLI.setCellValue("TLI #:");
        TLI.setCellStyle(redFontStyle);
        row24.createCell(2).setCellValue("");

        HSSFRow space21 = sheet.createRow((short) 43);

        HSSFRow row26 = sheet.createRow((short) 44);
        Cell exp = row26.createCell(1);
        exp.setCellValue("Expiration: ");
        exp.setCellStyle(redFontStyle);
        row26.createCell(2).setCellValue("");

        try (FileOutputStream fileOut = new FileOutputStream(filename)) {
            workbook.write(fileOut);
        }
        System.out.print("Your excel file has been generate");

        String spotRateId = String.valueOf(ID);

        JOptionPane.showMessageDialog(null, "PID" + ID + " has been successfully update.");
        pQuoteIDTextField.setText("");
        validityFromDatePicker.getJFormattedTextField().setText("");
        validityToDatePicker.getJFormattedTextField().setText("");
        kkluNumberTextField.setText("");
        pPolTextField.setText("");
        pPodTextField.setText("");
        pCommodityClassComboBox.setSelectedIndex(0);
        pHandlingInstructions.setSelectedIndex(0);
        pCommodityDescriptionTextField.setText("");
        pOftTextField.setText("");
        pOftComboBox.setSelectedItem("");
        bafSubjectToTariffCheckBox.setSelected(false);
        pBafTextField.setText("");
        pBafIncludedCheckBox.setSelected(false);
        pEcaTextField.setText("");
        pEcaComboBox.setSelectedItem("");
        pEcaIncludedCheckBox.setSelected(false);
        ecaSubjectToTariffCheckBox.setSelected(false);
        pThcTextField.setText("");
        pThcComboBox.setSelectedIndex(0);
        pThcIncludedCheckBox.setSelected(false);
        thcSubjectToTariffCheckBox.setSelected(false);
        pWfgTextField.setText("");
        pWfgComboBox.setSelectedIndex(0);
        pWfgIncludedCheckBox.setSelected(false);
        wfgSubjectToTariffCheckBox.setSelected(false);
        pDocFeeComboBox.setSelectedIndex(0);
        pWarRiskCheckBox.setSelected(false);
        storageSubjectToTariffCheckBox.setSelected(false);
        pCommentsTextArea.setText("");
        pBookingNumberTextField.setText("");
        storageTextField.setText("");
        storageUnitComboBox.setSelectedIndex(0);
        storageIncludedCheckBox.setSelected(false);
        pQuoteNumberTextField.setText("");
        pIDTextField.setText("");

    } catch (SQLException | IOException e) {
        JOptionPane.showMessageDialog(null, "Error: " + e.getMessage());
        System.out.println(e.getMessage());
    }
}

From source file:se.mithlond.services.content.impl.ejb.report.ExcelReportServiceBean.java

License:Apache License

/**
 * {@inheritDoc}//  w  ww.  j a  v a 2s.  c  om
 */
@Override
@SuppressWarnings("all")
public CellStyle getCellStyle(final ExcelElement el, final Workbook workbook) {

    // Check sanity
    Validate.notNull(workbook, "workbook");
    Validate.notNull(el, "el");

    // Acquire the el and Font as expected
    final CellStyle toReturn = workbook.createCellStyle();
    final Font theFont = workbook.createFont();

    switch (el) {

    case TITLE:
        theFont.setFontHeightInPoints((short) 18);
        theFont.setBold(true);
        theFont.setColor(IndexedColors.BLUE_GREY.getIndex());

        toReturn.setAlignment(HorizontalAlignment.CENTER);
        toReturn.setVerticalAlignment(VerticalAlignment.CENTER);
        break;

    case HEADER:
        theFont.setFontHeightInPoints((short) 11);
        theFont.setColor(IndexedColors.WHITE.getIndex());

        toReturn.setAlignment(HorizontalAlignment.CENTER);
        toReturn.setVerticalAlignment(VerticalAlignment.CENTER);
        toReturn.setFillForegroundColor(IndexedColors.BLUE_GREY.getIndex());
        toReturn.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        toReturn.setWrapText(true);
        break;

    case CELL:

        toReturn.setAlignment(HorizontalAlignment.LEFT);
        toReturn.setWrapText(true);
        toReturn.setBorderRight(BORDER_THIN);
        toReturn.setRightBorderColor(GREY_25_PERCENT);
        toReturn.setBorderLeft(BORDER_THIN);
        toReturn.setLeftBorderColor(GREY_25_PERCENT);
        toReturn.setBorderTop(BORDER_THIN);
        toReturn.setTopBorderColor(GREY_25_PERCENT);
        toReturn.setBorderBottom(BORDER_THIN);
        toReturn.setBottomBorderColor(GREY_25_PERCENT);
        break;

    case NON_WRAPPING:
        toReturn.setAlignment(HorizontalAlignment.LEFT);
        toReturn.setWrapText(false);
        toReturn.setBorderRight(BORDER_THIN);
        toReturn.setRightBorderColor(GREY_25_PERCENT);
        toReturn.setBorderLeft(BORDER_THIN);
        toReturn.setLeftBorderColor(GREY_25_PERCENT);
        toReturn.setBorderTop(BORDER_THIN);
        toReturn.setTopBorderColor(GREY_25_PERCENT);
        toReturn.setBorderBottom(BORDER_THIN);
        toReturn.setBottomBorderColor(GREY_25_PERCENT);
        break;

    case FORMULA:
        toReturn.setAlignment(HorizontalAlignment.CENTER);
        toReturn.setVerticalAlignment(VerticalAlignment.CENTER);
        toReturn.setFillForegroundColor(GREY_25_PERCENT);
        toReturn.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        toReturn.setDataFormat(workbook.createDataFormat().getFormat("0.00"));
        break;

    case ALT_FORMULA:
        toReturn.setAlignment(HorizontalAlignment.CENTER);
        toReturn.setVerticalAlignment(VerticalAlignment.CENTER);
        toReturn.setFillForegroundColor(IndexedColors.GREY_40_PERCENT.getIndex());
        toReturn.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        toReturn.setDataFormat(workbook.createDataFormat().getFormat("0.00"));
        break;

    default:
        throw new IllegalArgumentException(
                "Style [" + el.name() + "] was not defined. " + "Blame the programmer.");
    }

    // All done.
    toReturn.setFont(theFont);
    return toReturn;
}

From source file:servlet.exportScoreSheet.java

private static Map<String, CellStyle> createStyles(Workbook wb) {
    Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
    CellStyle style;
    Font titleFont = wb.createFont();
    titleFont.setFontHeightInPoints((short) 18);
    titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    style = wb.createCellStyle();/*  w w w.ja  va 2s  .  c o m*/
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFont(titleFont);
    styles.put("title", style);

    Font monthFont = wb.createFont();
    monthFont.setFontHeightInPoints((short) 11);
    monthFont.setColor(IndexedColors.WHITE.getIndex());
    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setFont(monthFont);
    style.setWrapText(true);
    styles.put("header", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setWrapText(true);
    style.setBorderRight(CellStyle.BORDER_THIN);
    style.setRightBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderLeft(CellStyle.BORDER_THIN);
    style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderTop(CellStyle.BORDER_THIN);
    style.setTopBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderBottom(CellStyle.BORDER_THIN);
    style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
    styles.put("cell", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setDataFormat(wb.createDataFormat().getFormat("0.00"));
    styles.put("formula", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFillForegroundColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setDataFormat(wb.createDataFormat().getFormat("0.00"));
    styles.put("formula_2", style);

    return styles;
}

From source file:standarapp.algorithm.ReadFileVector.java

public String lectureRegistry(String nameFile, String nameOut, int[] col, double percent, int rowBegin) {
    String answer = "";
    int quantityFound = 0;

    workbook = Lecture.lectureXLSX(nameFile);
    sheet = workbook.getSheetAt(0);//from w ww .j a  v  a2  s. c o m

    for (Row row : sheet) {
        if (row.getRowNum() < rowBegin) {
            continue;
        }

        String[] cellsWI = new String[col.length + 1];
        for (int i = 0; i < col.length; i++) {
            cellsWI[i] = "";
            try {
                Cell cell = row.getCell(col[i]);
                if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
                    cellsWI[i] = deleteTrash(cell.getStringCellValue());
                } else {
                    cellsWI[i] = cell.getDateCellValue().toString();
                    cellsWI[col.length] = String.valueOf(cell.getDateCellValue().getMonth());
                }
                if (i == 2) {
                    cellsWI[i] = cell.getStringCellValue();
                }
            } catch (Exception e) {
            }
        }
        registry.add(cellsWI);
    }

    System.out.println("Total: " + registry.size());
    /*for (int i = 0; i < registry.size(); i++) {
    System.out.println(i +" Municipio: " + registry.get(i)[0] + " | Localidad: " + registry.get(i)[1] + " | Especie: " + registry.get(i)[2] + " | Fecha: " + registry.get(i)[3]);
    }*/

    int rowCount = 0;
    int columnCount = 0;

    CellStyle cs = workbook.createCellStyle();
    //Font font = workbook.createFont();
    cs.setAlignment(HorizontalAlignment.CENTER);
    cs.setVerticalAlignment(VerticalAlignment.CENTER);
    cs.setBorderRight(BorderStyle.THIN);
    cs.setBorderLeft(BorderStyle.THIN);
    cs.setBorderBottom(BorderStyle.THIN);
    cs.setBorderTop(BorderStyle.THIN);

    sheet = workbook.createSheet();
    sheet.setFitToPage(true);
    sheet.setHorizontallyCenter(true);
    sheet.setColumnWidth(0, 20);

    Row row = sheet.createRow(0);
    Cell encabezado = row.createCell(rowCount);
    encabezado.setCellValue("Base de  datos coordenadas");
    encabezado.setCellStyle(cs);

    CellRangeAddress region = new CellRangeAddress(0, 0, 0, 8);
    sheet.addMergedRegion(region);

    row = sheet.createRow(++rowCount);
    Cell cell = row.createCell(columnCount);
    cell.setCellValue("Especie");
    cell.setCellStyle(cs);
    cell = row.createCell(++columnCount);
    cell.setCellValue("Municipio");
    cell.setCellStyle(cs);
    cell = row.createCell(++columnCount);
    cell.setCellValue("Codigo Municipio");
    cell.setCellStyle(cs);
    cell = row.createCell(++columnCount);
    cell.setCellValue("Vereda");
    cell.setCellStyle(cs);
    cell = row.createCell(++columnCount);
    cell.setCellValue("Codigo Vereda");
    cell.setCellStyle(cs);
    cell = row.createCell(++columnCount);
    cell.setCellValue("Mes");
    cell.setCellStyle(cs);
    cell = row.createCell(++columnCount);
    cell.setCellValue("Ao");
    cell.setCellStyle(cs);
    cell = row.createCell(++columnCount);
    cell.setCellValue("Latitud");
    cell.setCellStyle(cs);
    cell = row.createCell(++columnCount);
    cell.setCellValue("Longitud");
    cell.setCellStyle(cs);
    cell = row.createCell(++columnCount);
    cell.setCellValue("Fuente");
    cell.setCellStyle(cs);

    for (int i = 0; i < registry.size(); i++) {
        try {
            String[] registro = registry.get(i);
            columnCount = -1;
            int cod_Mncp = 0;
            row = sheet.createRow(++rowCount);
            double levenstein = 0;
            double localidad_oficial = 0;
            double levensteinActual = 0;

            for (Integer codMunicipio : codigo_Municipio.keySet()) {
                if (registro[0].equals(codigo_Municipio.get(codMunicipio))) {
                    cod_Mncp = codMunicipio;
                    break;
                }

                try {
                    double levenstein_local = FuzzySearch.ratio(registro[0],
                            codigo_Municipio.get(codMunicipio));
                    if (levenstein_local >= levensteinActual) {
                        cod_Mncp = codMunicipio;
                        levensteinActual = levenstein_local;
                    }

                    if (levensteinActual == 100) {
                        break;
                    }
                } catch (Exception e) {
                }
            }

            for (Double cod_Loc : mncp_localidad.get(cod_Mncp).keySet()) {
                String loc = mncp_localidad.get(cod_Mncp).get(cod_Loc);

                if (registro[1].equals(loc)) {
                    localidad_oficial = cod_Loc;
                    levenstein = 101;
                }

                try {
                    double levenstein_local = FuzzySearch.ratio(registro[1], loc);
                    if (levenstein_local >= levenstein) {
                        localidad_oficial = cod_Loc;
                        levenstein = levenstein_local;
                    }

                    if (levenstein == 100) {
                        break;
                    }

                } catch (Exception e) {
                }
            }

            String mncp_oficial = codigo_Municipio.get(cod_Mncp);
            String loc_oficial = codigo_localidad.get(localidad_oficial);
            String especie = registro[2];
            double locX = localidad_x.get(localidad_oficial);
            double locY = localidad_y.get(localidad_oficial);
            int year = 0;
            int month = 0;
            System.out.println();
            try {
                year = Integer.parseInt(registro[3].split(" ")[5]);
                month = Integer.parseInt(registro[registro.length - 1]) + 1;
            } catch (Exception e) {
                year = Integer.parseInt(registro[3].substring(registro[3].length() - 4));
                month = Integer
                        .parseInt(registro[3].substring(registro[3].length() - 7, registro[3].length() - 5));
            }

            quantityFound++;

            cell = row.createCell(++columnCount);
            cell.setCellValue(especie);
            cell.setCellStyle(cs);
            cell = row.createCell(++columnCount);
            cell.setCellValue(mncp_oficial);
            cell.setCellStyle(cs);
            cell = row.createCell(++columnCount);
            cell.setCellValue(cod_Mncp);
            cell.setCellStyle(cs);
            cell = row.createCell(++columnCount);
            cell.setCellValue(loc_oficial);
            cell.setCellStyle(cs);
            cell = row.createCell(++columnCount);
            cell.setCellValue(localidad_oficial);
            cell.setCellStyle(cs);
            cell = row.createCell(++columnCount);
            cell.setCellValue(month);
            cell.setCellStyle(cs);
            cell = row.createCell(++columnCount);
            cell.setCellValue(year);
            cell.setCellStyle(cs);
            cell = row.createCell(++columnCount);
            cell.setCellValue(locY);
            cell.setCellStyle(cs);
            cell = row.createCell(++columnCount);
            cell.setCellValue(locX);
            cell.setCellStyle(cs);
        } catch (Exception e) {
            continue;
        }
    }

    sheet.setColumnWidth(0, 5800);
    sheet.setColumnWidth(1, 5800);
    sheet.setColumnWidth(2, 3000);
    sheet.setColumnWidth(3, 5800);
    sheet.setColumnWidth(4, 3000);
    sheet.setColumnWidth(5, 3000);
    sheet.setColumnWidth(6, 3000);
    sheet.setColumnWidth(7, 6400);
    sheet.setColumnWidth(8, 6400);

    answer = "Se generaron " + quantityFound + " vector(es)";
    try (FileOutputStream outputStream = new FileOutputStream(nameOut)) {
        workbook.write(outputStream);
    } catch (IOException ex) {
        quantityFound = 0;
        answer = "Cerrar el archivo de entrada ";
    }
    return answer;
}

From source file:test.poi.MyExcelDemo.java

License:Apache License

/**
 * Create a library of cell styles/* w  w  w .j av a  2s.  c o  m*/
 */
private static Map<String, CellStyle> createStyles(Workbook wb) {
    Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
    CellStyle style;
    Font titleFont = wb.createFont();
    titleFont.setFontHeightInPoints((short) 18);
    titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFont(titleFont);
    styles.put("title", style);

    Font headerFont = wb.createFont();
    headerFont.setFontHeightInPoints((short) 11);
    headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    headerFont.setColor(IndexedColors.BLACK.getIndex());
    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFillForegroundColor(IndexedColors.WHITE.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setFont(headerFont);
    //        style.setWrapText(true);
    style.setBorderRight(CellStyle.BORDER_THIN);
    style.setRightBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderLeft(CellStyle.BORDER_THIN);
    style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderTop(CellStyle.BORDER_THIN);
    style.setTopBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderBottom(CellStyle.BORDER_THIN);
    style.setBottomBorderColor(IndexedColors.BLACK.getIndex());

    styles.put("header", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setWrapText(true);
    style.setBorderRight(CellStyle.BORDER_THIN);
    style.setRightBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderLeft(CellStyle.BORDER_THIN);
    style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderTop(CellStyle.BORDER_THIN);
    style.setTopBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderBottom(CellStyle.BORDER_THIN);
    style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
    styles.put("cell", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setDataFormat(wb.createDataFormat().getFormat("0.00"));
    styles.put("formula", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFillForegroundColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setDataFormat(wb.createDataFormat().getFormat("0.00"));
    styles.put("formula_2", style);

    return styles;
}

From source file:util.ExcelConverter.java

public static File createXlsx(String[] header, String[][] data, String path) {

    try {//w  w  w. jav a 2s  . c o  m
        XSSFWorkbook xwb = new XSSFWorkbook();
        XSSFSheet sheet = xwb.createSheet();

        CellStyle cellStyle = xwb.createCellStyle();
        cellStyle.setAlignment(CellStyle.ALIGN_LEFT);
        cellStyle.setAlignment(CellStyle.VERTICAL_TOP);
        cellStyle.setBorderBottom(XSSFCellStyle.BORDER_THIN);
        cellStyle.setBorderTop(XSSFCellStyle.BORDER_THIN);
        cellStyle.setBorderRight(XSSFCellStyle.BORDER_THIN);
        cellStyle.setBorderLeft(XSSFCellStyle.BORDER_THIN);
        cellStyle.setWrapText(false);

        Font bold = xwb.createFont();
        bold.setBoldweight(Font.BOLDWEIGHT_BOLD);
        bold.setFontHeightInPoints((short) 10);

        CellStyle cellStyleHeader = xwb.createCellStyle();
        cellStyleHeader.setAlignment(CellStyle.ALIGN_LEFT);
        cellStyleHeader.setAlignment(CellStyle.VERTICAL_TOP);
        cellStyleHeader.setBorderBottom(XSSFCellStyle.BORDER_THIN);
        cellStyleHeader.setBorderTop(XSSFCellStyle.BORDER_THIN);
        cellStyleHeader.setBorderRight(XSSFCellStyle.BORDER_THIN);
        cellStyleHeader.setBorderLeft(XSSFCellStyle.BORDER_THIN);
        cellStyleHeader.setFont(bold);
        cellStyleHeader.setWrapText(false);

        XSSFRow row;
        Cell cell;

        //header
        row = sheet.createRow(0);
        for (int i = 0; i < header.length; i++) {
            cell = row.createCell(i);
            cell.setCellStyle(cellStyleHeader);
            cell.setCellValue(header[i]);
        }

        int colCount = header.length;
        int no = 1;

        for (String[] obj : data) {
            row = sheet.createRow(no);
            for (int i = 0; i < colCount; i++) {
                cell = row.createCell(i);
                cell.setCellStyle(cellStyle);
                cell.setCellValue(obj[i]);
            }
            no++;
        }

        for (int i = 0; i < header.length; i++) {
            sheet.autoSizeColumn(i);
        }

        File newFile = new File(path);
        try (FileOutputStream fileOut = new FileOutputStream(path)) {
            xwb.write(fileOut);
        }

        return newFile;
    } catch (IOException e) {
        return null;
    }
}

From source file:util.ExcelConverter.java

public static File createXls(String[] header, String[][] data, String path) {

    try {//from  ww w  .j  a v a  2  s . c o m
        HSSFWorkbook xwb = new HSSFWorkbook();
        HSSFSheet sheet = xwb.createSheet();

        CellStyle cellStyle = xwb.createCellStyle();
        cellStyle.setAlignment(CellStyle.ALIGN_LEFT);
        cellStyle.setAlignment(CellStyle.VERTICAL_TOP);
        cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
        cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
        cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        cellStyle.setWrapText(false);

        Font bold = xwb.createFont();
        bold.setBoldweight(Font.BOLDWEIGHT_BOLD);
        bold.setFontHeightInPoints((short) 10);

        CellStyle cellStyleHeader = xwb.createCellStyle();
        cellStyleHeader.setAlignment(CellStyle.ALIGN_LEFT);
        cellStyleHeader.setAlignment(CellStyle.VERTICAL_TOP);
        cellStyleHeader.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        cellStyleHeader.setBorderTop(HSSFCellStyle.BORDER_THIN);
        cellStyleHeader.setBorderRight(HSSFCellStyle.BORDER_THIN);
        cellStyleHeader.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        cellStyleHeader.setFont(bold);
        cellStyleHeader.setWrapText(false);

        HSSFRow row;
        Cell cell;

        //header
        row = sheet.createRow(0);
        for (int i = 0; i < header.length; i++) {
            cell = row.createCell(i);
            cell.setCellStyle(cellStyleHeader);
            cell.setCellValue(header[i]);
        }

        int colCount = header.length;
        int no = 1;

        for (String[] obj : data) {
            row = sheet.createRow(no);
            for (int i = 0; i < colCount; i++) {
                cell = row.createCell(i);
                cell.setCellStyle(cellStyle);
                cell.setCellValue(obj[i]);
            }
            no++;
        }

        for (int i = 0; i < header.length; i++) {
            sheet.autoSizeColumn(i);
        }

        File newFile = new File(path);
        try (FileOutputStream fileOut = new FileOutputStream(newFile)) {
            xwb.write(fileOut);
        }

        return newFile;
    } catch (IOException e) {
        return null;
    }
}