Package org.jboss.seam.excel

Examples of org.jboss.seam.excel.ExcelWorkbookException


        if (log.isTraceEnabled()) {
            log.trace("Adding a cell with data #1 at column #2 and row #3",
                    uiCell.getValue(), currentColumnIndex, currentRowIndex);
        }
        if (worksheet == null) {
            throw new ExcelWorkbookException(
                    "Can't add cells before creating worksheet");
        }

        // Determine where to really place the cell
        int useRow = uiCell.getRow() != null ? uiCell.getRow()
                : currentRowIndex;
        int useColumn = uiCell.getColumn() != null ? uiCell.getColumn()
                : currentColumnIndex;

        CellInfo cellInfo = jxlHelper.getCellInfo(uiCell);
        WritableCell cell = JXLHelper.createCell(useColumn, useRow, cellInfo
                .getCellType(), uiCell.getValue(), cellInfo.getCellFormat());
        if (cellInfo.getCellFeatures() != null) {
            cell.setCellFeatures(cellInfo.getCellFeatures());
        }
        try {
            worksheet.addCell(cell);
        } catch (WriteException e) {
            throw new ExcelWorkbookException("Could not add cell", e);
        }
        // Only increase row if cell had no explicit placing
        if (uiCell.getColumn() == null && uiCell.getRow() == null) {
            nextRow();
        }
View Full Code Here


    public byte[] getBytes() {
        if (log.isTraceEnabled()) {
            log.trace("Returning bytes from workbook");
        }
        if (workbook == null) {
            throw new ExcelWorkbookException(
                    "You can't get workbook data before creating a workbook");
        }
        // You will get an IndexOutOfBoundException if trying to write a
        // workbook
        // without sheets,
        // creating a dummy. Could also throw an exception...
        if (workbook.getSheets().length == 0) {
            if (log.isTraceEnabled()) {
                log.trace("Creating dummy sheet");
            }
            workbook.createSheet("dummy", 0);
        }
        try {
            workbook.write();
            workbook.close();
        } catch (WriteException e) {
            throw new ExcelWorkbookException(
                    "There was an exception writing the workbook", e);
        } catch (IOException e) {
            throw new ExcelWorkbookException(
                    "There was an exception closing the workbook", e);
        }
        return byteStream.toByteArray();
    }
View Full Code Here

                    templateStream = getClass().getResourceAsStream(urlString);
                } else {
                    templateStream = new URL(urlString).openStream();
                }
            } catch (Exception e) {
                throw new ExcelWorkbookException(
                        "Could not handle template URI", e);
            }
        }
        WorkbookSettings workbookSettings = null;
        if (uiWorkbook.hasSettings()) {
            workbookSettings = jxlHelper.createWorkbookSettings(uiWorkbook);
        }
        if (log.isDebugEnabled()) {
            log.debug("Creating workbook with creation type #0", uiWorkbook
                    .getCreationType());
        }
        // The joys of multiple constructors and no setters...
        try {
            switch (uiWorkbook.getCreationType()) {
            case WITH_SETTNGS_AND_TEMPLATE:
                workbook = Workbook.createWorkbook(byteStream, Workbook
                        .getWorkbook(templateStream), workbookSettings);
                break;
            case WITH_SETTINGS_WITHOUT_TEMPLATE:
                workbook = Workbook
                        .createWorkbook(byteStream, workbookSettings);
                break;
            case WITHOUT_SETTINGS_WITH_TEMPLATE:
                workbook = Workbook.createWorkbook(byteStream, Workbook
                        .getWorkbook(templateStream));
                break;
            case WITHOUT_SETTINGS_OR_TEMPLATE:
                workbook = Workbook.createWorkbook(byteStream);
                break;
            }
        } catch (Exception e) {
            throw new ExcelWorkbookException("Could not create workbook", e);
        }
        if (uiWorkbook.getWorkbookProtected() != null) {
            workbook.setProtected(uiWorkbook.getWorkbookProtected());
        }
        currentWorksheetIndex = workbook.getNumberOfSheets();
View Full Code Here

     * @param uiColumn
     *            the UI column to inspect for settings
     */
    public void applyColumnSettings(UIColumn uiColumn) {
        if (worksheet == null) {
            throw new ExcelWorkbookException(
                    "You can't set column settings before creating a worksheet");
        }
        jxlHelper.applyColumnSettings(uiColumn, worksheet, currentColumnIndex);
    }
View Full Code Here

     * @param uiImage
     *            The image to add
     */
    private void addImage(UIImage uiImage) {
        if (worksheet == null) {
            throw new ExcelWorkbookException(
                    "Can't add an image before creating a worksheet");
        }

        BufferedImage image = null;
        ByteArrayOutputStream pngStream = null;
        try {
            image = ImageIO.read(new URI(uiImage.getURI()).toURL());
            pngStream = new ByteArrayOutputStream();
            ImageIO.write(image, "PNG", pngStream);
        } catch (Exception e) {
            throw new ExcelWorkbookException("Could not load or process image",
                    e);
        }

        int useStartColumn = uiImage.getStartColumn() == null ? currentColumnIndex
                : uiImage.getStartRow();
View Full Code Here

     * @param url
     *            The target URL
     */
    private void addHyperlink(UIHyperlink uiHyperlink) {
        if (worksheet == null) {
            throw new ExcelWorkbookException(
                    "Can't add a hyperlink before creating a worksheet");
        }

        int useStartColumn = uiHyperlink.getStartColumn() == null ? currentColumnIndex
                : uiHyperlink.getStartColumn();
        int useStartRow = uiHyperlink.getStartRow() == null ? currentRowIndex
                : uiHyperlink.getStartRow();
        int useEndColumn = uiHyperlink.getEndColumn() == null ? useStartColumn
                : uiHyperlink.getEndColumn();
        int useEndRow = uiHyperlink.getEndRow() == null ? useStartRow
                : uiHyperlink.getEndRow();
        String useDescription = uiHyperlink.getDescription() == null ? uiHyperlink
                .getURL()
                : uiHyperlink.getDescription();
        URL useURL = null;

        try {
            useURL = new URL(uiHyperlink.getURL());
        } catch (MalformedURLException e) {
            throw new ExcelWorkbookException("Bad url", e);
        }
        try {
            worksheet.addHyperlink(new WritableHyperlink(useStartColumn,
                    useStartRow, useEndColumn, useEndRow, useURL,
                    useDescription));
        } catch (Exception e) {
            throw new ExcelWorkbookException("Could not add hyperlink", e);
        }
    }
View Full Code Here

            break;
        case image:
            addImage((UIImage) item);
            break;
        default:
            throw new ExcelWorkbookException(Interpolator.instance()
                    .interpolate("Unknown item type {0}", item.getItemType()));
        }
    }
View Full Code Here

            break;
        case add_row_pagebreak:
            addRowPageBreak((UIRowPageBreak) command);
            break;
        default:
            throw new ExcelWorkbookException(
                    Interpolator.instance().interpolate("Unknown command #0",
                            command.getCommandType()));
        }
    }
View Full Code Here

    private void addRowPageBreak(UIRowPageBreak command) {
        if (log.isTraceEnabled()) {
            log.trace("Adding row page break #0", command);
        }
        if (worksheet == null) {
            throw new ExcelWorkbookException(
                    "Can't add row page breaks before creating a worksheet");
        }
        int useRow = command.getRow() != null ? command.getRow()
                : currentRowIndex;
        worksheet.addRowPageBreak(useRow);
View Full Code Here

    private void groupRows(UIGroupRows command) {
        if (log.isTraceEnabled()) {
            log.trace("Grouping rows #0", command);
        }
        if (worksheet == null) {
            throw new ExcelWorkbookException(
                    "Can't group rows before creating a worksheet");
        }
        if (command.getStartRow() == null || command.getEndRow() == null) {
            throw new ExcelWorkbookException(
                    "Must define starting and ending rows when grouping rows");
        }
        boolean collapse = command.getCollapse() == null ? false : command
                .getCollapse();
        try {
            worksheet.setRowGroup(command.getStartRow(), command.getEndRow(),
                    collapse);
        } catch (Exception e) {
            throw new ExcelWorkbookException("Could not group columns", e);
        }
    }
View Full Code Here

TOP

Related Classes of org.jboss.seam.excel.ExcelWorkbookException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.