Example usage for org.apache.poi.ss.usermodel Workbook getSheetAt

List of usage examples for org.apache.poi.ss.usermodel Workbook getSheetAt

Introduction

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

Prototype

Sheet getSheetAt(int index);

Source Link

Document

Get the Sheet object at the given index.

Usage

From source file:com.coast.controler.Controler.java

public static void writeProductsToExcel(ArrayList<Product> products, String inFile, String outFile,
        ResultMSG resultMSG) throws Exception {
    int sum = 0;/*from  w w w. j av a 2  s.c o m*/
    InputStream is = null;
    OutputStream os = null;
    try {
        File f = new File(outFile);
        f.delete();
        is = new FileInputStream(new File(inFile));
        Workbook wb = WorkbookFactory.create(is);
        Sheet sheet = wb.getSheetAt(0);
        String brand = null;
        Iterator<Product> iter = products.iterator();
        while (iter.hasNext()) {
            Product product = iter.next();
            ProductToSAPUtil sapUtil = new ProductToSAPUtil(product);

            //
            if (product.getSnCode().equals("K630207E00")) {
                System.out.println("error:" + product);
            }
            String fullSize = product.getSize() + "(" + sapUtil.getInternationalSize() + ")";
            int thatRowNum = getRowNum(sheet, product.getSnCode(), product.getColorCode(), fullSize);
            if (thatRowNum == 0) {
                String notFoundMsg = "SAP?sn=" + product.getSnCode() + " color="
                        + product.getColorCode() + " size=" + fullSize + " amount=" + product.getAmount()
                        + "\n";
                resultMSG.setErrorMessage(resultMSG.getErrorMessage() + notFoundMsg);
            } else {
                sheet.getRow(thatRowNum).createCell(6).setCellValue((int) product.getAmount());
                sum += product.getAmount();
            }
        }

        //
        os = new FileOutputStream(new File(outFile));
        wb.write(os);
        os.flush();
        resultMSG.setWriteMessage("?,:" + sum + "");
    } catch (Exception e) {
        e.printStackTrace();
        resultMSG.setWriteMessage(",:" + sum + ",:" + e.toString());
    } finally {
        is.close();
        os.close();
    }
}

From source file:com.coast.controler.Controler.java

public static ArrayList<Product> readProductsFromMyExcel(String file, ResultMSG resultMSG) throws Exception {
    ArrayList<Product> products = new ArrayList<Product>();
    InputStream is = null;//from  ww  w.ja v a2  s.  c  om
    int sum = 0;
    int row = 1;
    try {
        File f = new File(file);
        is = new FileInputStream(f);
        Workbook wb = WorkbookFactory.create(is);
        Sheet sheet = wb.getSheetAt(0);

        POIUtil poiUtil = new POIUtil();
        int lastRowNum = sheet.getLastRowNum();
        while (row <= lastRowNum) {
            //??
            Cell firstCell = sheet.getRow(row).getCell(0);
            if (firstCell == null)
                break;
            if (firstCell.getRichStringCellValue().toString().toUpperCase() == "")
                break;

            //fullsn
            Cell fullSnCell = sheet.getRow(row).getCell(0);
            String fullSn = poiUtil.getCellContentToString(fullSnCell);
            int len = fullSn.length();
            String snCode = fullSn.substring(0, len - 3);
            String colorCode = fullSn.substring(len - 3, len - 1);
            String sizeCode = fullSn.substring(len - 1, len);
            //                String sizeRegex = convertSizeToRegex(sizeCode);

            //type
            Cell typeCell = sheet.getRow(row).getCell(1);
            String type = poiUtil.getCellContentToString(typeCell);

            //color
            Cell colorCell = sheet.getRow(row).getCell(2);
            String color = poiUtil.getCellContentToString(colorCell);

            //size
            Cell sizeCell = sheet.getRow(row).getCell(3);
            String size = poiUtil.getCellContentToString(sizeCell);

            //price
            Cell priceCell = sheet.getRow(row).getCell(5);
            String orgPrice = poiUtil.getCellContentToString(priceCell);

            //amount
            Cell amountCell = sheet.getRow(row).getCell(10);
            int amount = Integer.parseInt(poiUtil.getCellContentToString(amountCell));

            //Porduct
            Product product = new Product(fullSn, snCode, colorCode, sizeCode, type, color, size, orgPrice,
                    amount);

            products.add(product);

            sum += product.getAmount();
            row++;
        }
        resultMSG.setReadMessage("??,:" + sum + "!");
    } catch (Exception e) {
        System.out.println(
                "readProductsFromMyExcel:=" + row + "=?" + e.toString());
        products = null;
        e.printStackTrace();
        resultMSG.setReadMessage("?,:" + sum + "!:" + e.toString());
    } finally {
        is.close();
        System.out.println("?:" + sum);
        return products;
    }
}

From source file:com.compassplus.gui.MainForm.java

private void save(String file) throws IOException, InvalidFormatException {
    final String sfile = file;
    FileInputStream inp = new FileInputStream(sfile);
    final Workbook wb = WorkbookFactory.create(inp);
    inp.close();/*  w ww .j  av  a2s . c o m*/
    {
        final ArrayList<String> sheets = new ArrayList<String>(0);
        for (int i = 0; i < wb.getNumberOfSheets(); i++) {
            if (!(wb.isSheetHidden(i) || wb.isSheetVeryHidden(i))) {
                sheets.add(wb.getSheetName(i));
            }
        }
        if (sheets.size() == 0) {
            JOptionPane.showMessageDialog(getRoot(), "Selected excel workbook is empty", "Error",
                    JOptionPane.ERROR_MESSAGE);
            return;
        }

        Integer rowsCountInt = null;
        Integer cellIndexInt = null;
        Integer rowIndexInt = null;
        String sheetIndexStr = null;
        Integer sheetIndexInt = null;

        Integer psRowsCountInt = null;
        Integer psCellIndexInt = null;
        Integer psRowIndexInt = null;
        String psSheetIndexStr = null;
        Integer psSheetIndexInt = null;

        Integer oRowsCountInt = null;
        Integer oCellIndexInt = null;
        Integer oRowIndexInt = null;
        String oSheetIndexStr = null;
        Integer oSheetIndexInt = null;

        Sheet settingsSheet = wb.getSheet("PCTSettings");
        final List<RowStyle> rowStyles = new ArrayList<RowStyle>();
        final List<RowStyle> psRowStyles = new ArrayList<RowStyle>();
        final List<RowStyle> oRowStyles = new ArrayList<RowStyle>();
        boolean sameCurrency = false;
        if (settingsSheet != null) {
            Row currentSettingsRow = settingsSheet.getRow(0);
            if (currentSettingsRow != null) {
                Cell oldProposalCell = currentSettingsRow.getCell(0);
                Cell rowsCountCell = currentSettingsRow.getCell(1);
                Cell cellIndexCell = currentSettingsRow.getCell(2);
                Cell rowIndexCell = currentSettingsRow.getCell(3);
                Cell sheetIndexCell = currentSettingsRow.getCell(4);
                try {
                    Proposal oldProposal = new Proposal(config);
                    String proposalString = oldProposalCell.getStringCellValue();
                    if (proposalString != null) {
                        oldProposal.init(CommonUtils.getInstance().getDocumentFromString(proposalString));
                        sameCurrency = getCurrentProposalForm().getProposal().getCurrency().getName()
                                .equals(oldProposal.getCurrency().getName());
                    }
                } catch (Exception e) {

                }

                if (rowsCountCell != null && rowIndexCell != null && sheetIndexCell != null
                        && cellIndexCell != null) {
                    try {
                        rowsCountInt = Integer.parseInt(rowsCountCell.getStringCellValue());
                        cellIndexInt = Integer.parseInt(cellIndexCell.getStringCellValue());
                        rowIndexInt = Integer.parseInt(rowIndexCell.getStringCellValue());
                        rowIndexInt++;
                        cellIndexInt++;
                        //sheetIndexInt = Integer.parseInt(sheetIndexCell.getStringCellValue());
                        sheetIndexStr = sheetIndexCell.getStringCellValue();
                        if (wb.getSheet(sheetIndexStr) != null) {
                            //sheetIndexStr = wb.getSheetAt(sheetIndexInt).getSheetName();
                            for (int j = 0; j < rowsCountInt; j++) {
                                RowStyle rowStyle = new RowStyle();
                                rowStyle.init(wb, wb.getSheet(sheetIndexStr).getRow(rowIndexInt - 1));
                                rowStyles.add(rowStyle);
                                removeRow(wb.getSheet(sheetIndexStr), rowIndexInt - 1, wb);
                            }
                        }
                    } catch (Exception ex) {
                    }
                }
            } else {
            }
        }

        if (settingsSheet != null) {
            Row currentSettingsRow = settingsSheet.getRow(0);
            if (currentSettingsRow != null) {
                Cell oldProposalCell = currentSettingsRow.getCell(0);
                Cell rowsCountCell = currentSettingsRow.getCell(5);
                Cell cellIndexCell = currentSettingsRow.getCell(6);
                Cell rowIndexCell = currentSettingsRow.getCell(7);
                Cell sheetIndexCell = currentSettingsRow.getCell(8);
                try {
                    Proposal oldProposal = new Proposal(config);
                    String proposalString = oldProposalCell.getStringCellValue();
                    if (proposalString != null) {
                        oldProposal.init(CommonUtils.getInstance().getDocumentFromString(proposalString));
                        sameCurrency = getCurrentProposalForm().getProposal().getCurrency().getName()
                                .equals(oldProposal.getCurrency().getName());
                    }
                } catch (Exception e) {

                }

                if (rowsCountCell != null && rowIndexCell != null && sheetIndexCell != null
                        && cellIndexCell != null) {
                    try {
                        psRowsCountInt = Integer.parseInt(rowsCountCell.getStringCellValue());
                        psCellIndexInt = Integer.parseInt(cellIndexCell.getStringCellValue());
                        psRowIndexInt = Integer.parseInt(rowIndexCell.getStringCellValue());
                        psRowIndexInt++;
                        psCellIndexInt++;
                        psSheetIndexStr = sheetIndexCell.getStringCellValue();
                        if (wb.getSheet(psSheetIndexStr) != null) {
                            //sheetIndexStr = wb.getSheetAt(sheetIndexInt).getSheetName();
                            for (int j = 0; j < psRowsCountInt; j++) {
                                RowStyle rowStyle = new RowStyle();
                                rowStyle.init(wb, wb.getSheet(psSheetIndexStr).getRow(psRowIndexInt - 1));
                                psRowStyles.add(rowStyle);
                                removeRow(wb.getSheet(psSheetIndexStr), psRowIndexInt - 1, wb, true);
                            }
                        }
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
            } else {
            }
        }

        if (settingsSheet != null) {
            Row currentSettingsRow = settingsSheet.getRow(0);
            if (currentSettingsRow != null) {
                Cell oldProposalCell = currentSettingsRow.getCell(0);
                Cell rowsCountCell = currentSettingsRow.getCell(9);
                Cell cellIndexCell = currentSettingsRow.getCell(10);
                Cell rowIndexCell = currentSettingsRow.getCell(11);
                Cell sheetIndexCell = currentSettingsRow.getCell(12);
                try {
                    Proposal oldProposal = new Proposal(config);
                    String proposalString = oldProposalCell.getStringCellValue();
                    if (proposalString != null) {
                        oldProposal.init(CommonUtils.getInstance().getDocumentFromString(proposalString));
                        sameCurrency = getCurrentProposalForm().getProposal().getCurrency().getName()
                                .equals(oldProposal.getCurrency().getName());
                    }
                } catch (Exception e) {

                }

                if (rowsCountCell != null && rowIndexCell != null && sheetIndexCell != null
                        && cellIndexCell != null) {
                    try {
                        oRowsCountInt = Integer.parseInt(rowsCountCell.getStringCellValue());
                        oCellIndexInt = Integer.parseInt(cellIndexCell.getStringCellValue());
                        oRowIndexInt = Integer.parseInt(rowIndexCell.getStringCellValue());
                        oRowIndexInt++;
                        oCellIndexInt++;
                        oSheetIndexStr = sheetIndexCell.getStringCellValue();
                        if (wb.getSheet(oSheetIndexStr) != null) {
                            //sheetIndexStr = wb.getSheetAt(sheetIndexInt).getSheetName();
                            for (int j = 0; j < oRowsCountInt; j++) {
                                RowStyle rowStyle = new RowStyle();
                                rowStyle.init(wb, wb.getSheet(oSheetIndexStr).getRow(oRowIndexInt - 1));
                                oRowStyles.add(rowStyle);
                                removeRow(wb.getSheet(oSheetIndexStr), oRowIndexInt - 1, wb, true);
                            }
                        }
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
            } else {
            }
        }

        final boolean isPSQ = getCurrentProposalForm().getProposal().getPSQuote().enabled();
        final boolean isOQ = !getCurrentProposalForm().getProposal().getConfig().isSalesSupport()
                && getCurrentProposalForm().getProposal().getOracleQuote().enabled()
                && getCurrentProposalForm().getProposal().getOracleQuote().getOracleLicenses().size() > 0;

        final JComboBox sheetIndexField = sheets.size() > 1 ? new JComboBox(sheets.toArray()) : null;
        if (sheetIndexField != null && sheetIndexStr != null) {
            for (String key : sheets) {
                if (key.equals(sheetIndexStr)) {
                    sheetIndexField.setSelectedItem(key);
                    break;
                }
            }
        }
        String selectedSheet1 = sheetIndexField != null ? (String) sheetIndexField.getSelectedItem() : null;

        final JComboBox psSheetIndexField = sheets.size() > 1 && isPSQ ? new JComboBox(sheets.toArray()) : null;
        if (psSheetIndexField != null && psSheetIndexStr != null) {
            for (String key : sheets) {
                if (key.equals(psSheetIndexStr)) {
                    psSheetIndexField.setSelectedItem(key);
                    break;
                }
            }
        } else if (psSheetIndexField != null) {
            for (String key : sheets) {
                if (!key.equals(selectedSheet1)) {
                    psSheetIndexField.setSelectedItem(key);
                    break;
                }
            }
        }
        String selectedSheet2 = psSheetIndexField != null ? (String) psSheetIndexField.getSelectedItem() : null;

        final JComboBox oSheetIndexField = sheets.size() > 1 && isOQ ? new JComboBox(sheets.toArray()) : null;
        if (oSheetIndexField != null && oSheetIndexStr != null) {
            for (String key : sheets) {
                if (key.equals(oSheetIndexStr)) {
                    oSheetIndexField.setSelectedItem(key);
                    break;
                }
            }
        } else if (oSheetIndexField != null) {
            for (String key : sheets) {
                if (!key.equals(selectedSheet1) && !key.equals(selectedSheet2)) {
                    oSheetIndexField.setSelectedItem(key);
                    break;
                }
            }
        }

        final JTextField rowIndexField = new JTextField(rowIndexInt != null ? rowIndexInt.toString() : "1");
        final JTextField cellIndexField = new JTextField(cellIndexInt != null ? cellIndexInt.toString() : "1");

        final JTextField psRowIndexField = new JTextField(
                psRowIndexInt != null ? psRowIndexInt.toString() : "1");
        final JTextField psCellIndexField = new JTextField(
                psCellIndexInt != null ? psCellIndexInt.toString() : "1");
        final JTextField oRowIndexField = new JTextField(oRowIndexInt != null ? oRowIndexInt.toString() : "1");
        final JTextField oCellIndexField = new JTextField(
                oCellIndexInt != null ? oCellIndexInt.toString() : "1");
        final JOptionPane optionPane = new JOptionPane(new JComponent[] {
                sheets.size() > 1 ? new JLabel("Products sheet") : null, sheetIndexField,
                new JLabel("Products row index"), rowIndexField, new JLabel("Products cell index"),
                cellIndexField, (sheets.size() > 1 && isPSQ) ? new JLabel("Prof. services sheet") : null,
                isPSQ ? psSheetIndexField : null, isPSQ ? new JLabel("Prof. services row index") : null,
                isPSQ ? psRowIndexField : null, isPSQ ? new JLabel("Prof. services cell index") : null,
                isPSQ ? psCellIndexField : null,

                (sheets.size() > 1 && isOQ) ? new JLabel("Oracle calculation sheet") : null,
                isOQ ? oSheetIndexField : null, isOQ ? new JLabel("Oracle calculation row index") : null,
                isOQ ? oRowIndexField : null, isOQ ? new JLabel("Oracle calculation cell index") : null,
                isOQ ? oCellIndexField : null }, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);

        final JDialog dialog = new JDialog(getFrame(), "Export position", true);
        dialog.setResizable(false);
        dialog.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent we) {
                dialog.dispose();
            }
        });
        dialog.setContentPane(optionPane);
        dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);

        final boolean fSameCurrency = false;//sameCurrency;
        optionPane.addPropertyChangeListener(new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent e) {
                if (optionPane.getValue() != null) {
                    String prop = e.getPropertyName();
                    if (dialog.isVisible() && (e.getSource() == optionPane)
                            && (prop.equals(JOptionPane.VALUE_PROPERTY))) {
                        try {
                            if (optionPane.getValue() instanceof Integer) {
                                int value = (Integer) optionPane.getValue();
                                if (value == JOptionPane.OK_OPTION) {
                                    Sheet s = null;
                                    Sheet psS = null;
                                    Sheet oS = null;
                                    if (sheetIndexField != null) {
                                        try {
                                            s = wb.getSheet((String) sheetIndexField.getSelectedItem());
                                        } catch (Exception exception) {
                                        }
                                    } else {
                                        s = wb.getSheet(sheets.get(0));
                                    }

                                    //PS
                                    if (psSheetIndexField != null) {
                                        try {
                                            psS = wb.getSheet((String) psSheetIndexField.getSelectedItem());
                                        } catch (Exception exception) {
                                        }
                                    } else {
                                        psS = wb.getSheet(sheets.get(0));
                                    }

                                    //Oracle
                                    if (oSheetIndexField != null) {
                                        try {
                                            oS = wb.getSheet((String) oSheetIndexField.getSelectedItem());
                                        } catch (Exception exception) {
                                        }
                                    } else {
                                        oS = wb.getSheet(sheets.get(0));
                                    }

                                    if (getCurrentProposalForm().getProposal().getPSQuote().enabled()) {
                                        if (s.equals(psS)) {
                                            JOptionPane.showMessageDialog(getRoot(),
                                                    "Products and prof. services can't be exported on the same sheet",
                                                    "Error", JOptionPane.ERROR_MESSAGE);
                                            throw new Exception();
                                        }
                                    }

                                    if (getCurrentProposalForm().getProposal().getPSQuote().enabled() && isOQ) {
                                        if (psS.equals(oS)) {
                                            JOptionPane.showMessageDialog(getRoot(),
                                                    "Oracle calculation and prof. services can't be exported on the same sheet",
                                                    "Error", JOptionPane.ERROR_MESSAGE);
                                            throw new Exception();
                                        }
                                    }

                                    if (isOQ) {
                                        if (s.equals(oS)) {
                                            JOptionPane.showMessageDialog(getRoot(),
                                                    "Products and oracle calculation can't be exported on the same sheet",
                                                    "Error", JOptionPane.ERROR_MESSAGE);
                                            throw new Exception();
                                        }
                                    }

                                    Integer rowIndex = null;
                                    try {
                                        rowIndex = Integer.parseInt(rowIndexField.getText());
                                        rowIndex--;
                                    } catch (Exception exception) {
                                    }
                                    if (rowIndex == null || rowIndex < 0) {
                                        JOptionPane.showMessageDialog(getRoot(),
                                                "Products row index is not valid", "Error",
                                                JOptionPane.ERROR_MESSAGE);
                                        rowIndexField.requestFocus();
                                        rowIndexField.selectAll();
                                        throw new Exception();
                                    }

                                    //PS
                                    Integer psRowIndex = null;
                                    try {
                                        psRowIndex = Integer.parseInt(psRowIndexField.getText());
                                        psRowIndex--;
                                    } catch (Exception exception) {
                                    }
                                    if ((psRowIndex == null || psRowIndex < 0) && isPSQ) {
                                        JOptionPane.showMessageDialog(getRoot(),
                                                "Prof. services row index is not valid", "Error",
                                                JOptionPane.ERROR_MESSAGE);
                                        psRowIndexField.requestFocus();
                                        psRowIndexField.selectAll();
                                        throw new Exception();
                                    }

                                    //Oracle
                                    Integer oRowIndex = null;
                                    try {
                                        oRowIndex = Integer.parseInt(oRowIndexField.getText());
                                        oRowIndex--;
                                    } catch (Exception exception) {
                                    }
                                    if ((oRowIndex == null || oRowIndex < 0) && isOQ) {
                                        JOptionPane.showMessageDialog(getRoot(),
                                                "Oracle calculation row index is not valid", "Error",
                                                JOptionPane.ERROR_MESSAGE);
                                        oRowIndexField.requestFocus();
                                        oRowIndexField.selectAll();
                                        throw new Exception();
                                    }

                                    Integer cellIndex = null;
                                    try {
                                        cellIndex = Integer.parseInt(cellIndexField.getText());
                                        cellIndex--;
                                    } catch (Exception exception) {
                                    }
                                    if (cellIndex == null || cellIndex < 0) {
                                        JOptionPane.showMessageDialog(getRoot(),
                                                "Products cell index is not valid", "Error",
                                                JOptionPane.ERROR_MESSAGE);
                                        cellIndexField.requestFocus();
                                        cellIndexField.selectAll();
                                        throw new Exception();
                                    }

                                    Integer psCellIndex = null;
                                    try {
                                        psCellIndex = Integer.parseInt(psCellIndexField.getText());
                                        psCellIndex--;
                                    } catch (Exception exception) {
                                    }
                                    if ((psCellIndex == null || psCellIndex < 0) && isPSQ) {
                                        JOptionPane.showMessageDialog(getRoot(),
                                                "Prof. services cell index is not valid", "Error",
                                                JOptionPane.ERROR_MESSAGE);
                                        psCellIndexField.requestFocus();
                                        psCellIndexField.selectAll();
                                        throw new Exception();
                                    }

                                    Integer oCellIndex = null;
                                    try {
                                        oCellIndex = Integer.parseInt(oCellIndexField.getText());
                                        oCellIndex--;
                                    } catch (Exception exception) {
                                    }
                                    if ((oCellIndex == null || oCellIndex < 0) && isOQ) {
                                        JOptionPane.showMessageDialog(getRoot(),
                                                "Oracle calculation cell index is not valid", "Error",
                                                JOptionPane.ERROR_MESSAGE);
                                        oCellIndexField.requestFocus();
                                        oCellIndexField.selectAll();
                                        throw new Exception();
                                    }

                                    dialog.dispose();
                                    try {
                                        int i = 0;
                                        Sheet settingsSheet = wb.getSheet("PCTSettings");
                                        if (settingsSheet == null) {
                                            settingsSheet = wb.createSheet("PCTSettings");
                                        } else {

                                        }
                                        if (rowStyles.size() == 0) {
                                            RowStyle rowStyle = new RowStyle();
                                            rowStyle.init(wb, s.getRow(rowIndex));
                                            rowStyles.add(rowStyle);
                                        }

                                        //PS
                                        if (psRowStyles.size() == 0) {
                                            RowStyle rowStyle = new RowStyle();
                                            rowStyle.init(wb, psS.getRow(psRowIndex));
                                            psRowStyles.add(rowStyle);
                                        }

                                        //Oracle
                                        if (oRowStyles.size() == 0) {
                                            RowStyle rowStyle = new RowStyle();
                                            rowStyle.init(wb, oS.getRow(oRowIndex));
                                            oRowStyles.add(rowStyle);
                                        }

                                        String regPriceCol = CellReference.convertNumToColString(1 + cellIndex);
                                        String regPriceDiscount = CellReference
                                                .convertNumToColString(2 + cellIndex);
                                        String supPriceCol = CellReference.convertNumToColString(4 + cellIndex);
                                        String supPriceDiscount = CellReference
                                                .convertNumToColString(5 + cellIndex);
                                        int currentRowIndex = 0;
                                        for (Product p : getCurrentProposalForm().getProposal().getProducts()
                                                .values()) {
                                            if (s.getLastRowNum() >= rowIndex + i) {
                                                s.shiftRows(rowIndex + i, s.getLastRowNum(), 1);
                                            }
                                            RowStyle rowStyle = rowStyles
                                                    .get((int) (currentRowIndex - rowStyles.size()
                                                            * Math.floor(currentRowIndex / rowStyles.size())));
                                            currentRowIndex++;
                                            Row r = s.createRow(rowIndex + i);
                                            for (int y = rowStyle.getFirst(); y < 0 + cellIndex; y++) {
                                                CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                if (tcs != null) {
                                                    Cell tc = r.createCell(y);
                                                    tc.setCellStyle(tcs);
                                                }
                                            }

                                            Cell c1 = r.createCell(0 + cellIndex);
                                            CellStyle cs1 = rowStyle.getCellStyle(0 + cellIndex,
                                                    wb.createCellStyle());
                                            cs1.setWrapText(true);
                                            c1.setCellValue(p.getDescription());
                                            c1.setCellStyle(cs1);

                                            Cell c2 = r.createCell(1 + cellIndex);
                                            CellStyle cs2 = rowStyle.getCellStyle(1 + cellIndex,
                                                    wb.createCellStyle());
                                            String format = (getCurrentProposalForm().getProposal()
                                                    .getCurrency().getSymbol() != null
                                                            ? "\"" + getCurrentProposalForm().getProposal()
                                                                    .getCurrency().getSymbol() + "\" "
                                                            : "")
                                                    + "#,##0"
                                                    + (getCurrentProposalForm().getProposal().getCurrency()
                                                            .getSymbol() == null ? " \""
                                                                    + getCurrentProposalForm().getProposal()
                                                                            .getCurrency().getName()
                                                                    + "\"" : "");
                                            if (!fSameCurrency)
                                                cs2.setDataFormat(
                                                        s.getWorkbook().createDataFormat().getFormat(format));
                                            c2.setCellStyle(cs2);
                                            c2.setCellValue(p.getProposal().getConfig().isSalesSupport() ? 0
                                                    : p.getRegionPrice());

                                            Cell c3 = r.createCell(2 + cellIndex);
                                            CellStyle cs3 = rowStyle.getCellStyle(2 + cellIndex,
                                                    wb.createCellStyle());
                                            cs3.setDataFormat(
                                                    s.getWorkbook().createDataFormat().getFormat("0%;-0%"));
                                            c3.setCellStyle(cs3);
                                            c3.setCellValue(p.getProposal().getConfig().isSalesSupport() ? 0
                                                    : p.getDiscount());

                                            Cell c4 = r.createCell(3 + cellIndex);
                                            CellStyle cs4 = rowStyle.getCellStyle(3 + cellIndex,
                                                    wb.createCellStyle());
                                            if (!fSameCurrency)
                                                cs4.setDataFormat(
                                                        s.getWorkbook().createDataFormat().getFormat(format));
                                            c4.setCellStyle(cs4);
                                            int rowIndexTotal = rowIndex + i + 1;
                                            c4.setCellFormula("CEILING(" + regPriceCol + rowIndexTotal + "*(1-"
                                                    + regPriceDiscount + rowIndexTotal + "),1)");

                                            Cell c5 = r.createCell(4 + cellIndex);
                                            CellStyle cs5 = rowStyle.getCellStyle(4 + cellIndex,
                                                    wb.createCellStyle());
                                            if (!fSameCurrency)
                                                cs5.setDataFormat(
                                                        s.getWorkbook().createDataFormat().getFormat(format));
                                            c5.setCellStyle(cs5);
                                            c5.setCellValue(p.getProposal().getConfig().isSalesSupport() ? 0
                                                    : p.getSupportPriceUndiscounted());

                                            Cell c6 = r.createCell(5 + cellIndex);
                                            CellStyle cs6 = rowStyle.getCellStyle(5 + cellIndex,
                                                    wb.createCellStyle());
                                            cs6.setDataFormat(
                                                    s.getWorkbook().createDataFormat().getFormat("0%;-0%"));
                                            c6.setCellStyle(cs6);
                                            c6.setCellValue(p.getProposal().getConfig().isSalesSupport() ? 0
                                                    : p.getSupportDiscount());

                                            Cell c7 = r.createCell(6 + cellIndex);
                                            CellStyle cs7 = rowStyle.getCellStyle(6 + cellIndex,
                                                    wb.createCellStyle());
                                            if (!fSameCurrency)
                                                cs7.setDataFormat(
                                                        s.getWorkbook().createDataFormat().getFormat(format));
                                            c7.setCellStyle(cs7);
                                            c7.setCellFormula("CEILING(" + supPriceCol + rowIndexTotal + "*(1-"
                                                    + supPriceDiscount + rowIndexTotal + "),1)");

                                            for (int y = 7 + cellIndex; y <= rowStyle.getLast(); y++) {
                                                CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                if (tcs != null) {
                                                    Cell tc = r.createCell(y);
                                                    tc.setCellStyle(tcs);
                                                }
                                            }
                                            i++;
                                        }

                                        PSQuote psq = getCurrentProposalForm().getProposal().getPSQuote();
                                        //PS
                                        i = 0;
                                        currentRowIndex = 0;
                                        if (isPSQ) {
                                            int sTotal = -1;
                                            int tTotal = -1;

                                            int currentRowIndexFrom = -1;
                                            int currentRowIndexTo = -1;
                                            String rCol = CellReference.convertNumToColString(1 + psCellIndex);
                                            String chargeCol = CellReference
                                                    .convertNumToColString(2 + psCellIndex);
                                            String totalCol = CellReference
                                                    .convertNumToColString(3 + psCellIndex);
                                            String format = (getCurrentProposalForm().getProposal()
                                                    .getCurrency().getSymbol() != null
                                                            ? "\"" + getCurrentProposalForm().getProposal()
                                                                    .getCurrency().getSymbol() + "\" "
                                                            : "")
                                                    + "#,##0"
                                                    + (getCurrentProposalForm().getProposal().getCurrency()
                                                            .getSymbol() == null ? " \""
                                                                    + getCurrentProposalForm().getProposal()
                                                                            .getCurrency().getName()
                                                                    + "\"" : "");
                                            {
                                                if (psS.getLastRowNum() >= psRowIndex + i) {
                                                    psS.shiftRows(psRowIndex + i, psS.getLastRowNum(), 1);
                                                }
                                                RowStyle rowStyle = psRowStyles
                                                        .get((int) (currentRowIndex - psRowStyles.size() * Math
                                                                .floor(currentRowIndex / psRowStyles.size())));
                                                currentRowIndex++;
                                                Row r = psS.createRow(psRowIndex + i);
                                                for (int y = rowStyle.getFirst(); y < 0 + psCellIndex; y++) {
                                                    CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                    if (tcs != null) {
                                                        Cell tc = r.createCell(y);
                                                        tc.setCellStyle(tcs);
                                                    }
                                                }
                                                Cell c1 = r.createCell(0 + psCellIndex);
                                                CellStyle cs1 = rowStyle.getCellStyle(0 + psCellIndex,
                                                        wb.createCellStyle());
                                                cs1.setWrapText(true);
                                                c1.setCellValue("Man-day rate:");
                                                c1.setCellStyle(cs1);

                                                Cell c2 = r.createCell(1 + psCellIndex);
                                                CellStyle cs2 = rowStyle.getCellStyle(1 + psCellIndex,
                                                        wb.createCellStyle());
                                                cs2.setWrapText(true);
                                                c2.setCellValue(!getCurrentProposalForm().getProposal()
                                                        .getConfig().isSalesSupport()
                                                                ? getCurrentProposalForm().getProposal()
                                                                        .getRegion().getMDRate()
                                                                        * getCurrentProposalForm().getProposal()
                                                                                .getCurrency().getRate()
                                                                : 0);
                                                if (!fSameCurrency)
                                                    cs2.setDataFormat(psS.getWorkbook().createDataFormat()
                                                            .getFormat(format));
                                                c2.setCellStyle(cs2);

                                                for (int y = 2 + psCellIndex; y <= rowStyle.getLast(); y++) {
                                                    CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                    if (tcs != null) {
                                                        Cell tc = r.createCell(y);
                                                        tc.setCellStyle(tcs);
                                                    }
                                                }

                                                i++;
                                            }

                                            {
                                                if (psS.getLastRowNum() >= psRowIndex + i) {
                                                    psS.shiftRows(psRowIndex + i, psS.getLastRowNum(), 1);
                                                }
                                                RowStyle rowStyle = psRowStyles
                                                        .get((int) (currentRowIndex - psRowStyles.size() * Math
                                                                .floor(currentRowIndex / psRowStyles.size())));
                                                currentRowIndex++;
                                                Row r = psS.createRow(psRowIndex + i);
                                                for (int y = rowStyle.getFirst(); y < 0 + psCellIndex; y++) {
                                                    CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                    if (tcs != null) {
                                                        Cell tc = r.createCell(y);
                                                        tc.setCellStyle(tcs);
                                                    }
                                                }
                                                Cell c1 = r.createCell(0 + psCellIndex);
                                                CellStyle cs1 = rowStyle.getCellStyle(0 + psCellIndex,
                                                        wb.createCellStyle());
                                                cs1.setWrapText(true);
                                                c1.setCellValue("Man-day discount:");
                                                c1.setCellStyle(cs1);

                                                Cell c2 = r.createCell(1 + psCellIndex);
                                                CellStyle cs2 = rowStyle.getCellStyle(1 + psCellIndex,
                                                        wb.createCellStyle());
                                                cs2.setDataFormat(psS.getWorkbook().createDataFormat()
                                                        .getFormat("0%;-0%"));
                                                c2.setCellStyle(cs2);
                                                c2.setCellValue(
                                                        !getCurrentProposalForm().getProposal().getConfig()
                                                                .isSalesSupport() ? psq.getMDDiscount() : 0);

                                                for (int y = 2 + psCellIndex; y <= rowStyle.getLast(); y++) {
                                                    CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                    if (tcs != null) {
                                                        Cell tc = r.createCell(y);
                                                        tc.setCellStyle(tcs);
                                                    }
                                                }

                                                i++;
                                            }

                                            /*{
                                                if (psS.getLastRowNum() >= psRowIndex + i) {
                                                    psS.shiftRows(psRowIndex + i, psS.getLastRowNum(), 1);
                                                }
                                                RowStyle rowStyle = psRowStyles.get((int) (currentRowIndex - psRowStyles.size() * Math.floor(currentRowIndex / psRowStyles.size())));
                                                currentRowIndex++;
                                                Row r = psS.createRow(psRowIndex + i);
                                                for (int y = rowStyle.getFirst(); y < 0 + psCellIndex; y++) {
                                                    CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                    if (tcs != null) {
                                                        Cell tc = r.createCell(y);
                                                        tc.setCellStyle(tcs);
                                                    }
                                                }
                                                Cell c1 = r.createCell(0 + psCellIndex);
                                                CellStyle cs1 = rowStyle.getCellStyle(0 + psCellIndex, wb.createCellStyle());
                                                cs1.setWrapText(true);
                                                c1.setCellValue("");
                                                c1.setCellStyle(cs1);
                                                    
                                                for (int y = 1 + psCellIndex; y <= rowStyle.getLast(); y++) {
                                                    CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                    if (tcs != null) {
                                                        Cell tc = r.createCell(y);
                                                        tc.setCellStyle(tcs);
                                                    }
                                                }
                                                i++;
                                            }
                                            {
                                                if (psS.getLastRowNum() >= psRowIndex + i) {
                                                    psS.shiftRows(psRowIndex + i, psS.getLastRowNum(), 1);
                                                }
                                                RowStyle rowStyle = psRowStyles.get((int) (currentRowIndex - psRowStyles.size() * Math.floor(currentRowIndex / psRowStyles.size())));
                                                currentRowIndex++;
                                                Row r = psS.createRow(psRowIndex + i);
                                                for (int y = rowStyle.getFirst(); y < 0 + psCellIndex; y++) {
                                                    CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                    if (tcs != null) {
                                                        Cell tc = r.createCell(y);
                                                        tc.setCellStyle(tcs);
                                                    }
                                                }
                                                Cell c1 = r.createCell(0 + psCellIndex);
                                                CellStyle cs1 = rowStyle.getCellStyle(0 + psCellIndex, wb.createCellStyle());
                                                cs1.setWrapText(true);
                                                c1.setCellValue("Onsite daily rate:");
                                                c1.setCellStyle(cs1);
                                                    
                                                    
                                                Cell c2 = r.createCell(1 + psCellIndex);
                                                CellStyle cs2 = rowStyle.getCellStyle(1 + psCellIndex, wb.createCellStyle());
                                                cs2.setWrapText(true);
                                                c2.setCellValue(!getCurrentProposalForm().getProposal().getConfig().isSalesSupport()?getCurrentProposalForm().getProposal().getRegion().getOnsiteDailyCost() * getCurrentProposalForm().getProposal().getCurrency().getRate():0);
                                                if (!fSameCurrency)
                                                    cs2.setDataFormat(psS.getWorkbook().createDataFormat().getFormat(format));
                                                c2.setCellStyle(cs2);
                                                    
                                                for (int y = 2 + psCellIndex; y <= rowStyle.getLast(); y++) {
                                                    CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                    if (tcs != null) {
                                                        Cell tc = r.createCell(y);
                                                        tc.setCellStyle(tcs);
                                                    }
                                                }
                                                    
                                                i++;
                                            }
                                            {
                                                if (psS.getLastRowNum() >= psRowIndex + i) {
                                                    psS.shiftRows(psRowIndex + i, psS.getLastRowNum(), 1);
                                                }
                                                RowStyle rowStyle = psRowStyles.get((int) (currentRowIndex - psRowStyles.size() * Math.floor(currentRowIndex / psRowStyles.size())));
                                                currentRowIndex++;
                                                Row r = psS.createRow(psRowIndex + i);
                                                for (int y = rowStyle.getFirst(); y < 0 + psCellIndex; y++) {
                                                    CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                    if (tcs != null) {
                                                        Cell tc = r.createCell(y);
                                                        tc.setCellStyle(tcs);
                                                    }
                                                }
                                                Cell c1 = r.createCell(0 + psCellIndex);
                                                CellStyle cs1 = rowStyle.getCellStyle(0 + psCellIndex, wb.createCellStyle());
                                                cs1.setWrapText(true);
                                                c1.setCellValue("Onsite trip rate:");
                                                c1.setCellStyle(cs1);
                                                    
                                                    
                                                Cell c2 = r.createCell(1 + psCellIndex);
                                                CellStyle cs2 = rowStyle.getCellStyle(1 + psCellIndex, wb.createCellStyle());
                                                cs2.setWrapText(true);
                                                c2.setCellValue(!getCurrentProposalForm().getProposal().getConfig().isSalesSupport()?getCurrentProposalForm().getProposal().getRegion().getTripPrice() * getCurrentProposalForm().getProposal().getCurrency().getRate():0);
                                                if (!fSameCurrency)
                                                    cs2.setDataFormat(psS.getWorkbook().createDataFormat().getFormat(format));
                                                c2.setCellStyle(cs2);
                                                    
                                                for (int y = 2 + psCellIndex; y <= rowStyle.getLast(); y++) {
                                                    CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                    if (tcs != null) {
                                                        Cell tc = r.createCell(y);
                                                        tc.setCellStyle(tcs);
                                                    }
                                                }
                                                    
                                                i++;
                                            }*/
                                            {
                                                if (psS.getLastRowNum() >= psRowIndex + i) {
                                                    psS.shiftRows(psRowIndex + i, psS.getLastRowNum(), 1);
                                                }
                                                RowStyle rowStyle = psRowStyles
                                                        .get((int) (currentRowIndex - psRowStyles.size() * Math
                                                                .floor(currentRowIndex / psRowStyles.size())));
                                                currentRowIndex++;
                                                Row r = psS.createRow(psRowIndex + i);
                                                for (int y = rowStyle.getFirst(); y < 0 + psCellIndex; y++) {
                                                    CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                    if (tcs != null) {
                                                        Cell tc = r.createCell(y);
                                                        tc.setCellStyle(tcs);
                                                    }
                                                }
                                                Cell c1 = r.createCell(0 + psCellIndex);
                                                CellStyle cs1 = rowStyle.getCellStyle(0 + psCellIndex,
                                                        wb.createCellStyle());
                                                cs1.setWrapText(true);
                                                c1.setCellValue("");
                                                c1.setCellStyle(cs1);

                                                for (int y = 1 + psCellIndex; y <= rowStyle.getLast(); y++) {
                                                    CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                    if (tcs != null) {
                                                        Cell tc = r.createCell(y);
                                                        tc.setCellStyle(tcs);
                                                    }
                                                }
                                                i++;
                                            }
                                            {
                                                if (psS.getLastRowNum() >= psRowIndex + i) {
                                                    psS.shiftRows(psRowIndex + i, psS.getLastRowNum(), 1);
                                                }
                                                RowStyle rowStyle = psRowStyles
                                                        .get((int) (currentRowIndex - psRowStyles.size() * Math
                                                                .floor(currentRowIndex / psRowStyles.size())));
                                                currentRowIndex++;
                                                Row r = psS.createRow(psRowIndex + i);
                                                for (int y = rowStyle.getFirst(); y < 0 + psCellIndex; y++) {
                                                    CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                    if (tcs != null) {
                                                        Cell tc = r.createCell(y);
                                                        tc.setCellStyle(tcs);
                                                    }
                                                }
                                                Cell c1 = r.createCell(0 + psCellIndex);
                                                CellStyle cs1 = rowStyle.getCellStyle(0 + psCellIndex,
                                                        wb.createCellStyle());
                                                cs1.setWrapText(true);
                                                c1.setCellValue("");
                                                c1.setCellStyle(cs1);

                                                for (int y = 1 + psCellIndex; y <= rowStyle.getLast(); y++) {
                                                    CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                    if (tcs != null) {
                                                        Cell tc = r.createCell(y);
                                                        tc.setCellStyle(tcs);
                                                    }
                                                }
                                                i++;
                                            }

                                            {
                                                if (psS.getLastRowNum() >= psRowIndex + i) {
                                                    psS.shiftRows(psRowIndex + i, psS.getLastRowNum(), 1);
                                                }
                                                RowStyle rowStyle = psRowStyles
                                                        .get((int) (currentRowIndex - psRowStyles.size() * Math
                                                                .floor(currentRowIndex / psRowStyles.size())));
                                                currentRowIndex++;
                                                Row r = psS.createRow(psRowIndex + i);
                                                for (int y = rowStyle.getFirst(); y < 0 + psCellIndex; y++) {
                                                    CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                    if (tcs != null) {
                                                        Cell tc = r.createCell(y);
                                                        tc.setCellStyle(tcs);
                                                    }
                                                }
                                                Cell c1 = r.createCell(0 + psCellIndex);
                                                CellStyle cs1 = rowStyle.getCellStyle(0 + psCellIndex,
                                                        wb.createCellStyle());
                                                cs1.setWrapText(true);
                                                c1.setCellValue("Professional Services Description:");
                                                c1.setCellStyle(cs1);

                                                Cell c2 = r.createCell(1 + psCellIndex);
                                                CellStyle cs2 = rowStyle.getCellStyle(1 + psCellIndex,
                                                        wb.createCellStyle());
                                                cs2.setWrapText(true);
                                                c2.setCellValue("M/D:");
                                                c2.setCellStyle(cs2);

                                                Cell c3 = r.createCell(2 + psCellIndex);
                                                CellStyle cs3 = rowStyle.getCellStyle(2 + psCellIndex,
                                                        wb.createCellStyle());
                                                cs3.setWrapText(true);
                                                c3.setCellValue("Chargeable:");
                                                c3.setCellStyle(cs3);

                                                Cell c4 = r.createCell(3 + psCellIndex);
                                                CellStyle cs4 = rowStyle.getCellStyle(3 + psCellIndex,
                                                        wb.createCellStyle());
                                                cs4.setWrapText(true);
                                                c4.setCellValue("$$:");
                                                c4.setCellStyle(cs4);

                                                /*Cell c5 = r.createCell(4 + psCellIndex);
                                                CellStyle cs5 = rowStyle.getCellStyle(4 + psCellIndex, wb.createCellStyle());
                                                cs5.setWrapText(true);
                                                c5.setCellValue("Onsite days:");
                                                c5.setCellStyle(cs5);
                                                        
                                                Cell c6 = r.createCell(5 + psCellIndex);
                                                CellStyle cs6 = rowStyle.getCellStyle(5 + psCellIndex, wb.createCellStyle());
                                                cs6.setWrapText(true);
                                                c6.setCellValue("Onsite trips:");
                                                c6.setCellStyle(cs6);*/

                                                for (int y = 4 + psCellIndex; y <= rowStyle.getLast(); y++) {
                                                    CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                    if (tcs != null) {
                                                        Cell tc = r.createCell(y);
                                                        tc.setCellStyle(tcs);
                                                    }
                                                }

                                                i++;
                                            }

                                            {
                                                if (psS.getLastRowNum() >= psRowIndex + i) {
                                                    psS.shiftRows(psRowIndex + i, psS.getLastRowNum(), 1);
                                                }
                                                RowStyle rowStyle = psRowStyles
                                                        .get((int) (currentRowIndex - psRowStyles.size() * Math
                                                                .floor(currentRowIndex / psRowStyles.size())));
                                                currentRowIndex++;
                                                Row r = psS.createRow(psRowIndex + i);
                                                for (int y = rowStyle.getFirst(); y < 0 + psCellIndex; y++) {
                                                    CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                    if (tcs != null) {
                                                        Cell tc = r.createCell(y);
                                                        tc.setCellStyle(tcs);
                                                    }
                                                }
                                                Cell c1 = r.createCell(0 + psCellIndex);
                                                CellStyle cs1 = rowStyle.getCellStyle(0 + psCellIndex,
                                                        wb.createCellStyle());
                                                cs1.setWrapText(true);
                                                c1.setCellValue("");
                                                c1.setCellStyle(cs1);

                                                for (int y = 1 + psCellIndex; y <= rowStyle.getLast(); y++) {
                                                    CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                    if (tcs != null) {
                                                        Cell tc = r.createCell(y);
                                                        tc.setCellStyle(tcs);
                                                    }
                                                }
                                                i++;
                                            }

                                            for (ServicesGroup sg : getCurrentProposalForm().getProposal()
                                                    .getConfig().getServicesRoot().getGroups()) {
                                                if (sg.notEmpty(psq)) {
                                                    //vigrujaem gruppu
                                                    {
                                                        if (psS.getLastRowNum() >= psRowIndex + i) {
                                                            psS.shiftRows(psRowIndex + i, psS.getLastRowNum(),
                                                                    1);
                                                        }
                                                        RowStyle rowStyle = psRowStyles
                                                                .get((int) (currentRowIndex - psRowStyles.size()
                                                                        * Math.floor(currentRowIndex
                                                                                / psRowStyles.size())));
                                                        currentRowIndex++;
                                                        if (currentRowIndexFrom < 0) {
                                                            currentRowIndexFrom = currentRowIndex;
                                                        }
                                                        Row r = psS.createRow(psRowIndex + i);
                                                        for (int y = rowStyle.getFirst(); y < 0
                                                                + psCellIndex; y++) {
                                                            CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                            if (tcs != null) {
                                                                Cell tc = r.createCell(y);
                                                                tc.setCellStyle(tcs);
                                                            }
                                                        }
                                                        Cell c1 = r.createCell(0 + psCellIndex);
                                                        CellStyle cs1 = rowStyle.getCellStyle(0 + psCellIndex,
                                                                wb.createCellStyle());
                                                        cs1.setWrapText(true);
                                                        c1.setCellValue(sg.getName());
                                                        c1.setCellStyle(cs1);
                                                        if (psq.isExportable(sg.getKey())) {
                                                            Cell c2 = r.createCell(1 + psCellIndex);
                                                            CellStyle cs2 = rowStyle.getCellStyle(
                                                                    1 + psCellIndex, wb.createCellStyle());
                                                            c2.setCellValue(sg.getTotalMD(psq));
                                                            c2.setCellStyle(cs2);

                                                            Cell c3 = r.createCell(2 + psCellIndex);
                                                            CellStyle cs3 = rowStyle.getCellStyle(
                                                                    2 + psCellIndex, wb.createCellStyle());
                                                            c3.setCellValue(sg.getChargeableMD(psq));
                                                            c3.setCellStyle(cs3);

                                                            Cell c4 = r.createCell(3 + psCellIndex);
                                                            CellStyle cs4 = rowStyle.getCellStyle(
                                                                    3 + psCellIndex, wb.createCellStyle());
                                                            c4.setCellFormula(rCol + (psRowIndex + 1) + "*"
                                                                    + chargeCol + (psRowIndex + currentRowIndex)
                                                                    + "*(1-" + rCol + (psRowIndex + 2) + ")");
                                                            if (!fSameCurrency)
                                                                cs4.setDataFormat(psS.getWorkbook()
                                                                        .createDataFormat().getFormat(format));
                                                            c4.setCellStyle(cs4);

                                                            /*Cell c5 = r.createCell(4 + psCellIndex);
                                                            CellStyle cs5 = rowStyle.getCellStyle(4 + psCellIndex, wb.createCellStyle());
                                                            c5.setCellValue(sg.getTotalOnsiteMD(psq));
                                                            c5.setCellStyle(cs5);
                                                                    
                                                            Cell c6 = r.createCell(5 + psCellIndex);
                                                            CellStyle cs6 = rowStyle.getCellStyle(5 + psCellIndex, wb.createCellStyle());
                                                            c6.setCellValue(sg.getTotalOnsiteTrips(psq));
                                                            c6.setCellStyle(cs6);*/
                                                        }

                                                        for (int y = 4 + psCellIndex; y <= rowStyle
                                                                .getLast(); y++) {
                                                            CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                            if (tcs != null) {
                                                                Cell tc = r.createCell(y);
                                                                tc.setCellStyle(tcs);
                                                            }
                                                        }
                                                        i++;
                                                    }
                                                    if (!psq.isExportable(sg.getKey())) {
                                                        for (Service srv : sg.getServices().values()) {
                                                            if (srv.notEmpty(psq)) {
                                                                //System.out.println("\n\nsg.getKey()="+sg.getKey());
                                                                //System.out.println("psq.isHidden(sg.getKey())="+psq.isHidden(sg.getKey()));
                                                                if (psq.isExportable(srv.getKey())) {
                                                                    //vigrujaem service
                                                                    {
                                                                        if (psS.getLastRowNum() >= psRowIndex
                                                                                + i) {
                                                                            psS.shiftRows(psRowIndex + i,
                                                                                    psS.getLastRowNum(), 1);
                                                                        }
                                                                        RowStyle rowStyle = psRowStyles
                                                                                .get((int) (currentRowIndex
                                                                                        - psRowStyles.size()
                                                                                                * Math.floor(
                                                                                                        currentRowIndex
                                                                                                                / psRowStyles
                                                                                                                        .size())));
                                                                        currentRowIndex++;
                                                                        Row r = psS.createRow(psRowIndex + i);
                                                                        for (int y = rowStyle.getFirst(); y < 0
                                                                                + psCellIndex; y++) {
                                                                            CellStyle tcs = rowStyle
                                                                                    .getCellStyle(y, null);
                                                                            if (tcs != null) {
                                                                                Cell tc = r.createCell(y);
                                                                                tc.setCellStyle(tcs);
                                                                            }
                                                                        }
                                                                        Cell c1 = r.createCell(0 + psCellIndex);
                                                                        CellStyle cs1 = rowStyle.getCellStyle(
                                                                                0 + psCellIndex,
                                                                                wb.createCellStyle());
                                                                        cs1.setWrapText(true);
                                                                        c1.setCellValue(srv.getName());
                                                                        c1.setCellStyle(cs1);
                                                                        Cell c2 = r.createCell(1 + psCellIndex);
                                                                        CellStyle cs2 = rowStyle.getCellStyle(
                                                                                1 + psCellIndex,
                                                                                wb.createCellStyle());
                                                                        c2.setCellValue(srv.getTotalMD(psq));
                                                                        c2.setCellStyle(cs2);

                                                                        Cell c3 = r.createCell(2 + psCellIndex);
                                                                        CellStyle cs3 = rowStyle.getCellStyle(
                                                                                2 + psCellIndex,
                                                                                wb.createCellStyle());
                                                                        c3.setCellValue(
                                                                                srv.getChargeableMD(psq));
                                                                        c3.setCellStyle(cs3);

                                                                        Cell c4 = r.createCell(3 + psCellIndex);
                                                                        CellStyle cs4 = rowStyle.getCellStyle(
                                                                                3 + psCellIndex,
                                                                                wb.createCellStyle());
                                                                        c4.setCellFormula(rCol
                                                                                + (psRowIndex + 1) + "*"
                                                                                + chargeCol
                                                                                + (psRowIndex + currentRowIndex)
                                                                                + "*(1-" + rCol
                                                                                + (psRowIndex + 2) + ")");
                                                                        if (!fSameCurrency)
                                                                            cs4.setDataFormat(psS.getWorkbook()
                                                                                    .createDataFormat()
                                                                                    .getFormat(format));
                                                                        c4.setCellStyle(cs4);

                                                                        /*Cell c5 = r.createCell(4 + psCellIndex);
                                                                        CellStyle cs5 = rowStyle.getCellStyle(4 + psCellIndex, wb.createCellStyle());
                                                                        c5.setCellValue(srv.getTotalOnsiteMD(psq));
                                                                        c5.setCellStyle(cs5);
                                                                                
                                                                        Cell c6 = r.createCell(5 + psCellIndex);
                                                                        CellStyle cs6 = rowStyle.getCellStyle(5 + psCellIndex, wb.createCellStyle());
                                                                        c6.setCellValue(srv.getTotalOnsiteTrips(psq));
                                                                        c6.setCellStyle(cs6);*/

                                                                        for (int y = 4
                                                                                + psCellIndex; y <= rowStyle
                                                                                        .getLast(); y++) {
                                                                            CellStyle tcs = rowStyle
                                                                                    .getCellStyle(y, null);
                                                                            if (tcs != null) {
                                                                                Cell tc = r.createCell(y);
                                                                                tc.setCellStyle(tcs);
                                                                            }
                                                                        }
                                                                        i++;
                                                                    }
                                                                } else {
                                                                    for (com.compassplus.proposalModel.Service inst : psq
                                                                            .getServices().values()) {
                                                                        if (inst.getService().getGroupKey()
                                                                                .equals(sg.getKey())
                                                                                && inst.getService().getKey()
                                                                                        .equals(srv.getKey())) {
                                                                            {
                                                                                if (psS.getLastRowNum() >= psRowIndex
                                                                                        + i) {
                                                                                    psS.shiftRows(
                                                                                            psRowIndex + i,
                                                                                            psS.getLastRowNum(),
                                                                                            1);
                                                                                }
                                                                                RowStyle rowStyle = psRowStyles
                                                                                        .get((int) (currentRowIndex
                                                                                                - psRowStyles
                                                                                                        .size()
                                                                                                        * Math.floor(
                                                                                                                currentRowIndex
                                                                                                                        / psRowStyles
                                                                                                                                .size())));
                                                                                currentRowIndex++;
                                                                                Row r = psS.createRow(
                                                                                        psRowIndex + i);
                                                                                for (int y = rowStyle
                                                                                        .getFirst(); y < 0
                                                                                                + psCellIndex; y++) {
                                                                                    CellStyle tcs = rowStyle
                                                                                            .getCellStyle(y,
                                                                                                    null);
                                                                                    if (tcs != null) {
                                                                                        Cell tc = r
                                                                                                .createCell(y);
                                                                                        tc.setCellStyle(tcs);
                                                                                    }
                                                                                }
                                                                                Cell c1 = r.createCell(
                                                                                        0 + psCellIndex);
                                                                                CellStyle cs1 = rowStyle
                                                                                        .getCellStyle(
                                                                                                0 + psCellIndex,
                                                                                                wb.createCellStyle());
                                                                                cs1.setWrapText(true);
                                                                                c1.setCellValue(inst.getName());
                                                                                c1.setCellStyle(cs1);
                                                                                Cell c2 = r.createCell(
                                                                                        1 + psCellIndex);
                                                                                CellStyle cs2 = rowStyle
                                                                                        .getCellStyle(
                                                                                                1 + psCellIndex,
                                                                                                wb.createCellStyle());
                                                                                c2.setCellValue(
                                                                                        inst.getTotalValue());
                                                                                c2.setCellStyle(cs2);

                                                                                Cell c3 = r.createCell(
                                                                                        2 + psCellIndex);
                                                                                CellStyle cs3 = rowStyle
                                                                                        .getCellStyle(
                                                                                                2 + psCellIndex,
                                                                                                wb.createCellStyle());
                                                                                c3.setCellValue(inst.getCharge()
                                                                                        ? inst.getTotalValue()
                                                                                        : 0);
                                                                                c3.setCellStyle(cs3);

                                                                                Cell c4 = r.createCell(
                                                                                        3 + psCellIndex);
                                                                                CellStyle cs4 = rowStyle
                                                                                        .getCellStyle(
                                                                                                3 + psCellIndex,
                                                                                                wb.createCellStyle());
                                                                                c4.setCellFormula(rCol
                                                                                        + (psRowIndex + 1) + "*"
                                                                                        + chargeCol
                                                                                        + (psRowIndex
                                                                                                + currentRowIndex)
                                                                                        + "*(1-" + rCol
                                                                                        + (psRowIndex + 2)
                                                                                        + ")");
                                                                                if (!fSameCurrency)
                                                                                    cs4.setDataFormat(psS
                                                                                            .getWorkbook()
                                                                                            .createDataFormat()
                                                                                            .getFormat(format));
                                                                                c4.setCellStyle(cs4);

                                                                                /*Cell c5 = r.createCell(4 + psCellIndex);
                                                                                CellStyle cs5 = rowStyle.getCellStyle(4 + psCellIndex, wb.createCellStyle());
                                                                                c5.setCellValue(inst.getOnsiteTotalValue());
                                                                                c5.setCellStyle(cs5);
                                                                                        
                                                                                Cell c6 = r.createCell(5 + psCellIndex);
                                                                                CellStyle cs6 = rowStyle.getCellStyle(5 + psCellIndex, wb.createCellStyle());
                                                                                c6.setCellValue(inst.getTripTotalValue());
                                                                                c6.setCellStyle(cs6);*/

                                                                                for (int y = 4
                                                                                        + psCellIndex; y <= rowStyle
                                                                                                .getLast(); y++) {
                                                                                    CellStyle tcs = rowStyle
                                                                                            .getCellStyle(y,
                                                                                                    null);
                                                                                    if (tcs != null) {
                                                                                        Cell tc = r
                                                                                                .createCell(y);
                                                                                        tc.setCellStyle(tcs);
                                                                                    }
                                                                                }
                                                                                i++;
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            currentRowIndexTo = currentRowIndex;
                                            {
                                                if (psS.getLastRowNum() >= psRowIndex + i) {
                                                    psS.shiftRows(psRowIndex + i, psS.getLastRowNum(), 1);
                                                }
                                                RowStyle rowStyle = psRowStyles
                                                        .get((int) (currentRowIndex - psRowStyles.size() * Math
                                                                .floor(currentRowIndex / psRowStyles.size())));
                                                currentRowIndex++;
                                                Row r = psS.createRow(psRowIndex + i);
                                                for (int y = rowStyle.getFirst(); y < 0 + psCellIndex; y++) {
                                                    CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                    if (tcs != null) {
                                                        Cell tc = r.createCell(y);
                                                        tc.setCellStyle(tcs);
                                                    }
                                                }
                                                Cell c1 = r.createCell(0 + psCellIndex);
                                                CellStyle cs1 = rowStyle.getCellStyle(0 + psCellIndex,
                                                        wb.createCellStyle());
                                                cs1.setWrapText(true);
                                                c1.setCellValue("");
                                                c1.setCellStyle(cs1);

                                                for (int y = 1 + psCellIndex; y <= rowStyle.getLast(); y++) {
                                                    CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                    if (tcs != null) {
                                                        Cell tc = r.createCell(y);
                                                        tc.setCellStyle(tcs);
                                                    }
                                                }
                                                i++;
                                            }
                                            {
                                                sTotal = currentRowIndex;
                                                if (psS.getLastRowNum() >= psRowIndex + i) {
                                                    psS.shiftRows(psRowIndex + i, psS.getLastRowNum(), 1);
                                                }
                                                RowStyle rowStyle = psRowStyles
                                                        .get((int) (currentRowIndex - psRowStyles.size() * Math
                                                                .floor(currentRowIndex / psRowStyles.size())));
                                                currentRowIndex++;
                                                Row r = psS.createRow(psRowIndex + i);
                                                for (int y = rowStyle.getFirst(); y < 0 + psCellIndex; y++) {
                                                    CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                    if (tcs != null) {
                                                        Cell tc = r.createCell(y);
                                                        tc.setCellStyle(tcs);
                                                    }
                                                }
                                                Cell c1 = r.createCell(0 + psCellIndex);
                                                CellStyle cs1 = rowStyle.getCellStyle(0 + psCellIndex,
                                                        wb.createCellStyle());
                                                cs1.setWrapText(true);
                                                c1.setCellValue("Services total:");
                                                c1.setCellStyle(cs1);

                                                Cell c2 = r.createCell(1 + psCellIndex);
                                                CellStyle cs2 = rowStyle.getCellStyle(1 + psCellIndex,
                                                        wb.createCellStyle());
                                                c2.setCellFormula("SUM(" + rCol
                                                        + (psRowIndex + currentRowIndexFrom) + ":" + rCol
                                                        + (psRowIndex + currentRowIndexTo) + ")");
                                                c2.setCellStyle(cs2);

                                                Cell c3 = r.createCell(2 + psCellIndex);
                                                CellStyle cs3 = rowStyle.getCellStyle(2 + psCellIndex,
                                                        wb.createCellStyle());
                                                cs3.setWrapText(true);
                                                c3.setCellValue("");
                                                c3.setCellStyle(cs3);

                                                Cell c4 = r.createCell(3 + psCellIndex);
                                                CellStyle cs4 = rowStyle.getCellStyle(3 + psCellIndex,
                                                        wb.createCellStyle());
                                                c4.setCellFormula("SUM(" + totalCol
                                                        + (psRowIndex + currentRowIndexFrom) + ":" + totalCol
                                                        + (psRowIndex + currentRowIndexTo) + ")");
                                                if (!fSameCurrency)
                                                    cs4.setDataFormat(psS.getWorkbook().createDataFormat()
                                                            .getFormat(format));
                                                c4.setCellStyle(cs4);

                                                for (int y = 4 + psCellIndex; y <= rowStyle.getLast(); y++) {
                                                    CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                    if (tcs != null) {
                                                        Cell tc = r.createCell(y);
                                                        tc.setCellStyle(tcs);
                                                    }
                                                }

                                                i++;
                                            }

                                            int currentRowIndexFromTC = -1;
                                            int currentRowIndexToTC = -1;
                                            if (psq.getTrainingCoursesCount() > 0) {
                                                {
                                                    if (psS.getLastRowNum() >= psRowIndex + i) {
                                                        psS.shiftRows(psRowIndex + i, psS.getLastRowNum(), 1);
                                                    }
                                                    RowStyle rowStyle = psRowStyles.get((int) (currentRowIndex
                                                            - psRowStyles.size() * Math.floor(
                                                                    currentRowIndex / psRowStyles.size())));
                                                    currentRowIndex++;
                                                    Row r = psS.createRow(psRowIndex + i);
                                                    for (int y = rowStyle.getFirst(); y < 0
                                                            + psCellIndex; y++) {
                                                        CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                        if (tcs != null) {
                                                            Cell tc = r.createCell(y);
                                                            tc.setCellStyle(tcs);
                                                        }
                                                    }
                                                    Cell c1 = r.createCell(0 + psCellIndex);
                                                    CellStyle cs1 = rowStyle.getCellStyle(0 + psCellIndex,
                                                            wb.createCellStyle());
                                                    cs1.setWrapText(true);
                                                    c1.setCellValue("");
                                                    c1.setCellStyle(cs1);

                                                    for (int y = 1 + psCellIndex; y <= rowStyle
                                                            .getLast(); y++) {
                                                        CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                        if (tcs != null) {
                                                            Cell tc = r.createCell(y);
                                                            tc.setCellStyle(tcs);
                                                        }
                                                    }
                                                    i++;
                                                }
                                                {
                                                    if (psS.getLastRowNum() >= psRowIndex + i) {
                                                        psS.shiftRows(psRowIndex + i, psS.getLastRowNum(), 1);
                                                    }
                                                    RowStyle rowStyle = psRowStyles.get((int) (currentRowIndex
                                                            - psRowStyles.size() * Math.floor(
                                                                    currentRowIndex / psRowStyles.size())));
                                                    currentRowIndex++;
                                                    Row r = psS.createRow(psRowIndex + i);
                                                    for (int y = rowStyle.getFirst(); y < 0
                                                            + psCellIndex; y++) {
                                                        CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                        if (tcs != null) {
                                                            Cell tc = r.createCell(y);
                                                            tc.setCellStyle(tcs);
                                                        }
                                                    }
                                                    Cell c1 = r.createCell(0 + psCellIndex);
                                                    CellStyle cs1 = rowStyle.getCellStyle(0 + psCellIndex,
                                                            wb.createCellStyle());
                                                    cs1.setWrapText(true);
                                                    c1.setCellValue("");
                                                    c1.setCellStyle(cs1);

                                                    for (int y = 1 + psCellIndex; y <= rowStyle
                                                            .getLast(); y++) {
                                                        CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                        if (tcs != null) {
                                                            Cell tc = r.createCell(y);
                                                            tc.setCellStyle(tcs);
                                                        }
                                                    }
                                                    i++;
                                                }

                                                {
                                                    if (psS.getLastRowNum() >= psRowIndex + i) {
                                                        psS.shiftRows(psRowIndex + i, psS.getLastRowNum(), 1);
                                                    }
                                                    RowStyle rowStyle = psRowStyles.get((int) (currentRowIndex
                                                            - psRowStyles.size() * Math.floor(
                                                                    currentRowIndex / psRowStyles.size())));
                                                    currentRowIndex++;
                                                    Row r = psS.createRow(psRowIndex + i);
                                                    for (int y = rowStyle.getFirst(); y < 0
                                                            + psCellIndex; y++) {
                                                        CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                        if (tcs != null) {
                                                            Cell tc = r.createCell(y);
                                                            tc.setCellStyle(tcs);
                                                        }
                                                    }
                                                    Cell c1 = r.createCell(0 + psCellIndex);
                                                    CellStyle cs1 = rowStyle.getCellStyle(0 + psCellIndex,
                                                            wb.createCellStyle());
                                                    cs1.setWrapText(true);
                                                    c1.setCellValue("Training course:");
                                                    c1.setCellStyle(cs1);

                                                    Cell c2 = r.createCell(1 + psCellIndex);
                                                    CellStyle cs2 = rowStyle.getCellStyle(1 + psCellIndex,
                                                            wb.createCellStyle());
                                                    cs2.setWrapText(true);
                                                    c2.setCellValue("Cost per person:");
                                                    c2.setCellStyle(cs2);

                                                    Cell c3 = r.createCell(2 + psCellIndex);
                                                    CellStyle cs3 = rowStyle.getCellStyle(2 + psCellIndex,
                                                            wb.createCellStyle());
                                                    cs3.setWrapText(true);
                                                    c3.setCellValue("Number of participants:");
                                                    c3.setCellStyle(cs3);

                                                    Cell c4 = r.createCell(3 + psCellIndex);
                                                    CellStyle cs4 = rowStyle.getCellStyle(3 + psCellIndex,
                                                            wb.createCellStyle());
                                                    cs4.setWrapText(true);
                                                    c4.setCellValue("$$:");
                                                    c4.setCellStyle(cs4);

                                                    for (int y = 4 + psCellIndex; y <= rowStyle
                                                            .getLast(); y++) {
                                                        CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                        if (tcs != null) {
                                                            Cell tc = r.createCell(y);
                                                            tc.setCellStyle(tcs);
                                                        }
                                                    }

                                                    i++;
                                                }
                                                {
                                                    if (psS.getLastRowNum() >= psRowIndex + i) {
                                                        psS.shiftRows(psRowIndex + i, psS.getLastRowNum(), 1);
                                                    }
                                                    RowStyle rowStyle = psRowStyles.get((int) (currentRowIndex
                                                            - psRowStyles.size() * Math.floor(
                                                                    currentRowIndex / psRowStyles.size())));
                                                    currentRowIndex++;
                                                    Row r = psS.createRow(psRowIndex + i);
                                                    for (int y = rowStyle.getFirst(); y < 0
                                                            + psCellIndex; y++) {
                                                        CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                        if (tcs != null) {
                                                            Cell tc = r.createCell(y);
                                                            tc.setCellStyle(tcs);
                                                        }
                                                    }
                                                    Cell c1 = r.createCell(0 + psCellIndex);
                                                    CellStyle cs1 = rowStyle.getCellStyle(0 + psCellIndex,
                                                            wb.createCellStyle());
                                                    cs1.setWrapText(true);
                                                    c1.setCellValue("");
                                                    c1.setCellStyle(cs1);

                                                    for (int y = 1 + psCellIndex; y <= rowStyle
                                                            .getLast(); y++) {
                                                        CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                        if (tcs != null) {
                                                            Cell tc = r.createCell(y);
                                                            tc.setCellStyle(tcs);
                                                        }
                                                    }
                                                    i++;
                                                }
                                                for (TrainingCourse ttc : psq.getTrainingCourses().values()) {
                                                    if (!ttc.getInclude()) {
                                                        continue;
                                                    }
                                                    if (currentRowIndexFromTC < 0) {
                                                        currentRowIndexFromTC = currentRowIndex + 1;
                                                    }
                                                    if (psS.getLastRowNum() >= psRowIndex + i) {
                                                        psS.shiftRows(psRowIndex + i, psS.getLastRowNum(), 1);
                                                    }
                                                    RowStyle rowStyle = psRowStyles.get((int) (currentRowIndex
                                                            - psRowStyles.size() * Math.floor(
                                                                    currentRowIndex / psRowStyles.size())));
                                                    currentRowIndex++;
                                                    Row r = psS.createRow(psRowIndex + i);
                                                    for (int y = rowStyle.getFirst(); y < 0
                                                            + psCellIndex; y++) {
                                                        CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                        if (tcs != null) {
                                                            Cell tc = r.createCell(y);
                                                            tc.setCellStyle(tcs);
                                                        }
                                                    }
                                                    Cell c1 = r.createCell(0 + psCellIndex);
                                                    CellStyle cs1 = rowStyle.getCellStyle(0 + psCellIndex,
                                                            wb.createCellStyle());
                                                    cs1.setWrapText(true);
                                                    c1.setCellValue(ttc.getTrainingCourse().getName());
                                                    c1.setCellStyle(cs1);

                                                    Cell c2 = r.createCell(1 + psCellIndex);
                                                    CellStyle cs2 = rowStyle.getCellStyle(1 + psCellIndex,
                                                            wb.createCellStyle());
                                                    c2.setCellValue(!getCurrentProposalForm().getProposal()
                                                            .getConfig().isSalesSupport()
                                                                    ? ttc.getPricePerAttendee()
                                                                    : 0);
                                                    if (!fSameCurrency)
                                                        cs2.setDataFormat(psS.getWorkbook().createDataFormat()
                                                                .getFormat(format));
                                                    c2.setCellStyle(cs2);

                                                    Cell c3 = r.createCell(2 + psCellIndex);
                                                    CellStyle cs3 = rowStyle.getCellStyle(2 + psCellIndex,
                                                            wb.createCellStyle());
                                                    cs3.setWrapText(true);
                                                    c3.setCellValue(ttc.getAttendees());
                                                    c3.setCellStyle(cs3);

                                                    Cell c4 = r.createCell(3 + psCellIndex);
                                                    CellStyle cs4 = rowStyle.getCellStyle(3 + psCellIndex,
                                                            wb.createCellStyle());
                                                    c4.setCellValue(
                                                            !getCurrentProposalForm().getProposal().getConfig()
                                                                    .isSalesSupport() ? ttc.getRegionalPrice()
                                                                            : 0);
                                                    if (!fSameCurrency)
                                                        cs4.setDataFormat(psS.getWorkbook().createDataFormat()
                                                                .getFormat(format));
                                                    c4.setCellStyle(cs4);

                                                    for (int y = 4 + psCellIndex; y <= rowStyle
                                                            .getLast(); y++) {
                                                        CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                        if (tcs != null) {
                                                            Cell tc = r.createCell(y);
                                                            tc.setCellStyle(tcs);
                                                        }
                                                    }

                                                    i++;
                                                }
                                                currentRowIndexToTC = currentRowIndex;
                                                {
                                                    if (psS.getLastRowNum() >= psRowIndex + i) {
                                                        psS.shiftRows(psRowIndex + i, psS.getLastRowNum(), 1);
                                                    }
                                                    RowStyle rowStyle = psRowStyles.get((int) (currentRowIndex
                                                            - psRowStyles.size() * Math.floor(
                                                                    currentRowIndex / psRowStyles.size())));
                                                    currentRowIndex++;
                                                    Row r = psS.createRow(psRowIndex + i);
                                                    for (int y = rowStyle.getFirst(); y < 0
                                                            + psCellIndex; y++) {
                                                        CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                        if (tcs != null) {
                                                            Cell tc = r.createCell(y);
                                                            tc.setCellStyle(tcs);
                                                        }
                                                    }
                                                    Cell c1 = r.createCell(0 + psCellIndex);
                                                    CellStyle cs1 = rowStyle.getCellStyle(0 + psCellIndex,
                                                            wb.createCellStyle());
                                                    cs1.setWrapText(true);
                                                    c1.setCellValue("");
                                                    c1.setCellStyle(cs1);

                                                    for (int y = 1 + psCellIndex; y <= rowStyle
                                                            .getLast(); y++) {
                                                        CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                        if (tcs != null) {
                                                            Cell tc = r.createCell(y);
                                                            tc.setCellStyle(tcs);
                                                        }
                                                    }
                                                    i++;
                                                }
                                                {
                                                    tTotal = currentRowIndex;
                                                    if (psS.getLastRowNum() >= psRowIndex + i) {
                                                        psS.shiftRows(psRowIndex + i, psS.getLastRowNum(), 1);
                                                    }
                                                    RowStyle rowStyle = psRowStyles.get((int) (currentRowIndex
                                                            - psRowStyles.size() * Math.floor(
                                                                    currentRowIndex / psRowStyles.size())));
                                                    currentRowIndex++;
                                                    Row r = psS.createRow(psRowIndex + i);
                                                    for (int y = rowStyle.getFirst(); y < 0
                                                            + psCellIndex; y++) {
                                                        CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                        if (tcs != null) {
                                                            Cell tc = r.createCell(y);
                                                            tc.setCellStyle(tcs);
                                                        }
                                                    }
                                                    Cell c1 = r.createCell(0 + psCellIndex);
                                                    CellStyle cs1 = rowStyle.getCellStyle(0 + psCellIndex,
                                                            wb.createCellStyle());
                                                    cs1.setWrapText(true);
                                                    c1.setCellValue("Training courses total:");
                                                    c1.setCellStyle(cs1);

                                                    Cell c2 = r.createCell(1 + psCellIndex);
                                                    CellStyle cs2 = rowStyle.getCellStyle(1 + psCellIndex,
                                                            wb.createCellStyle());
                                                    cs2.setWrapText(true);
                                                    c2.setCellValue("");
                                                    c2.setCellStyle(cs2);

                                                    Cell c3 = r.createCell(2 + psCellIndex);
                                                    CellStyle cs3 = rowStyle.getCellStyle(2 + psCellIndex,
                                                            wb.createCellStyle());
                                                    cs3.setWrapText(true);
                                                    c3.setCellValue("");
                                                    c3.setCellStyle(cs3);

                                                    Cell c4 = r.createCell(3 + psCellIndex);
                                                    CellStyle cs4 = rowStyle.getCellStyle(3 + psCellIndex,
                                                            wb.createCellStyle());
                                                    c4.setCellFormula("SUM(" + totalCol
                                                            + (psRowIndex + currentRowIndexFromTC) + ":"
                                                            + totalCol + (psRowIndex + currentRowIndexToTC)
                                                            + ")");
                                                    if (!fSameCurrency)
                                                        cs4.setDataFormat(psS.getWorkbook().createDataFormat()
                                                                .getFormat(format));
                                                    c4.setCellStyle(cs4);

                                                    for (int y = 4 + psCellIndex; y <= rowStyle
                                                            .getLast(); y++) {
                                                        CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                        if (tcs != null) {
                                                            Cell tc = r.createCell(y);
                                                            tc.setCellStyle(tcs);
                                                        }
                                                    }

                                                    i++;
                                                }
                                            }

                                            {
                                                if (psS.getLastRowNum() >= psRowIndex + i) {
                                                    psS.shiftRows(psRowIndex + i, psS.getLastRowNum(), 1);
                                                }
                                                RowStyle rowStyle = psRowStyles
                                                        .get((int) (currentRowIndex - psRowStyles.size() * Math
                                                                .floor(currentRowIndex / psRowStyles.size())));
                                                currentRowIndex++;
                                                Row r = psS.createRow(psRowIndex + i);
                                                for (int y = rowStyle.getFirst(); y < 0 + psCellIndex; y++) {
                                                    CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                    if (tcs != null) {
                                                        Cell tc = r.createCell(y);
                                                        tc.setCellStyle(tcs);
                                                    }
                                                }
                                                Cell c1 = r.createCell(0 + psCellIndex);
                                                CellStyle cs1 = rowStyle.getCellStyle(0 + psCellIndex,
                                                        wb.createCellStyle());
                                                cs1.setWrapText(true);
                                                c1.setCellValue("");
                                                c1.setCellStyle(cs1);

                                                for (int y = 1 + psCellIndex; y <= rowStyle.getLast(); y++) {
                                                    CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                    if (tcs != null) {
                                                        Cell tc = r.createCell(y);
                                                        tc.setCellStyle(tcs);
                                                    }
                                                }
                                                i++;
                                            }
                                            {
                                                if (psS.getLastRowNum() >= psRowIndex + i) {
                                                    psS.shiftRows(psRowIndex + i, psS.getLastRowNum(), 1);
                                                }
                                                RowStyle rowStyle = psRowStyles
                                                        .get((int) (currentRowIndex - psRowStyles.size() * Math
                                                                .floor(currentRowIndex / psRowStyles.size())));
                                                currentRowIndex++;
                                                Row r = psS.createRow(psRowIndex + i);
                                                for (int y = rowStyle.getFirst(); y < 0 + psCellIndex; y++) {
                                                    CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                    if (tcs != null) {
                                                        Cell tc = r.createCell(y);
                                                        tc.setCellStyle(tcs);
                                                    }
                                                }
                                                Cell c1 = r.createCell(0 + psCellIndex);
                                                CellStyle cs1 = rowStyle.getCellStyle(0 + psCellIndex,
                                                        wb.createCellStyle());
                                                cs1.setWrapText(true);
                                                c1.setCellValue("Total cost discount:");
                                                c1.setCellStyle(cs1);

                                                Cell c2 = r.createCell(1 + psCellIndex);
                                                CellStyle cs2 = rowStyle.getCellStyle(1 + psCellIndex,
                                                        wb.createCellStyle());
                                                c2.setCellValue(
                                                        !getCurrentProposalForm().getProposal().getConfig()
                                                                .isSalesSupport() ? psq.getPSDiscount() : 0);
                                                cs2.setDataFormat(
                                                        s.getWorkbook().createDataFormat().getFormat("0%;-0%"));
                                                c2.setCellStyle(cs2);

                                                Cell c3 = r.createCell(2 + psCellIndex);
                                                CellStyle cs3 = rowStyle.getCellStyle(2 + psCellIndex,
                                                        wb.createCellStyle());
                                                cs3.setWrapText(true);
                                                c3.setCellValue("");
                                                c3.setCellStyle(cs3);

                                                Cell c4 = r.createCell(3 + psCellIndex);
                                                CellStyle cs4 = rowStyle.getCellStyle(3 + psCellIndex,
                                                        wb.createCellStyle());
                                                c4.setCellFormula("(1-" + rCol + (psRowIndex + currentRowIndex)
                                                        + ")*(" + totalCol + (psRowIndex + sTotal + 1) + "+"
                                                        + totalCol + (psRowIndex + tTotal + 1) + ")");
                                                if (!fSameCurrency)
                                                    cs4.setDataFormat(psS.getWorkbook().createDataFormat()
                                                            .getFormat(format));
                                                c4.setCellStyle(cs4);

                                                for (int y = 4 + psCellIndex; y <= rowStyle.getLast(); y++) {
                                                    CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                    if (tcs != null) {
                                                        Cell tc = r.createCell(y);
                                                        tc.setCellStyle(tcs);
                                                    }
                                                }

                                                i++;
                                            }
                                        }

                                        com.compassplus.proposalModel.OracleQuote oq = getCurrentProposalForm()
                                                .getProposal().getOracleQuote();
                                        //Oracle
                                        int j = i;
                                        i = 0;
                                        currentRowIndex = 0;
                                        if (isOQ) {
                                            int sTotal = -1;
                                            int tTotal = -1;

                                            int currentRowIndexFrom = -1;
                                            int currentRowIndexTo = -1;
                                            String rCol = CellReference.convertNumToColString(1 + oCellIndex);
                                            String licCol = CellReference.convertNumToColString(2 + oCellIndex);
                                            String supCol = CellReference.convertNumToColString(4 + oCellIndex);
                                            String totCol = CellReference.convertNumToColString(5 + oCellIndex);
                                            String disCol = CellReference.convertNumToColString(6 + oCellIndex);
                                            String cpCol = CellReference.convertNumToColString(7 + oCellIndex);
                                            String custCol = CellReference
                                                    .convertNumToColString(8 + oCellIndex);

                                            String format = (getCurrentProposalForm().getProposal()
                                                    .getCurrency().getSymbol() != null
                                                            ? "\"" + getCurrentProposalForm().getProposal()
                                                                    .getCurrency().getSymbol() + "\" "
                                                            : "")
                                                    + "#,##0"
                                                    + (getCurrentProposalForm().getProposal().getCurrency()
                                                            .getSymbol() == null ? " \""
                                                                    + getCurrentProposalForm().getProposal()
                                                                            .getCurrency().getName()
                                                                    + "\"" : "");
                                            boolean first = true;
                                            for (com.compassplus.proposalModel.OracleLicense ol : oq
                                                    .getOracleLicenses().values()) {
                                                if (ol.isMemberOfAnotherBox()) {
                                                    continue;
                                                }
                                                if (!first) {
                                                    if (oS.getLastRowNum() >= oRowIndex + i) {
                                                        oS.shiftRows(oRowIndex + i, oS.getLastRowNum(), 1);
                                                    }
                                                    RowStyle rowStyle = oRowStyles.get((int) (currentRowIndex
                                                            - oRowStyles.size() * Math.floor(
                                                                    currentRowIndex / oRowStyles.size())));
                                                    currentRowIndex++;
                                                    Row r = oS.createRow(oRowIndex + i);
                                                    for (int y = rowStyle.getFirst(); y < 0 + oCellIndex; y++) {
                                                        CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                        if (tcs != null) {
                                                            Cell tc = r.createCell(y);
                                                            tc.setCellStyle(tcs);
                                                        }
                                                    }
                                                    Cell c1 = r.createCell(0 + oCellIndex);
                                                    CellStyle cs1 = rowStyle.getCellStyle(0 + oCellIndex,
                                                            wb.createCellStyle());
                                                    cs1.setWrapText(true);
                                                    c1.setCellValue("");
                                                    c1.setCellStyle(cs1);

                                                    for (int y = 1 + oCellIndex; y <= rowStyle.getLast(); y++) {
                                                        CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                        if (tcs != null) {
                                                            Cell tc = r.createCell(y);
                                                            tc.setCellStyle(tcs);
                                                        }
                                                    }
                                                    i++;
                                                } else {
                                                    first = false;
                                                }
                                                {
                                                    if (oS.getLastRowNum() >= oRowIndex + i) {
                                                        oS.shiftRows(oRowIndex + i, oS.getLastRowNum(), 1);
                                                    }
                                                    RowStyle rowStyle = oRowStyles.get((int) (currentRowIndex
                                                            - oRowStyles.size() * Math.floor(
                                                                    currentRowIndex / oRowStyles.size())));
                                                    currentRowIndex++;
                                                    Row r = oS.createRow(oRowIndex + i);
                                                    for (int y = rowStyle.getFirst(); y < 0 + oCellIndex; y++) {
                                                        CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                        if (tcs != null) {
                                                            Cell tc = r.createCell(y);
                                                            tc.setCellStyle(tcs);
                                                        }
                                                    }
                                                    Cell c1 = r.createCell(0 + oCellIndex);
                                                    CellStyle cs1 = rowStyle.getCellStyle(0 + oCellIndex,
                                                            wb.createCellStyle());
                                                    cs1.setWrapText(true);
                                                    c1.setCellValue(ol.getProductKey());
                                                    c1.setCellStyle(cs1);

                                                    for (int y = 1 + oCellIndex; y <= rowStyle.getLast(); y++) {
                                                        CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                        if (tcs != null) {
                                                            Cell tc = r.createCell(y);
                                                            tc.setCellStyle(tcs);
                                                        }
                                                    }

                                                    i++;
                                                }

                                                {
                                                    if (oS.getLastRowNum() >= oRowIndex + i) {
                                                        oS.shiftRows(oRowIndex + i, oS.getLastRowNum(), 1);
                                                    }
                                                    RowStyle rowStyle = oRowStyles.get((int) (currentRowIndex
                                                            - oRowStyles.size() * Math.floor(
                                                                    currentRowIndex / oRowStyles.size())));
                                                    currentRowIndex++;
                                                    Row r = oS.createRow(oRowIndex + i);
                                                    for (int y = rowStyle.getFirst(); y < 0 + oCellIndex; y++) {
                                                        CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                        if (tcs != null) {
                                                            Cell tc = r.createCell(y);
                                                            tc.setCellStyle(tcs);
                                                        }
                                                    }
                                                    Cell c1 = r.createCell(0 + oCellIndex);
                                                    CellStyle cs1 = rowStyle.getCellStyle(0 + oCellIndex,
                                                            wb.createCellStyle());
                                                    cs1.setWrapText(true);
                                                    c1.setCellValue("");
                                                    c1.setCellStyle(cs1);

                                                    Cell c2 = r.createCell(1 + oCellIndex);
                                                    CellStyle cs2 = rowStyle.getCellStyle(1 + oCellIndex,
                                                            wb.createCellStyle());
                                                    cs2.setWrapText(true);
                                                    c2.setCellValue("");
                                                    c2.setCellStyle(cs2);

                                                    Cell c3 = r.createCell(2 + oCellIndex);
                                                    CellStyle cs3 = rowStyle.getCellStyle(2 + oCellIndex,
                                                            wb.createCellStyle());
                                                    cs3.setWrapText(true);
                                                    c3.setCellValue("License price");
                                                    c3.setCellStyle(cs3);

                                                    Cell c4 = r.createCell(3 + oCellIndex);
                                                    CellStyle cs4 = rowStyle.getCellStyle(3 + oCellIndex,
                                                            wb.createCellStyle());
                                                    cs4.setWrapText(true);
                                                    c4.setCellValue("Options price");
                                                    c4.setCellStyle(cs4);

                                                    Cell c5 = r.createCell(4 + oCellIndex);
                                                    CellStyle cs5 = rowStyle.getCellStyle(4 + oCellIndex,
                                                            wb.createCellStyle());
                                                    cs5.setWrapText(true);
                                                    c5.setCellValue("Support price");
                                                    c5.setCellStyle(cs5);

                                                    Cell c6 = r.createCell(5 + oCellIndex);
                                                    CellStyle cs6 = rowStyle.getCellStyle(5 + oCellIndex,
                                                            wb.createCellStyle());
                                                    cs6.setWrapText(true);
                                                    c6.setCellValue("Total price");
                                                    c6.setCellStyle(cs6);

                                                    Cell c7 = r.createCell(6 + oCellIndex);
                                                    CellStyle cs7 = rowStyle.getCellStyle(6 + oCellIndex,
                                                            wb.createCellStyle());
                                                    cs7.setWrapText(true);
                                                    c7.setCellValue("Discount");
                                                    c7.setCellStyle(cs7);

                                                    Cell c8 = r.createCell(7 + oCellIndex);
                                                    CellStyle cs8 = rowStyle.getCellStyle(7 + oCellIndex,
                                                            wb.createCellStyle());
                                                    cs8.setWrapText(true);
                                                    c8.setCellValue("CP price (total)");
                                                    c8.setCellStyle(cs8);

                                                    Cell c9 = r.createCell(8 + oCellIndex);
                                                    CellStyle cs9 = rowStyle.getCellStyle(8 + oCellIndex,
                                                            wb.createCellStyle());
                                                    cs9.setWrapText(true);
                                                    c9.setCellValue("Customer price");
                                                    c9.setCellStyle(cs9);

                                                    Cell c10 = r.createCell(9 + oCellIndex);
                                                    CellStyle cs10 = rowStyle.getCellStyle(9 + oCellIndex,
                                                            wb.createCellStyle());
                                                    cs10.setWrapText(true);
                                                    c10.setCellValue("Margin");
                                                    c10.setCellStyle(cs10);

                                                    for (int y = 10 + oCellIndex; y <= rowStyle
                                                            .getLast(); y++) {
                                                        CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                        if (tcs != null) {
                                                            Cell tc = r.createCell(y);
                                                            tc.setCellStyle(tcs);
                                                        }
                                                    }

                                                    i++;
                                                }
                                                /*
                                                * Cell c2 = r.createCell(1 + psCellIndex);
                                                    CellStyle cs2 = rowStyle.getCellStyle(1 + psCellIndex, wb.createCellStyle());
                                                    c2.setCellValue(!getCurrentProposalForm().getProposal().getConfig().isSalesSupport()?ttc.getPricePerAttendee():0);
                                                    if (!fSameCurrency)
                                                        cs2.setDataFormat(psS.getWorkbook().createDataFormat().getFormat(format));
                                                    c2.setCellStyle(cs2);
                                                        
                                                        
                                                    Cell c3 = r.createCell(2 + psCellIndex);
                                                    CellStyle cs3 = rowStyle.getCellStyle(2 + psCellIndex, wb.createCellStyle());
                                                    cs3.setWrapText(true);
                                                    c3.setCellValue(ttc.getAttendees());
                                                    c3.setCellStyle(cs3);
                                                * */

                                                {
                                                    if (oS.getLastRowNum() >= oRowIndex + i) {
                                                        oS.shiftRows(oRowIndex + i, oS.getLastRowNum(), 1);
                                                    }
                                                    RowStyle rowStyle = oRowStyles.get((int) (currentRowIndex
                                                            - oRowStyles.size() * Math.floor(
                                                                    currentRowIndex / oRowStyles.size())));
                                                    currentRowIndex++;
                                                    Row r = oS.createRow(oRowIndex + i);
                                                    for (int y = rowStyle.getFirst(); y < 0 + oCellIndex; y++) {
                                                        CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                        if (tcs != null) {
                                                            Cell tc = r.createCell(y);
                                                            tc.setCellStyle(tcs);
                                                        }
                                                    }
                                                    Cell c1 = r.createCell(0 + oCellIndex);
                                                    CellStyle cs1 = rowStyle.getCellStyle(0 + oCellIndex,
                                                            wb.createCellStyle());
                                                    cs1.setWrapText(true);
                                                    c1.setCellValue("License type");
                                                    c1.setCellStyle(cs1);

                                                    Cell c2 = r.createCell(1 + oCellIndex);
                                                    CellStyle cs2 = rowStyle.getCellStyle(1 + oCellIndex,
                                                            wb.createCellStyle());
                                                    cs2.setWrapText(true);
                                                    c2.setCellValue(ol.getOracleLicense().getName());
                                                    c2.setCellStyle(cs2);

                                                    Cell c3 = r.createCell(2 + oCellIndex);
                                                    CellStyle cs3 = rowStyle.getCellStyle(2 + oCellIndex,
                                                            wb.createCellStyle());
                                                    c3.setCellValue(!getCurrentProposalForm().getProposal()
                                                            .getConfig().isSalesSupport() ? ol.getLicensePrice()
                                                                    : 0);
                                                    if (!fSameCurrency)
                                                        cs3.setDataFormat(oS.getWorkbook().createDataFormat()
                                                                .getFormat(format));
                                                    c3.setCellStyle(cs3);

                                                    Cell c4 = r.createCell(3 + oCellIndex);
                                                    CellStyle cs4 = rowStyle.getCellStyle(3 + oCellIndex,
                                                            wb.createCellStyle());
                                                    c4.setCellValue(!getCurrentProposalForm().getProposal()
                                                            .getConfig().isSalesSupport() ? ol.getOptionsPrice()
                                                                    : 0);
                                                    if (!fSameCurrency)
                                                        cs4.setDataFormat(oS.getWorkbook().createDataFormat()
                                                                .getFormat(format));
                                                    c4.setCellStyle(cs4);

                                                    Cell c5 = r.createCell(4 + oCellIndex);
                                                    CellStyle cs5 = rowStyle.getCellStyle(4 + oCellIndex,
                                                            wb.createCellStyle());
                                                    c5.setCellValue(!getCurrentProposalForm().getProposal()
                                                            .getConfig().isSalesSupport()
                                                                    ? ol.getOracleSupportPrice()
                                                                    : 0);
                                                    if (!fSameCurrency)
                                                        cs5.setDataFormat(oS.getWorkbook().createDataFormat()
                                                                .getFormat(format));
                                                    c5.setCellStyle(cs5);

                                                    Cell c6 = r.createCell(5 + oCellIndex);
                                                    CellStyle cs6 = rowStyle.getCellStyle(5 + oCellIndex,
                                                            wb.createCellStyle());
                                                    c6.setCellFormula("SUM(" + licCol
                                                            + (oRowIndex + currentRowIndex) + ":" + supCol
                                                            + (oRowIndex + currentRowIndex) + ")");
                                                    //System.out.println("SUM(" + licCol + oRowIndex + ":" + supCol + oRowIndex + ")");
                                                    if (!fSameCurrency)
                                                        cs6.setDataFormat(oS.getWorkbook().createDataFormat()
                                                                .getFormat(format));
                                                    c6.setCellStyle(cs6);

                                                    Cell c7 = r.createCell(6 + oCellIndex);
                                                    CellStyle cs7 = rowStyle.getCellStyle(6 + oCellIndex,
                                                            wb.createCellStyle());
                                                    cs7.setDataFormat(psS.getWorkbook().createDataFormat()
                                                            .getFormat("0%;-0%"));
                                                    cs7.setWrapText(true);
                                                    c7.setCellValue(ol.getDiscount());
                                                    c7.setCellStyle(cs7);

                                                    /*
                                                    *
                                                    String totCol = CellReference.convertNumToColString(5 + oCellIndex);
                                                    String disCol = CellReference.convertNumToColString(6 + oCellIndex);
                                                    String cpCol = CellReference.convertNumToColString(7 + oCellIndex);
                                                    String custCol = CellReference.convertNumToColString(8 + oCellIndex);
                                                    * */

                                                    Cell c8 = r.createCell(7 + oCellIndex);
                                                    CellStyle cs8 = rowStyle.getCellStyle(7 + oCellIndex,
                                                            wb.createCellStyle());
                                                    c8.setCellFormula("CEILING(" + totCol
                                                            + (oRowIndex + currentRowIndex) + "*(1-" + rCol
                                                            + (oRowIndex + currentRowIndex + 6) + "),1)"); //Customer Price
                                                    if (!fSameCurrency)
                                                        cs8.setDataFormat(oS.getWorkbook().createDataFormat()
                                                                .getFormat(format));
                                                    c8.setCellStyle(cs8);

                                                    Cell c9 = r.createCell(8 + oCellIndex);
                                                    CellStyle cs9 = rowStyle.getCellStyle(8 + oCellIndex,
                                                            wb.createCellStyle());
                                                    c9.setCellFormula("CEILING(" + totCol
                                                            + (oRowIndex + currentRowIndex) + "*(1-" + disCol
                                                            + (oRowIndex + currentRowIndex) + "),1)"); //Customer Price
                                                    //System.out.println("CEILING(" + totCol + (oRowIndex + currentRowIndex) + "*(1-" + disCol + (oRowIndex + currentRowIndex) + "),1)");
                                                    if (!fSameCurrency)
                                                        cs9.setDataFormat(oS.getWorkbook().createDataFormat()
                                                                .getFormat(format));
                                                    c9.setCellStyle(cs9);

                                                    Cell c10 = r.createCell(9 + oCellIndex);
                                                    CellStyle cs10 = rowStyle.getCellStyle(9 + oCellIndex,
                                                            wb.createCellStyle());
                                                    c10.setCellFormula(custCol + (oRowIndex + currentRowIndex)
                                                            + "-" + cpCol + (oRowIndex + currentRowIndex)); //Customer Price
                                                    if (!fSameCurrency)
                                                        cs10.setDataFormat(oS.getWorkbook().createDataFormat()
                                                                .getFormat(format));
                                                    c10.setCellStyle(cs10);

                                                    for (int y = 10 + oCellIndex; y <= rowStyle
                                                            .getLast(); y++) {
                                                        CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                        if (tcs != null) {
                                                            Cell tc = r.createCell(y);
                                                            tc.setCellStyle(tcs);
                                                        }
                                                    }

                                                    i++;
                                                }
                                                {
                                                    if (oS.getLastRowNum() >= oRowIndex + i) {
                                                        oS.shiftRows(oRowIndex + i, oS.getLastRowNum(), 1);
                                                    }
                                                    RowStyle rowStyle = oRowStyles.get((int) (currentRowIndex
                                                            - oRowStyles.size() * Math.floor(
                                                                    currentRowIndex / oRowStyles.size())));
                                                    currentRowIndex++;
                                                    Row r = oS.createRow(oRowIndex + i);
                                                    for (int y = rowStyle.getFirst(); y < 0 + oCellIndex; y++) {
                                                        CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                        if (tcs != null) {
                                                            Cell tc = r.createCell(y);
                                                            tc.setCellStyle(tcs);
                                                        }
                                                    }
                                                    Cell c1 = r.createCell(0 + oCellIndex);
                                                    CellStyle cs1 = rowStyle.getCellStyle(0 + oCellIndex,
                                                            wb.createCellStyle());
                                                    cs1.setWrapText(true);
                                                    c1.setCellValue("Number of cores");
                                                    c1.setCellStyle(cs1);

                                                    Cell c2 = r.createCell(1 + oCellIndex);
                                                    CellStyle cs2 = rowStyle.getCellStyle(1 + oCellIndex,
                                                            wb.createCellStyle());
                                                    cs2.setWrapText(true);
                                                    c2.setCellValue(ol.getCores());
                                                    c2.setCellStyle(cs2);

                                                    for (int y = 2 + oCellIndex; y <= rowStyle.getLast(); y++) {
                                                        CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                        if (tcs != null) {
                                                            Cell tc = r.createCell(y);
                                                            tc.setCellStyle(tcs);
                                                        }
                                                    }

                                                    i++;
                                                }
                                                {
                                                    if (oS.getLastRowNum() >= oRowIndex + i) {
                                                        oS.shiftRows(oRowIndex + i, oS.getLastRowNum(), 1);
                                                    }
                                                    RowStyle rowStyle = oRowStyles.get((int) (currentRowIndex
                                                            - oRowStyles.size() * Math.floor(
                                                                    currentRowIndex / oRowStyles.size())));
                                                    currentRowIndex++;
                                                    Row r = oS.createRow(oRowIndex + i);
                                                    for (int y = rowStyle.getFirst(); y < 0 + oCellIndex; y++) {
                                                        CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                        if (tcs != null) {
                                                            Cell tc = r.createCell(y);
                                                            tc.setCellStyle(tcs);
                                                        }
                                                    }
                                                    Cell c1 = r.createCell(0 + oCellIndex);
                                                    CellStyle cs1 = rowStyle.getCellStyle(0 + oCellIndex,
                                                            wb.createCellStyle());
                                                    cs1.setWrapText(true);
                                                    c1.setCellValue("Model");
                                                    c1.setCellStyle(cs1);

                                                    Cell c2 = r.createCell(1 + oCellIndex);
                                                    CellStyle cs2 = rowStyle.getCellStyle(1 + oCellIndex,
                                                            wb.createCellStyle());
                                                    cs2.setWrapText(true);
                                                    c2.setCellValue(ol.getLicensingModel());
                                                    c2.setCellStyle(cs2);

                                                    for (int y = 2 + oCellIndex; y <= rowStyle.getLast(); y++) {
                                                        CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                        if (tcs != null) {
                                                            Cell tc = r.createCell(y);
                                                            tc.setCellStyle(tcs);
                                                        }
                                                    }

                                                    i++;
                                                }
                                                {
                                                    if (oS.getLastRowNum() >= oRowIndex + i) {
                                                        oS.shiftRows(oRowIndex + i, oS.getLastRowNum(), 1);
                                                    }
                                                    RowStyle rowStyle = oRowStyles.get((int) (currentRowIndex
                                                            - oRowStyles.size() * Math.floor(
                                                                    currentRowIndex / oRowStyles.size())));
                                                    currentRowIndex++;
                                                    Row r = oS.createRow(oRowIndex + i);
                                                    for (int y = rowStyle.getFirst(); y < 0 + oCellIndex; y++) {
                                                        CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                        if (tcs != null) {
                                                            Cell tc = r.createCell(y);
                                                            tc.setCellStyle(tcs);
                                                        }
                                                    }
                                                    Cell c1 = r.createCell(0 + oCellIndex);
                                                    CellStyle cs1 = rowStyle.getCellStyle(0 + oCellIndex,
                                                            wb.createCellStyle());
                                                    cs1.setWrapText(true);
                                                    c1.setCellValue("Coefficient");
                                                    c1.setCellStyle(cs1);

                                                    Cell c2 = r.createCell(1 + oCellIndex);
                                                    CellStyle cs2 = rowStyle.getCellStyle(1 + oCellIndex,
                                                            wb.createCellStyle());
                                                    cs2.setWrapText(true);
                                                    c2.setCellValue(ol.getCoefficient().getValue());
                                                    c2.setCellStyle(cs2);

                                                    for (int y = 2 + oCellIndex; y <= rowStyle.getLast(); y++) {
                                                        CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                        if (tcs != null) {
                                                            Cell tc = r.createCell(y);
                                                            tc.setCellStyle(tcs);
                                                        }
                                                    }

                                                    i++;
                                                }
                                                {
                                                    if (oS.getLastRowNum() >= oRowIndex + i) {
                                                        oS.shiftRows(oRowIndex + i, oS.getLastRowNum(), 1);
                                                    }
                                                    RowStyle rowStyle = oRowStyles.get((int) (currentRowIndex
                                                            - oRowStyles.size() * Math.floor(
                                                                    currentRowIndex / oRowStyles.size())));
                                                    currentRowIndex++;
                                                    Row r = oS.createRow(oRowIndex + i);
                                                    for (int y = rowStyle.getFirst(); y < 0 + oCellIndex; y++) {
                                                        CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                        if (tcs != null) {
                                                            Cell tc = r.createCell(y);
                                                            tc.setCellStyle(tcs);
                                                        }
                                                    }
                                                    Cell c1 = r.createCell(0 + oCellIndex);
                                                    CellStyle cs1 = rowStyle.getCellStyle(0 + oCellIndex,
                                                            wb.createCellStyle());
                                                    cs1.setWrapText(true);
                                                    c1.setCellValue("Included options");
                                                    c1.setCellStyle(cs1);

                                                    String options = "";
                                                    for (String ss : ol.getProduct().getOracleOptions()) {
                                                        OracleOption op = getCurrentProposalForm().getProposal()
                                                                .getConfig().getOracleOptions().get(ss);
                                                        options += ", " + op.getShortName();
                                                    }

                                                    Cell c2 = r.createCell(1 + oCellIndex);
                                                    CellStyle cs2 = rowStyle.getCellStyle(1 + oCellIndex,
                                                            wb.createCellStyle());
                                                    cs2.setWrapText(true);
                                                    c2.setCellValue(
                                                            options.length() > 0 ? options.substring(1) : "");
                                                    c2.setCellStyle(cs2);

                                                    for (int y = 2 + oCellIndex; y <= rowStyle.getLast(); y++) {
                                                        CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                        if (tcs != null) {
                                                            Cell tc = r.createCell(y);
                                                            tc.setCellStyle(tcs);
                                                        }
                                                    }

                                                    i++;
                                                }
                                                /*{
                                                    if (oS.getLastRowNum() >= oRowIndex + i) {
                                                        oS.shiftRows(oRowIndex + i, oS.getLastRowNum(), 1);
                                                    }
                                                    RowStyle rowStyle = oRowStyles.get((int) (currentRowIndex - oRowStyles.size() * Math.floor(currentRowIndex / oRowStyles.size())));
                                                    currentRowIndex++;
                                                    Row r = oS.createRow(oRowIndex + i);
                                                    for (int y = rowStyle.getFirst(); y < 0 + oCellIndex; y++) {
                                                        CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                        if (tcs != null) {
                                                            Cell tc = r.createCell(y);
                                                            tc.setCellStyle(tcs);
                                                        }
                                                    }
                                                    Cell c1 = r.createCell(0 + oCellIndex);
                                                    CellStyle cs1 = rowStyle.getCellStyle(0 + oCellIndex, wb.createCellStyle());
                                                    cs1.setWrapText(true);
                                                    c1.setCellValue("Support rate");
                                                    c1.setCellStyle(cs1);
                                                        
                                                    Cell c2 = r.createCell(1 + oCellIndex);
                                                    CellStyle cs2 = rowStyle.getCellStyle(1 + oCellIndex, wb.createCellStyle());
                                                    cs2.setWrapText(true);
                                                    cs2.setDataFormat(psS.getWorkbook().createDataFormat().getFormat("0%;-0%"));
                                                    c2.setCellValue(ol.getOracleLicense().getSupportRate());
                                                    c2.setCellStyle(cs2);
                                                        
                                                    for (int y = 2 + oCellIndex; y <= rowStyle.getLast(); y++) {
                                                        CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                        if (tcs != null) {
                                                            Cell tc = r.createCell(y);
                                                            tc.setCellStyle(tcs);
                                                        }
                                                    }
                                                        
                                                    i++;
                                                }*/
                                                {
                                                    if (oS.getLastRowNum() >= oRowIndex + i) {
                                                        oS.shiftRows(oRowIndex + i, oS.getLastRowNum(), 1);
                                                    }
                                                    RowStyle rowStyle = oRowStyles.get((int) (currentRowIndex
                                                            - oRowStyles.size() * Math.floor(
                                                                    currentRowIndex / oRowStyles.size())));
                                                    currentRowIndex++;
                                                    Row r = oS.createRow(oRowIndex + i);
                                                    for (int y = rowStyle.getFirst(); y < 0 + oCellIndex; y++) {
                                                        CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                        if (tcs != null) {
                                                            Cell tc = r.createCell(y);
                                                            tc.setCellStyle(tcs);
                                                        }
                                                    }
                                                    Cell c1 = r.createCell(0 + oCellIndex);
                                                    CellStyle cs1 = rowStyle.getCellStyle(0 + oCellIndex,
                                                            wb.createCellStyle());
                                                    cs1.setWrapText(true);
                                                    c1.setCellValue("Maximum discount");
                                                    c1.setCellStyle(cs1);

                                                    Cell c2 = r.createCell(1 + oCellIndex);
                                                    CellStyle cs2 = rowStyle.getCellStyle(1 + oCellIndex,
                                                            wb.createCellStyle());
                                                    cs2.setWrapText(true);
                                                    cs2.setDataFormat(psS.getWorkbook().createDataFormat()
                                                            .getFormat("0%;-0%"));
                                                    c2.setCellValue(ol.getCPDiscount() / 100d);
                                                    c2.setCellStyle(cs2);

                                                    for (int y = 2 + oCellIndex; y <= rowStyle.getLast(); y++) {
                                                        CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                        if (tcs != null) {
                                                            Cell tc = r.createCell(y);
                                                            tc.setCellStyle(tcs);
                                                        }
                                                    }

                                                    i++;
                                                }
                                                {
                                                    if (oS.getLastRowNum() >= oRowIndex + i) {
                                                        oS.shiftRows(oRowIndex + i, oS.getLastRowNum(), 1);
                                                    }
                                                    RowStyle rowStyle = oRowStyles.get((int) (currentRowIndex
                                                            - oRowStyles.size() * Math.floor(
                                                                    currentRowIndex / oRowStyles.size())));
                                                    currentRowIndex++;
                                                    Row r = oS.createRow(oRowIndex + i);
                                                    for (int y = rowStyle.getFirst(); y < 0 + oCellIndex; y++) {
                                                        CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                        if (tcs != null) {
                                                            Cell tc = r.createCell(y);
                                                            tc.setCellStyle(tcs);
                                                        }
                                                    }
                                                    Cell c1 = r.createCell(0 + oCellIndex);
                                                    CellStyle cs1 = rowStyle.getCellStyle(0 + oCellIndex,
                                                            wb.createCellStyle());
                                                    cs1.setWrapText(true);
                                                    c1.setCellValue("Shared");
                                                    c1.setCellStyle(cs1);

                                                    Cell c2 = r.createCell(1 + oCellIndex);
                                                    CellStyle cs2 = rowStyle.getCellStyle(1 + oCellIndex,
                                                            wb.createCellStyle());
                                                    cs2.setWrapText(true);

                                                    String sharedString = "Yes, with";
                                                    for (String ss : ol.getChildren()) {
                                                        sharedString += " " + ss + ",";
                                                    }

                                                    c2.setCellValue(
                                                            ol.isShared()
                                                                    ? sharedString.substring(0,
                                                                            sharedString.length() - 1)
                                                                    : "No");
                                                    c2.setCellStyle(cs2);

                                                    for (int y = 2 + oCellIndex; y <= rowStyle.getLast(); y++) {
                                                        CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                        if (tcs != null) {
                                                            Cell tc = r.createCell(y);
                                                            tc.setCellStyle(tcs);
                                                        }
                                                    }

                                                    i++;
                                                }
                                            }
                                            {
                                                if (oS.getLastRowNum() >= oRowIndex + i) {
                                                    oS.shiftRows(oRowIndex + i, oS.getLastRowNum(), 1);
                                                }
                                                RowStyle rowStyle = oRowStyles
                                                        .get((int) (currentRowIndex - oRowStyles.size() * Math
                                                                .floor(currentRowIndex / oRowStyles.size())));
                                                currentRowIndex++;
                                                Row r = oS.createRow(oRowIndex + i);
                                                for (int y = rowStyle.getFirst(); y < 0 + oCellIndex; y++) {
                                                    CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                    if (tcs != null) {
                                                        Cell tc = r.createCell(y);
                                                        tc.setCellStyle(tcs);
                                                    }
                                                }
                                                Cell c1 = r.createCell(0 + oCellIndex);
                                                CellStyle cs1 = rowStyle.getCellStyle(0 + oCellIndex,
                                                        wb.createCellStyle());
                                                cs1.setWrapText(true);
                                                c1.setCellValue("");
                                                c1.setCellStyle(cs1);

                                                for (int y = 1 + oCellIndex; y <= rowStyle.getLast(); y++) {
                                                    CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                    if (tcs != null) {
                                                        Cell tc = r.createCell(y);
                                                        tc.setCellStyle(tcs);
                                                    }
                                                }
                                                i++;
                                            }
                                            /*{
                                                if (psS.getLastRowNum() >= psRowIndex + i) {
                                                    psS.shiftRows(psRowIndex + i, psS.getLastRowNum(), 1);
                                                }
                                                RowStyle rowStyle = psRowStyles.get((int) (currentRowIndex - psRowStyles.size() * Math.floor(currentRowIndex / psRowStyles.size())));
                                                currentRowIndex++;
                                                Row r = psS.createRow(psRowIndex + i);
                                                for (int y = rowStyle.getFirst(); y < 0 + psCellIndex; y++) {
                                                    CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                    if (tcs != null) {
                                                        Cell tc = r.createCell(y);
                                                        tc.setCellStyle(tcs);
                                                    }
                                                }
                                                Cell c1 = r.createCell(0 + psCellIndex);
                                                CellStyle cs1 = rowStyle.getCellStyle(0 + psCellIndex, wb.createCellStyle());
                                                cs1.setWrapText(true);
                                                c1.setCellValue("");
                                                c1.setCellStyle(cs1);
                                                    
                                                for (int y = 1 + psCellIndex; y <= rowStyle.getLast(); y++) {
                                                    CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                    if (tcs != null) {
                                                        Cell tc = r.createCell(y);
                                                        tc.setCellStyle(tcs);
                                                    }
                                                }
                                                i++;
                                            }
                                            */
                                            {
                                                if (oS.getLastRowNum() >= oRowIndex + i) {
                                                    oS.shiftRows(oRowIndex + i, oS.getLastRowNum(), 1);
                                                }
                                                RowStyle rowStyle = oRowStyles
                                                        .get((int) (currentRowIndex - oRowStyles.size() * Math
                                                                .floor(currentRowIndex / oRowStyles.size())));
                                                currentRowIndex++;
                                                Row r = oS.createRow(oRowIndex + i);
                                                for (int y = rowStyle.getFirst(); y < 0 + oCellIndex; y++) {
                                                    CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                    if (tcs != null) {
                                                        Cell tc = r.createCell(y);
                                                        tc.setCellStyle(tcs);
                                                    }
                                                }
                                                Cell c1 = r.createCell(0 + oCellIndex);
                                                CellStyle cs1 = rowStyle.getCellStyle(0 + oCellIndex,
                                                        wb.createCellStyle());
                                                cs1.setWrapText(true);
                                                c1.setCellValue("Total");
                                                c1.setCellStyle(cs1);

                                                Cell c2 = r.createCell(1 + oCellIndex);
                                                CellStyle cs2 = rowStyle.getCellStyle(1 + oCellIndex,
                                                        wb.createCellStyle());
                                                cs2.setWrapText(true);
                                                c2.setCellValue("");
                                                c2.setCellStyle(cs2);

                                                Cell c3 = r.createCell(2 + oCellIndex);
                                                CellStyle cs3 = rowStyle.getCellStyle(2 + oCellIndex,
                                                        wb.createCellStyle());
                                                c3.setCellValue(
                                                        !getCurrentProposalForm().getProposal().getConfig()
                                                                .isSalesSupport() ? oq.getLicenseTotal() : 0);
                                                if (!fSameCurrency)
                                                    cs3.setDataFormat(oS.getWorkbook().createDataFormat()
                                                            .getFormat(format));
                                                c3.setCellStyle(cs3);

                                                Cell c4 = r.createCell(3 + oCellIndex);
                                                CellStyle cs4 = rowStyle.getCellStyle(3 + oCellIndex,
                                                        wb.createCellStyle());
                                                c4.setCellValue(
                                                        !getCurrentProposalForm().getProposal().getConfig()
                                                                .isSalesSupport() ? oq.getOptionsTotal() : 0);
                                                if (!fSameCurrency)
                                                    cs4.setDataFormat(oS.getWorkbook().createDataFormat()
                                                            .getFormat(format));
                                                c4.setCellStyle(cs4);

                                                Cell c5 = r.createCell(4 + oCellIndex);
                                                CellStyle cs5 = rowStyle.getCellStyle(4 + oCellIndex,
                                                        wb.createCellStyle());
                                                c5.setCellValue(
                                                        !getCurrentProposalForm().getProposal().getConfig()
                                                                .isSalesSupport() ? oq.getSupportTotal() : 0);
                                                if (!fSameCurrency)
                                                    cs5.setDataFormat(oS.getWorkbook().createDataFormat()
                                                            .getFormat(format));
                                                c5.setCellStyle(cs5);

                                                Cell c6 = r.createCell(5 + oCellIndex);
                                                CellStyle cs6 = rowStyle.getCellStyle(5 + oCellIndex,
                                                        wb.createCellStyle());
                                                c6.setCellValue(!getCurrentProposalForm().getProposal()
                                                        .getConfig().isSalesSupport() ? oq.getTotalTotal() : 0);
                                                //System.out.println("SUM(" + licCol + oRowIndex + ":" + supCol + oRowIndex + ")");
                                                if (!fSameCurrency)
                                                    cs6.setDataFormat(oS.getWorkbook().createDataFormat()
                                                            .getFormat(format));
                                                c6.setCellStyle(cs6);

                                                Cell c7 = r.createCell(6 + oCellIndex);
                                                CellStyle cs7 = rowStyle.getCellStyle(6 + oCellIndex,
                                                        wb.createCellStyle());
                                                //cs7.setDataFormat(psS.getWorkbook().createDataFormat().getFormat("0%;-0%"));
                                                cs7.setWrapText(true);
                                                c7.setCellValue("");
                                                c7.setCellStyle(cs7);

                                                /*
                                                *
                                                String totCol = CellReference.convertNumToColString(5 + oCellIndex);
                                                String disCol = CellReference.convertNumToColString(6 + oCellIndex);
                                                String cpCol = CellReference.convertNumToColString(7 + oCellIndex);
                                                String custCol = CellReference.convertNumToColString(8 + oCellIndex);
                                                * */

                                                Cell c8 = r.createCell(7 + oCellIndex);
                                                CellStyle cs8 = rowStyle.getCellStyle(7 + oCellIndex,
                                                        wb.createCellStyle());
                                                c8.setCellValue(!getCurrentProposalForm().getProposal()
                                                        .getConfig().isSalesSupport() ? oq.getCPTotal() : 0);
                                                if (!fSameCurrency)
                                                    cs8.setDataFormat(oS.getWorkbook().createDataFormat()
                                                            .getFormat(format));
                                                c8.setCellStyle(cs8);

                                                Cell c9 = r.createCell(8 + oCellIndex);
                                                CellStyle cs9 = rowStyle.getCellStyle(8 + oCellIndex,
                                                        wb.createCellStyle());
                                                c9.setCellValue(
                                                        !getCurrentProposalForm().getProposal().getConfig()
                                                                .isSalesSupport() ? oq.getCustomerTotal() : 0);
                                                //System.out.println("CEILING(" + totCol + (oRowIndex + currentRowIndex) + "*(1-" + disCol + (oRowIndex + currentRowIndex) + "),1)");
                                                if (!fSameCurrency)
                                                    cs9.setDataFormat(oS.getWorkbook().createDataFormat()
                                                            .getFormat(format));
                                                c9.setCellStyle(cs9);

                                                Cell c10 = r.createCell(9 + oCellIndex);
                                                CellStyle cs10 = rowStyle.getCellStyle(9 + oCellIndex,
                                                        wb.createCellStyle());
                                                c10.setCellValue(
                                                        !getCurrentProposalForm().getProposal().getConfig()
                                                                .isSalesSupport() ? oq.getTotalMargin() : 0);
                                                if (!fSameCurrency)
                                                    cs10.setDataFormat(oS.getWorkbook().createDataFormat()
                                                            .getFormat(format));
                                                c10.setCellStyle(cs10);

                                                for (int y = 10 + oCellIndex; y <= rowStyle.getLast(); y++) {
                                                    CellStyle tcs = rowStyle.getCellStyle(y, null);
                                                    if (tcs != null) {
                                                        Cell tc = r.createCell(y);
                                                        tc.setCellStyle(tcs);
                                                    }
                                                }

                                                i++;
                                            }
                                        }

                                        ArrayList<Row> rowsToRemove = new ArrayList();
                                        ScriptEngineManager factory = new ScriptEngineManager();
                                        ScriptEngine engine = factory.getEngineByName("JavaScript");
                                        Bindings bindings = getBindings(getCurrentProposalForm().getProposal(),
                                                engine);
                                        int dec = 0;
                                        int psDec = 0;
                                        for (int si = 0; si < wb.getNumberOfSheets(); si++) {
                                            Sheet sis = wb.getSheetAt(si);
                                            Iterator<Row> riter = sis.rowIterator();
                                            while (riter.hasNext()) {
                                                Row row = riter.next();
                                                Iterator<Cell> citer = row.cellIterator();
                                                while (citer.hasNext()) {
                                                    Cell cell = citer.next();
                                                    if (analyzeCell(wb, sis, row, cell, engine, bindings)) {
                                                        if (sis.getSheetName() == s.getSheetName()
                                                                && row.getRowNum() < rowIndex) {
                                                            dec++;
                                                        }
                                                        if (sis.getSheetName() == psS.getSheetName()
                                                                && row.getRowNum() < psRowIndex) {
                                                            psDec++;
                                                        }
                                                        if (!rowsToRemove.contains(row)) {
                                                            rowsToRemove.add(row);
                                                        }
                                                    }
                                                }
                                            }
                                            for (Row ri : rowsToRemove) {
                                                removeRow(sis, ri.getRowNum(), wb);
                                            }

                                            rowsToRemove.clear();
                                        }
                                        rowIndex = rowIndex - dec;
                                        psRowIndex = psRowIndex - psDec;

                                        Row settingsRow = settingsSheet.getRow(0);
                                        if (settingsRow == null) {
                                            settingsRow = settingsSheet.createRow(0);
                                        }
                                        CellUtil.createCell(settingsRow, 0,
                                                getCurrentProposalForm().getProposal().toString());
                                        CellUtil.createCell(settingsRow, 1, new Integer(
                                                getCurrentProposalForm().getProposal().getProducts().size())
                                                        .toString());
                                        CellUtil.createCell(settingsRow, 2, cellIndex.toString());
                                        CellUtil.createCell(settingsRow, 3, rowIndex.toString());
                                        CellUtil.createCell(settingsRow, 4, s.getSheetName());

                                        //PS
                                        if (isPSQ) {
                                            CellUtil.createCell(settingsRow, 5, new Integer(j).toString());
                                            CellUtil.createCell(settingsRow, 6, psCellIndex.toString());
                                            CellUtil.createCell(settingsRow, 7, psRowIndex.toString());
                                            CellUtil.createCell(settingsRow, 8, psS.getSheetName());
                                        }

                                        //Oracle
                                        if (isOQ) {
                                            CellUtil.createCell(settingsRow, 9, new Integer(i).toString());
                                            CellUtil.createCell(settingsRow, 10, oCellIndex.toString());
                                            CellUtil.createCell(settingsRow, 11, oRowIndex.toString());
                                            CellUtil.createCell(settingsRow, 12, oS.getSheetName());
                                        }

                                        wb.setSheetHidden(wb.getSheetIndex(settingsSheet), true);
                                        OutputStream out = new FileOutputStream(sfile);
                                        wb.write(out);
                                        out.close();
                                        getCurrentProposalForm().setChanged(false);
                                        JOptionPane.showMessageDialog(getRoot(),
                                                "Proposal successfully exported", "Result",
                                                JOptionPane.INFORMATION_MESSAGE);
                                    } catch (Exception exception) {
                                        exception.printStackTrace();
                                        JOptionPane.showMessageDialog(getRoot(), "Proposal can't be exported",
                                                "Error", JOptionPane.ERROR_MESSAGE);
                                    }
                                } else if (value == JOptionPane.CANCEL_OPTION) {
                                    dialog.dispose();
                                }
                            }
                        } catch (Exception exception) {
                            optionPane.setValue(null);
                        }
                    }
                }
            }
        });
        dialog.pack();
        dialog.setLocationRelativeTo(getRoot());
        dialog.setVisible(true);
    }
}

From source file:com.compomics.cell_coord.parser.impl.XLSFileParser.java

@Override
public Sample parseTrackFile(File trackFile) throws FileParserException {
    List<Track> list = new ArrayList<>();
    // create a new sample object -- watch out to set the relationships!
    Sample sample = new Sample(trackFile.getName());
    try {//w w w  .ja  va  2 s .com
        FileInputStream fileInputStream = new FileInputStream(trackFile);
        Workbook workbook = null;
        // xls extension
        if (trackFile.getName().endsWith("xls")) {
            workbook = new HSSFWorkbook(fileInputStream);
        } else if (trackFile.getName().endsWith("xlsx")) { // xlsx extension
            workbook = new XSSFWorkbook(fileInputStream);
        }
        if (workbook != null) {
            // check that at least one sheet is present
            if (workbook.getNumberOfSheets() > 0) {
                Track currentTrack = null;
                List<TrackSpot> currentTrackPointList = new ArrayList<>();
                Long currentId = 0L;
                Sheet sheet = workbook.getSheetAt(0);
                // iterate through all the rows, starting from the second one to skip the header
                for (int i = 1; i < sheet.getLastRowNum() + 1; i++) {
                    // get the row
                    Row row = sheet.getRow(i);
                    // check the track id
                    Long trackid = (long) row.getCell(0).getNumericCellValue();
                    if (!Objects.equals(currentId, trackid)) {
                        currentTrack = new Track();
                        currentTrack.setTrackid(trackid);
                        list.add(currentTrack);
                        currentId = trackid;
                        currentTrackPointList = new ArrayList<>();
                    }
                    // create new Track Spot object
                    Long spotid = (long) row.getCell(1).getNumericCellValue();
                    double x = row.getCell(2).getNumericCellValue();
                    double y = row.getCell(3).getNumericCellValue();
                    double time = row.getCell(4).getNumericCellValue();
                    TrackSpot trackSpot = new TrackSpot(spotid, x, y, time, currentTrack);
                    currentTrackPointList.add(trackSpot);
                    currentTrack.setTrackSpots(currentTrackPointList);
                    currentTrack.setSample(sample);
                }
            } else {
                throw new FileParserException(
                        "It seems an Excel file does not have any sheets!\nPlease check your files!");
            }
        } else {
            throw new FileParserException("The parser did not find a single workbook!\nCheck your files!!");
        }
    } catch (IOException ex) {
        LOG.error(ex.getMessage(), ex);
    } catch (NumberFormatException ex) {
        LOG.error(ex.getMessage(), ex);
        throw new FileParserException(
                "It seems like a line does not contain a number!\nPlease check your files!");
    }
    sample.setTracks(list);
    return sample;
}

From source file:com.cordys.coe.ac.fileconnector.utils.ExcelRead.java

License:Apache License

/**
 * Validates the reader-config.xml with the Excel file
 *
 * @param vcConfig The validator configuration object.
 * @param filename Name of the Excel file.
 * @param dDoc Document conatins the request.
 * @param iResultNode The record XML structure root node, or zero, if only validation is needed.
 * @param sheetno Sheet index of the Excel file.
 * @param startrow row index from which data to be read.
 * @param endrow   row index upto which data to be read.
 * @param lErrorList LinkedList contains all the errors.
 *///from   www .  j  a v  a2 s .c  o  m
public static void validate(ValidatorConfig vcConfig, String filename, Document dDoc, int iResultNode,
        int sheetno, int startrow, int endrow, List<FileException> lErrorList) {
    try {

        setRecordsread(0);
        setEndoffile(false);

        Workbook book = null;
        Sheet sheet = null;
        Row row;
        FileInputStream fileinp = null;
        //String sRecordName = vcConfig.mConfigMap.get("excel").lRecordList.get(0).sRecordName;
        int sheetindex;
        int noofsheets;
        if (filename == null) {
            throw new FileException(LogMessages.PLEASE_PROVIDE_FILE_NAME);
        }
        File file = new File(filename);
        fileinp = new FileInputStream(filename);
        if (file.exists()) {
            if (file.getName().substring(file.getName().lastIndexOf(".") + 1).equalsIgnoreCase("xls")) {
                try {
                    book = (Workbook) new HSSFWorkbook(fileinp);
                } catch (IOException ex) {
                    Logger.getLogger(ExcelRead.class.getName()).log(Level.SEVERE, null, ex);
                }
            } else if (file.getName().substring(file.getName().lastIndexOf(".") + 1).equalsIgnoreCase("xlsx")) {
                try {
                    book = new XSSFWorkbook(fileinp);
                } catch (IOException ex) {
                    Logger.getLogger(ExcelRead.class.getName()).log(Level.SEVERE, null, ex);
                }
            } else {
                //ERROR
                fileinp.close();
                throw new FileException(LogMessages.INPUT_FILE_NOT_SUPPORTED);
            }
        } else {
            //ERROR
            fileinp.close();
            throw new FileException(LogMessages.FILE_NOT_FOUND);
        }
        if (sheetno != -1) {
            sheetindex = sheetno;
            noofsheets = sheetindex + 1;
        } else {
            sheetindex = 0;
            noofsheets = book.getNumberOfSheets();
        }
        //check whether the sheetindex exists or not
        for (; sheetindex < noofsheets; sheetindex++) {
            if (sheetindex >= book.getNumberOfSheets()) {
                //no sheet
                throw new FileException(LogMessages.NO_SHEET_FOUND, sheetindex);
            }
            sheet = book.getSheetAt(sheetindex);
            if (sheet == null) {
                throw new FileException(LogMessages.NO_SHEET_FOUND, sheetindex);
            }
        }

        //validate columns

        //get last column index
        for (int i = sheet.getFirstRowNum(); i <= sheet.getLastRowNum(); i++) {
            row = sheet.getRow(i);
            if (maxcol < row.getLastCellNum()) {
                maxcol = row.getLastCellNum();
            }
        }
        //check column index in reader-config
        ListIterator fieldslist = vcConfig.mConfigMap.get("excel").lRecordList.get(0).lFieldList.listIterator();
        while (fieldslist.hasNext()) {
            FieldType excelfields = (FieldType) fieldslist.next();
            try {
                if (Short.parseShort(excelfields.sColumnIndex) < 0
                        || Short.parseShort(excelfields.sColumnIndex) >= maxcol) {
                    throw new FileException(LogMessages.COLUMN_INDEX_NOT_FOUND, excelfields.sColumnIndex,
                            (maxcol - 1));
                }
            } catch (NumberFormatException ex) {
                throw new FileException(ex, LogMessages.COLUMN_INDEX_NOT_VALID, excelfields.sColumnIndex);
            }
        }

        if (endrow == -1) {
            endrow = sheet.getLastRowNum();
            if (startrow == -1) {
                startrow = 0;
            }
        } else {
            endrow = startrow + endrow - 1;
            if (endrow > sheet.getLastRowNum()) {
                endrow = sheet.getLastRowNum();
            }
        }

        setRecordsread(endrow - startrow + 1);

    } catch (IOException ex) {
        lErrorList.add(new FileException(ex, LogMessages.IOEXCEPTION_WHILE_READING_FILE, filename));
    } catch (FileException ex) {
        lErrorList.add(ex);
    }

}

From source file:com.cordys.coe.ac.fileconnector.utils.ExcelRead.java

License:Apache License

/**
 * Read records from Excel file/*from   w ww.  j  a v  a  2  s. c  om*/
 *
 * @param vcConfig The validator configuration object.
 * @param bUseTupleOld
 * @param filename Name of the Excel file.
 * @param doc Document conatins the request.
 * @param iResponsenode The record XML structure root node, or zero, if only validation is needed.
 * @param sheetno Sheet index of the Excel file.
 * @param startrow row index from which data to be read.
 * @param endrow   row index upto which data to be read.
 * @param startcolumn column index from which data to be read.
 * @param endcolumn column index upto which data to be read.
 */
public static void readall(ValidatorConfig vcConfig, Boolean bUseTupleOld, String filename, Document doc,
        int iResponsenode, int sheetno, int startrow, int endrow, int startcolumn, int endcolumn)
        throws FileException {

    Workbook book = null;
    Sheet sheet;
    Cell cell;
    Row row;
    FileInputStream fileinp = null;
    String sRecordName = vcConfig.mConfigMap.get("excel").lRecordList.get(0).sRecordName;
    try {
        int iRow, iCol, sheetindex, noofsheets;
        File file = new File(filename);
        fileinp = new FileInputStream(filename);
        if (file.exists()) {
            if (file.getName().substring(file.getName().lastIndexOf(".") + 1).equalsIgnoreCase("xls")) {
                book = (Workbook) new HSSFWorkbook(fileinp);
            } else if (file.getName().substring(file.getName().lastIndexOf(".") + 1).equalsIgnoreCase("xlsx")) {
                book = new XSSFWorkbook(fileinp);
            } else {
                //ERROR
                fileinp.close();
            }
        } else {
            //ERROR
            fileinp.close();
        }

        if (sheetno != -1) {
            sheetindex = sheetno;
            noofsheets = sheetindex + 1;
        } else {
            sheetindex = 0;
            noofsheets = book.getNumberOfSheets();
        }
        for (; sheetindex < noofsheets; sheetindex++) {
            sheet = book.getSheetAt(sheetindex);

            if (endrow == -1) {
                endrow = sheet.getLastRowNum();
                if (startrow == -1) {
                    startrow = 0;
                }
            } else {
                endrow = startrow + endrow - 1;
                if (endrow > sheet.getLastRowNum()) {
                    endrow = sheet.getLastRowNum();
                }
            }

            if (endcolumn == -1) {
                endcolumn = 30;
                if (startcolumn == -1) {
                    startcolumn = 0;
                }
            }
            for (int i = startrow; i <= endrow; i++) {

                row = sheet.getRow(i);

                if (row == null) {
                    int iTup = doc.createElement("tuple", iResponsenode);

                    if (bUseTupleOld) {
                        iTup = doc.createElement("old", iTup);
                    }
                    iRow = doc.createElement(sRecordName, iTup);
                    //Node.setAttribute(iRow, "id", "" + i);
                    ListIterator fieldslist = vcConfig.mConfigMap.get("excel").lRecordList.get(0).lFieldList
                            .listIterator();
                    while (fieldslist.hasNext()) {
                        FieldType excelfields = (FieldType) fieldslist.next();
                        String sColumnName = excelfields.sFieldName;

                        iCol = doc.createTextElement(sColumnName, "", iRow);
                    }
                    continue;
                }
                int iTup = doc.createElement("tuple", iResponsenode);
                if (bUseTupleOld) {
                    iTup = doc.createElement("old", iTup);
                }
                iRow = doc.createElement(sRecordName, iTup);
                ListIterator fieldslist = vcConfig.mConfigMap.get("excel").lRecordList.get(0).lFieldList
                        .listIterator();
                while (fieldslist.hasNext()) {
                    FieldType excelfields = (FieldType) fieldslist.next();
                    int iColumnIndex = Integer.parseInt(excelfields.sColumnIndex);
                    cell = row.getCell(iColumnIndex);
                    String sColumnName = excelfields.sFieldName;
                    if (cell == null) {
                        iCol = doc.createTextElement(sColumnName, "", iRow);
                        continue;
                    }
                    switch (cell.getCellType()) {
                    case Cell.CELL_TYPE_BLANK:
                        iCol = doc.createTextElement(sColumnName, "", iRow);
                        break;
                    case Cell.CELL_TYPE_BOOLEAN:
                        iCol = doc.createTextElement(sColumnName, "" + cell.getBooleanCellValue(), iRow);

                        break;
                    case Cell.CELL_TYPE_ERROR:
                        iCol = doc.createTextElement(sColumnName, "", iRow);
                        break;
                    case Cell.CELL_TYPE_FORMULA:
                        iCol = doc.createTextElement(sColumnName, "" + cell.getCellFormula(), iRow);

                        break;
                    case Cell.CELL_TYPE_NUMERIC:
                        if (HSSFDateUtil.isCellDateFormatted(cell)) {
                            SimpleDateFormat simpledateformat = new SimpleDateFormat(
                                    "yyyy-MM-dd 'T' HH:mm:ss.S");
                            iCol = doc.createTextElement(sColumnName,
                                    "" + simpledateformat.format(cell.getDateCellValue()), iRow);

                        } else {
                            iCol = doc.createTextElement(sColumnName, "" + cell.getNumericCellValue(), iRow);
                        }
                        break;
                    case Cell.CELL_TYPE_STRING:
                        iCol = doc.createTextElement(sColumnName, "" + cell.getStringCellValue(), iRow);
                        break;
                    default:
                        System.out.println("default");
                    }
                }
            }
        }
    } catch (FileNotFoundException e) {
        throw new FileException(e, LogMessages.FILE_NOT_FOUND);
    } catch (IOException e) {
        throw new FileException(e, LogMessages.IOEXCEPTION_WHILE_READING_FILE, filename);
    } finally {
        try {
            fileinp.close();
        } catch (IOException ex) {
            Logger.getLogger(ExcelRead.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:com.crimelab.service.ChemistryServiceImpl.java

@Override
public Workbook create(Chemistry chemistry, HttpSession session) {
    Workbook wb = null;
    try {/*from  ww w  . ja  v a2 s .  c  o m*/

        //            date = sdf.parse(chemistry.getTimeDateReceived());
        //            sdf.applyPattern("M-dd-yyyy hh:mm:ss a");
        //            dateformat = sdf.format(date);
        InputStream inp = session.getServletContext()
                .getResourceAsStream("/WEB-INF/templates/DefaultDrugs.xls");
        wb = WorkbookFactory.create(inp);
        Sheet sheet = wb.getSheetAt(0);

        Cell examType = findCell(sheet, "$examType");
        Cell reportNo = findCell(sheet, "$reportNo");
        Cell caseType = findCell(sheet, "$caseType");
        Cell suspects = findCell(sheet, "$suspects");
        Cell victims = findCell(sheet, "$victims");
        Cell timeDateReceived = findCell(sheet, "$timeDateReceived");
        Cell requestingParty = findCell(sheet, "$requestingParty");
        Cell specimenSubmitted = findCell(sheet, "$specimenSubmitted");
        Cell purposeOfLabExam = findCell(sheet, "$purposeOfLabExam");
        Cell findings = findCell(sheet, "$findings");
        Cell conclusions = findCell(sheet, "$conclusions");
        Cell remarks = findCell(sheet, "$remarks");
        Cell timeDateCompleted = findCell(sheet, "$timeDateCompleted");
        Cell examinerName = findCell(sheet, "$examinerName");
        Cell examinerRank = findCell(sheet, "$examinerRank");
        Cell examinerPosition = findCell(sheet, "$examinerPosition");
        Cell appName = findCell(sheet, "$appName");
        Cell appRank = findCell(sheet, "$appRank");
        Cell appPosition = findCell(sheet, "$appPosition");
        Cell notedName = findCell(sheet, "$notedName");
        Cell notedRank = findCell(sheet, "$notedRank");
        Cell notedPosition = findCell(sheet, "$notedPosition");
        Cell subscribed = findCell(sheet, "$subscribed");
        Cell subscribedName = findCell(sheet, "$subscribedName");
        Cell subscribedRank = findCell(sheet, "$subscribedRank");
        Cell subscribedPosition = findCell(sheet, "$subscribedPosition");

        examType.setCellValue(chemistry.getExamType());
        reportNo.setCellValue(chemistry.getReportNo());
        caseType.setCellValue(chemistry.getCaseType());
        suspects.setCellValue(chemistry.getSuspects());
        victims.setCellValue(chemistry.getVictims());
        timeDateReceived.setCellValue(chemistry.getTimeDateReceived());
        requestingParty.setCellValue(chemistry.getRequestingParty());
        specimenSubmitted.setCellValue(chemistry.getSpecimenSubmitted());
        purposeOfLabExam.setCellValue(chemistry.getPurposeOfLabExam());
        findings.setCellValue(chemistry.getFindings());
        conclusions.setCellValue(chemistry.getConclusions());
        remarks.setCellValue(chemistry.getRemarks());
        timeDateCompleted.setCellValue(chemistry.getTimeDateCompleted());
        examinerName.setCellValue(chemistry.getExaminerName());
        examinerRank.setCellValue(chemistry.getExaminerRank());
        examinerPosition.setCellValue(chemistry.getExaminerPosition());
        appName.setCellValue(chemistry.getAppName());
        appRank.setCellValue(chemistry.getAppRank());
        appPosition.setCellValue(chemistry.getAppPosition());
        notedName.setCellValue(chemistry.getNotedName());
        notedRank.setCellValue(chemistry.getNotedRank());
        notedPosition.setCellValue(chemistry.getNotedPosition());
        subscribed.setCellValue(chemistry.getSubscribed());
        subscribedName.setCellValue(chemistry.getSubscribedName());
        subscribedRank.setCellValue(chemistry.getSubscribedRank());
        subscribedPosition.setCellValue(chemistry.getSubscribedPosition());

        chemistryDAO.chemistryInfo(chemistry);

    } catch (Exception e) {
        e.printStackTrace();

    }
    return wb;
}

From source file:com.crimelab.service.ChemistryServiceImpl.java

@Override
public Workbook createMonthlyReport(HttpSession session, String month) {
    Workbook wb = null;

    try {/*from   w w  w.  j  a  v  a2s .  c  o m*/
        InputStream inp = session.getServletContext()
                .getResourceAsStream("/WEB-INF/templates/DrugMonthlyReport.xls");
        wb = WorkbookFactory.create(inp);
        Sheet sheet = wb.getSheetAt(0);
        CellStyle cs1 = wb.createCellStyle();
        CellStyle cs2 = wb.createCellStyle();
        CellStyle bl = wb.createCellStyle();
        CellStyle br = wb.createCellStyle();
        CellStyle bt = wb.createCellStyle();
        CellStyle bb = wb.createCellStyle();
        CellStyle stf = wb.createCellStyle();
        cs1.setWrapText(true);
        cs2.setAlignment(ALIGN_CENTER);
        bt.setBorderTop(BORDER_THIN);
        bb.setBorderBottom(BORDER_THIN);
        bl.setBorderLeft(BORDER_THIN);
        br.setBorderRight(BORDER_THIN);
        stf.setShrinkToFit(true);

        Row intro1 = sheet.createRow(7);
        Cell in1 = intro1.createCell(0);//.setCellValue("DRUG INVETORY COVERED PERIOD JANUARY-DECEMBER CY-" +month.split("-")[0]);
        in1.setCellValue("DRUG INVENTORY COVERED PERIOD JANUARY-DECEMBER CY-" + month.split("-")[0]);
        in1.setCellStyle(cs1);
        in1.setCellStyle(cs2);

        Row intro2 = sheet.createRow(9);
        Cell in2 = intro2.createCell(0);//.setCellValue("SUMMARY OF SEIZED/SURRENDERED/RECOVERED OF DRUG EVIDENCES FROM NEGATION OPERATIONS FROM LAW ENFORCEMENTS, PHARMACEUTICAL COMPANIES AND SIMILAR ESTABLISHMENTS FOR THE MONTH OF "+month);
        in2.setCellValue(
                "SUMMARY OF SEIZED/SURRENDERED/RECOVERED OF DRUG EVIDENCES FROM NEGATION OPERATIONS FROM LAW ENFORCEMENTS, PHARMACEUTICAL COMPANIES AND SIMILAR ESTABLISHMENTS FOR THE MONTH OF "
                        + month);
        in2.setCellStyle(cs1);
        in2.setCellStyle(cs2);
        in2.setCellStyle(stf);

        int ctr = 12; //initial
        Row row = sheet.createRow(ctr);
        month = month.split("-")[1];

        //System.out.println("GAC " + chemistryDAO.getAllChemistry(month).isEmpty());
        for (Chemistry chemistry : chemistryDAO.getAllChemistry(month)) {
            //System.out.println("Test " + chemistry.getTimeDateReceived());
            Cell cell0 = row.createCell(0);
            cell0.setCellValue(chemistry.getTimeDateReceived());
            cell0.setCellStyle(bt);
            cell0.setCellStyle(bb);
            cell0.setCellStyle(bl);
            cell0.setCellStyle(br);

            Cell cell1 = row.createCell(1);//.setCellValue(chemistry.getReportNo());
            cell1.setCellValue(chemistry.getReportNo());
            cell1.setCellStyle(bt);
            cell1.setCellStyle(bb);
            cell1.setCellStyle(bl);
            cell1.setCellStyle(br);

            Cell cell2 = row.createCell(2);//.setCellValue(chemistry.getRequestingParty());
            cell2.setCellValue(chemistry.getRequestingParty());
            cell2.setCellStyle(bt);
            cell2.setCellStyle(bb);
            cell2.setCellStyle(bl);
            cell2.setCellStyle(br);

            Cell cell3 = row.createCell(3);//.setCellValue(chemistry.getDescriptionOfEvidence());
            cell3.setCellValue(chemistry.getDescriptionOfEvidence());
            cell3.setCellStyle(bt);
            cell3.setCellStyle(bb);
            cell3.setCellStyle(bl);
            cell3.setCellStyle(br);

            Cell cell4 = row.createCell(4);//.setCellValue(chemistry.getSpecimenWeight());
            cell4.setCellValue(chemistry.getSpecimenWeight());
            cell4.setCellStyle(bt);
            cell4.setCellStyle(bb);
            cell4.setCellStyle(bl);
            cell4.setCellStyle(br);

            Cell cell5 = row.createCell(5);//.setCellValue(chemistry.getCustody());
            cell5.setCellValue(chemistry.getCustody());
            cell5.setCellStyle(bt);
            cell5.setCellStyle(bb);
            cell5.setCellStyle(bl);
            cell5.setCellStyle(br);

            Cell cell6 = row.createCell(6);//.setCellValue(chemistry.getSuspects());
            cell6.setCellValue(chemistry.getSuspects());
            cell6.setCellStyle(bt);
            cell6.setCellStyle(bb);
            cell6.setCellStyle(bl);
            cell6.setCellStyle(br);

            Cell cell7 = row.createCell(7);//.setCellValue(chemistry.getTypeOfOperation());
            cell7.setCellValue(chemistry.getTypeOfOperation());
            cell7.setCellStyle(bt);
            cell7.setCellStyle(bb);
            cell7.setCellStyle(bl);
            cell7.setCellStyle(br);

            Cell cell8 = row.createCell(8);//.setCellValue(chemistry.getPlaceOfOperation());
            cell8.setCellValue(chemistry.getPlaceOfOperation());
            cell8.setCellStyle(bt);
            cell8.setCellStyle(bb);
            cell8.setCellStyle(bl);
            cell8.setCellStyle(br);

            row = sheet.createRow(ctr += 1);
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    return wb;
}

From source file:com.crimelab.service.CriminalServiceImpl.java

@Override
public Workbook createTenprintsCards(HttpSession session, String month) {
    Workbook wb = null;

    try {//from  w  ww. j a  v a  2s  .  co  m
        InputStream inp = session.getServletContext()
                .getResourceAsStream("/WEB-INF/templates/TenprintsCards.xls");
        wb = WorkbookFactory.create(inp);
        Sheet sheet = wb.getSheetAt(0);
        CellStyle cs1 = wb.createCellStyle();
        CellStyle cs2 = wb.createCellStyle();
        CellStyle bl = wb.createCellStyle();
        CellStyle br = wb.createCellStyle();
        CellStyle bt = wb.createCellStyle();
        CellStyle bb = wb.createCellStyle();
        cs1.setWrapText(true);
        cs2.setAlignment(ALIGN_CENTER);
        bt.setBorderTop(BORDER_THIN);
        bb.setBorderBottom(BORDER_THIN);
        bl.setBorderLeft(BORDER_THIN);
        br.setBorderRight(BORDER_THIN);

        Row intro1 = sheet.createRow(9);
        Cell in1 = intro1.createCell(0);
        in1.setCellValue("Submitted Tenprints Cards from " + month.split("-")[0]);
        in1.setCellStyle(cs1);
        in1.setCellStyle(cs2);

        int ctr = 11; //initial
        Row row = sheet.createRow(ctr);
        month = month.split("-")[1];

        //JOptionPane.showMessageDialog(null, criminalDAO.getAllCriminal(month));
        for (Criminal criminal : criminalDAO.getAllCriminal(month)) {
            //JOptionPane.showMessageDialog(null, criminal.getReportNo());

            Cell cell2 = row.createCell(2);//.setCellValue(criminal.getRequestingParty());
            cell2.setCellValue(criminal.getLastName());
            cell2.setCellStyle(bt);
            cell2.setCellStyle(bb);
            cell2.setCellStyle(bl);
            cell2.setCellStyle(br);

            Cell cell3 = row.createCell(3);//.setCellValue(criminal.getDescriptionOfEvidence());
            cell3.setCellValue(criminal.getFirstName());
            cell2.setCellStyle(bt);
            cell2.setCellStyle(bb);
            cell3.setCellStyle(bl);
            cell3.setCellStyle(br);

            Cell cell4 = row.createCell(4);//.setCellValue(criminal.getSpecimenWeight());
            cell4.setCellValue(criminal.getMiddleName());
            cell4.setCellStyle(bt);
            cell4.setCellStyle(bb);
            cell4.setCellStyle(bl);
            cell4.setCellStyle(br);

            Cell cell5 = row.createCell(5);//.setCellValue(criminal.getCustody());
            cell5.setCellValue(criminal.getTimeDateArrest());
            cell5.setCellStyle(bt);
            cell5.setCellStyle(bb);
            cell5.setCellStyle(bl);
            cell5.setCellStyle(br);

            Cell cell6 = row.createCell(6);//.setCellValue(criminal.getSuspects());
            cell6.setCellValue(criminal.getOffenseCharge());
            cell6.setCellStyle(bt);
            cell6.setCellStyle(bb);
            cell6.setCellStyle(bl);
            cell6.setCellStyle(br);

            row = sheet.createRow(ctr += 1);

            return wb;
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
    return wb;
}

From source file:com.crimelab.service.DrugTestServiceImpl.java

@Override
public Workbook create(DrugTest drugTest, HttpSession session) {
    Workbook wb = null;

    try {/*  w  ww  .  j  av a  2 s .  c om*/
        InputStream inp = session.getServletContext().getResourceAsStream("/WEB-INF/templates/DrugTest.xls");
        wb = WorkbookFactory.create(inp);
        Sheet sheet = wb.getSheetAt(0);

        //iterate over keywords  
        Cell fadtNo = findCell(sheet, "$fadtNo");
        Cell sbrNo = findCell(sheet, "$sbrNo");
        Cell timeDate = findCell(sheet, "$timeDate");
        Cell name = findCell(sheet, "$name");
        Cell address = findCell(sheet, "$address");
        Cell age = findCell(sheet, "$age");
        Cell sex = findCell(sheet, "$sex");
        Cell purposeFL = findCell(sheet, "$purposeFL");
        Cell purposePTCFOR = findCell(sheet, "$purposePTCFOR");
        Cell specimenSubmitted = findCell(sheet, "$specimenSubmitted");
        Cell purposeOfExamination = findCell(sheet, "$purposeOfExamination");
        Cell methamphetamine = findCell(sheet, "$methamphetamine");
        Cell thc = findCell(sheet, "$thc");
        Cell remarks = findCell(sheet, "$remarks");
        Cell examinerName = findCell(sheet, "$examinerName");
        Cell examinerRank = findCell(sheet, "$examinerRank");
        Cell examinerPosition = findCell(sheet, "$examinerPosition");
        Cell appName = findCell(sheet, "$appName");
        Cell appRank = findCell(sheet, "$appRank");
        Cell appPosition = findCell(sheet, "$appPosition");

        //Modify the cellContents here
        // Write the output to a file
        //get from param
        fadtNo.setCellValue(drugTest.getFadtNo());
        sbrNo.setCellValue(drugTest.getSbrNo());
        timeDate.setCellValue(drugTest.getTimeDate());
        name.setCellValue(drugTest.getName());
        address.setCellValue(drugTest.getAddress());
        age.setCellValue(drugTest.getAge());
        sex.setCellValue(drugTest.getSex());

        switch (drugTest.getPurpose().trim()) {
        case "Firearm License":
            purposeFL.setCellValue("   ");
            purposePTCFOR.setCellValue("");
            break;

        case "Permit to Carry Firearms Outside Residence (PTCFOR)":
            purposeFL.setCellValue("");
            purposePTCFOR.setCellValue("   ");
            break;

        default:
            purposeFL.setCellValue("   ");
            purposePTCFOR.setCellValue("   ");
            break;
        }

        specimenSubmitted.setCellValue(drugTest.getSpecimenSubmitted());
        purposeOfExamination.setCellValue(drugTest.getPurposeOfExamination());
        methamphetamine.setCellValue(drugTest.getMethamphetamine());
        thc.setCellValue(drugTest.getThc());
        remarks.setCellValue(drugTest.getRemarks());
        examinerName.setCellValue(drugTest.getExaminerName());
        examinerRank.setCellValue(drugTest.getExaminerRank());
        examinerPosition.setCellValue(drugTest.getExaminerPosition());
        appName.setCellValue(drugTest.getAppName());
        appRank.setCellValue(drugTest.getAppRank());
        appPosition.setCellValue(drugTest.getAppPosition());

        drugTestDAO.drugTestInfo(drugTest);
    } catch (Exception e) {
        e.printStackTrace();

    }
    return wb;
}