⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zdefaultsheet.java

📁 用Java写的报表.功能如下: 0.内建网络打印,网络预览功能! 1.文件操作。包括url 指定的文件。 2.全功能打印支持。包括打印预览。 3.Undo 和 redo。 4.合并单元格。 5.Cel
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     * @return
     */
    public ZRect getPrintableCells() {
        ZRect res = null;

        for (int i = 0; i < cellsList.size(); i++) {
            ZDefaultCell cell = (ZDefaultCell) cellsList.get(i);

            if (cell.hasProperty(ZBase.PTY_BackBrush | ZBase.PTY_Text | ZBase.PTY_LeftBorder | ZBase.PTY_RightBorder |
                                     ZBase.PTY_TopBorder | ZBase.PTY_BottomBorder) && !cell.isChild()) {
                ZRect cellRC;

                if (cell.isParent()) {
                    cellRC = cell.getSpan();
                } else {
                    cellRC = new ZRect(cell.getCol(), cell.getRow(), cell.getCol(), cell.getRow());
                }

                if (res == null) {
                    res = new ZRect(1, 1, 1, 1);
                }

                res.union(cellRC);
            }
        }

        return res;
    }

    /**
     * put your documentation comment here
     * @param printingCells
     */
    public void setPrintingRect(ZRect printingCells) {
        this.printingCells = printingCells;
    }

    /**
     * put your documentation comment here
     * @return
     */
    public ZRect getPrintingRect() {
        return printingCells;
    }

    /**
     * put your documentation comment here
     * @param row
     * @return
     */
    public ZRow getRow(int row) {
        ZRow tr = getExistRow(row);

        if (tr != null) {
            return tr;
        } else {
            defRow.setRow(row);

            return defRow;
        }
    }

    /**
     * put your documentation comment here
     * @param row
     * @return
     */
    public int getRowHeight(int row) {
        return getRow(row).getHeight();
    }

    /**
     * put your documentation comment here
     * @return
     */
    public Vector getRows() {
        return rowsList;
    }

    /**
     * put your documentation comment here
     * @return
     */
    public Enumeration getRowsEnum(ZRect rect) {
        return new _RowsEnum(rect);
    }

    /**
     * put your documentation comment here
     * @param rect
     * @param value
     */
    public void setSelectionBackBrush(ZRect rect, ZBrush value)
                               throws ZSelectionNoSupported {
        validateSelection(rect);

        ZCmdFormat cmd = new ZCmdFormat(this, (ZRect) rect.clone(), ZBase.PTY_BackBrush, value,
                                        new ZCmdWorker() {
            /**
             * put your documentation comment here
             * @param cmd
             * @param obj
             */
            public void workOnObject(ZCmdFormat cmd, ZBase obj) {
                ZBrush value = (ZBrush) cmd.getValueObject();
                obj.setBackBrush((ZBrush) value.clone());
            }
        });
        cmd.commit();
    }

    /**
     * put your documentation comment here
     * @param rect
     * @param pens
     */
    public void setSelectionBorders(ZRect rect, ZPen[] pens)
                             throws ZSelectionNoSupported {
        //
        // make sure selection type is rows
        validateSelection(rect, ZRect.CELLS);

        ZCmdFormat cmd = new ZCmdFormat(this, (ZRect) rect.clone(), ZBase.PTY_TopBorder | ZBase.PTY_LeftBorder, pens,
                                        new ZCmdWorker(ZCmdWorker.ACCEPT_CELL) {
            /**
             * put your documentation comment here
             * @param cmd
             * @param obj
             */
            public void workOnObject(ZCmdFormat cmd, ZBase obj) {
                ZPen[] pens = (ZPen[]) cmd.getValueObject();
                ZRect effectCells = cmd.getEffectCells();

                // Only allows ZCell to have their borders
                if (!(obj instanceof ZCell)) {
                    return;
                }

                ZCell cell = (ZCell) obj;

                if (cell.isParent()) {
                    ZSheet sheet = cmd.getSheet();
                    ZRect childrenCells = cell.getSpan();

                    for (int r = childrenCells.top; r <= childrenCells.bottom; r++)
                        for (int c = childrenCells.left; c <= childrenCells.right; c++)
                            setBorderToCell((ZBase) sheet.getCell(r, c), pens, effectCells);
                } else {
                    setBorderToCell(obj, pens, effectCells);
                }
            }

            private void setBorderToCell(ZBase obj, ZPen[] pens, ZRect effectCells) {
                Point point = effectCells.getLocation(obj.getCol(), obj.getRow());

                if (pens[point.x] != null) {
                    obj.setLeftBorder((ZPen) pens[point.x].clone());
                }

                if (pens[point.y] != null) {
                    obj.setTopBorder((ZPen) pens[point.y].clone());
                }

                if ((obj.col == effectCells.right) && (pens[2] != null)) {
                    obj.setRightBorder(pens[2]);
                }

                if ((obj.row == effectCells.bottom) && (pens[5] != null)) {
                    obj.setBottomBorder(pens[5]);
                }
            }
        });
        cmd.commit();
    }

    /**
     * put your documentation comment here
     * @param rect
     * @param font
     */
    public void setSelectionFont(ZRect rect, ZFont font)
                          throws ZSelectionNoSupported {
        validateSelection(rect);

        ZCmdFormat cmd = new ZCmdFormat(this, (ZRect) rect.clone(), ZBase.PTY_Font, (ZFont) font.clone(),
                                        new ZCmdWorker() {
            /**
             * put your documentation comment here
             * @param cmd
             * @param obj
             */
            public void workOnObject(ZCmdFormat cmd, ZBase obj) {
                ZFont font = (ZFont) cmd.getValueObject();
                obj.setFont((ZFont) (font.clone()));
            }
        });
        cmd.commit();
    }

    /**
     * put your documentation comment here
     * @param rect
     * @param fontBold
     */
    public void setSelectionFontBold(ZRect rect, boolean fontBold)
                              throws ZSelectionNoSupported {
        validateSelection(rect);

        ZCmdFormat cmd = new ZCmdFormat(this, (ZRect) rect.clone(), ZBase.PTY_Font, new Boolean(fontBold),
                                        new ZCmdWorker() {
            /**
             * put your documentation comment here
             * @param cmd
             * @param obj
             */
            public void workOnObject(ZCmdFormat cmd, ZBase obj) {
                Boolean fontBold = (Boolean) cmd.getValueObject();
                obj.setFontBold(fontBold.booleanValue());
            }
        });
        cmd.commit();
    }

    /**
     * put your documentation comment here
     * @param rect
     * @param fontItalic
     */
    public void setSelectionFontItalic(ZRect rect, boolean fontItalic)
                                throws ZSelectionNoSupported {
        validateSelection(rect);

        ZCmdFormat cmd = new ZCmdFormat(this, (ZRect) rect.clone(), ZBase.PTY_Font, new Boolean(fontItalic),
                                        new ZCmdWorker() {
            /**
             * put your documentation comment here
             * @param cmd
             * @param obj
             */
            public void workOnObject(ZCmdFormat cmd, ZBase obj) {
                Boolean fontItalic = (Boolean) cmd.getValueObject();
                obj.setFontItalic(fontItalic.booleanValue());
            }
        });
        cmd.commit();
    }

    /**
     * put your documentation comment here
     * @param rect
     * @param fontName
     */
    public void setSelectionFontName(ZRect rect, String fontName)
                              throws ZSelectionNoSupported {
        validateSelection(rect);

        ZCmdFormat cmd = new ZCmdFormat(this, (ZRect) rect.clone(), ZBase.PTY_Font, fontName,
                                        new ZCmdWorker() {
            /**
             * put your documentation comment here
             * @param cmd
             * @param obj
             */
            public void workOnObject(ZCmdFormat cmd, ZBase obj) {
                String fontName = (String) cmd.getValueObject();
                obj.setFontName(new String(fontName));
            }
        });
        cmd.commit();
    }

    /**
     *
     * @param rect
     * @param fontOutline
     *
     * @throws ZSelectionNoSupported
     */
    public void setSelectionFontOutline(ZRect rect, boolean fontOutline)
                                 throws ZSelectionNoSupported {
        validateSelection(rect);

        ZCmdFormat cmd = new ZCmdFormat(this, (ZRect) rect.clone(), ZBase.PTY_Font, new Boolean(fontOutline),
                                        new ZCmdWorker() {
            /**
             * put your documentation comment here
             * @param cmd
             * @param obj
             */
            public void workOnObject(ZCmdFormat cmd, ZBase obj) {
                Boolean fontOutline = (Boolean) cmd.getValueObject();
                obj.setFontOutline(fontOutline.booleanValue());
            }
        });
        cmd.commit();
    }

    /**
     *
     * @param rect
     *
     * @return
     *
     * @throws ZSelectionNoSupported
     */
    public ZCmdClear clearSelection(ZRect rect) throws ZSelectionNoSupported {
        validateSelection(rect);

        ZCmdClear cmd = new ZCmdClear(this, (ZRect) rect.clone());
        cmd.commit();

        return cmd;
    }

    /**
     * put your documentation comment here
     * @param from
     * @param to
     * @return
     */
    public int colsWidth(int from, int to) {
        int result = 0;

        for (int i = from; i <= to; i++)
            result += getCol(i).getWidth();

        return result;
    }

    /**
     * put your documentation comment here
     * @param rect
     * @param toCells
     */
    public void copyCells(ZRect rect, Vector toCells) {
        int row;
        int col;

        for (row = rect.top; row <= rect.bottom; row++)
            for (col = rect.left; col <= rect.right; col++) {
                ZDefaultCell cell = getExistCell(row, col); // = buildCell(row,col);

                if (cell != null) {
                    cell = (ZDefaultCell) cell.clone();

                    ZRow or = getExistRow(row);

                    if (or != null) {
                        cell.copyFrom(or);
                    }

                    ZCol oc = getExistCol(col);

                    if (oc != null) {
                        cell.copyFrom(oc);
                    }

                    cell.setNoPropUnder(ZBase.PTY_BaseAll);
                    toCells.add(cell);
                }
            }
    }

    /**
     * put your documentation comment here
     * @param from
     * @param to
     * @param toCols
     * @param toCells
     */
    public void copyCols(int from, int to, Vector toCols, Vector toCells) {
        int row;
        int col;
        ZDefaultCell cell;
        ZRow or;
        ZCol oc;

        // save rows
        for (col = from; col <= to; col++) {
            oc = getCol(col);

            if (oc != null) {
                oc = (ZCol) oc.clone();
                oc.setNoPropUnder(ZBase.PTY_All);
                toCols.add(oc);
            }
        }

        // save cells in those rows
        Enumeration enum = getCellsEnum(new ZRect(from, 1, to, lastRow));

        while (enum.hasMoreElements()) {
            cell = (ZDefaultCell) enum.nextElement();
            cell = (ZDefaultCell) cell.clone();
            or = getExistRow(cell.getRow());

            if (or != null) {
                cell.copyFrom(or);
            }

            oc = getExistCol(cell.getCol());

            if (oc != null) {
                cell.copyFrom(oc);
            }

            toCells.add(cell);
        }

        enum = getRows().elements();

        while (enum.hasMoreElements()) {
            or = (ZRow) enum.nextElement();

            // if the col has olny property of width ,then loop again;
            if (!or.hasProperty2(~ZBase.PTY_Width)) {
                continue;
            }

            for (col = from; col <= to; col++) {
                cell = (ZDefaultCell) getCell(or.getRow(), col);

                if (cell != null) // this cell has been done above
                {
                    continue;
                }

                cell = new ZDefaultCell(this, or.getRow(), col);
                cell.copyFrom(or);
                oc = getExistCol(cell.getCol());

                if (oc != null) {
                    cell.copyFrom(oc);
                }

                toCells.add(cell);
            }
        }
    }

    /**
     * put your documentation comment here
     * @param from
     * @param to
     * @param toRows
     * @param toCells
     */
    public void copyRows(int from, int to, Vector toRows, Vector toCells) {
        int row;
        int col;
        ZDefaultCell cell;
        ZRow or;
        ZCol oc;

        // save rows
        for (row = from; row <= to; row++) {
            or = getRow(row);

            if (or != null) {
                or = (ZRow) or.clone();
                or.setNoPropUnder(ZBase.PTY_All);
                toRows.add(or);
            }
        }

        // save cells in those rows
        Enumeration enum = getCellsEnum(new ZRect(1, from, lastCol, to));

        while (enum.hasMoreElements()) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -