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

📄 writablesheetimpl.java

📁 实现JAVA界面的代码GWT
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    }

    public void addCell(WritableCell cell)
        throws WriteException, RowsExceededException
    {
        if(cell.getType() == CellType.EMPTY && cell != null && cell.getCellFormat() == null)
            return;
        CellValue cv = (CellValue)cell;
        if(cv.isReferenced())
        {
            throw new JxlWriteException(JxlWriteException.cellReferenced);
        } else
        {
            int row = cell.getRow();
            RowRecord rowrec = getRowRecord(row);
            rowrec.addCell(cv);
            numRows = Math.max(row + 1, numRows);
            numColumns = Math.max(numColumns, rowrec.getMaxColumn());
            cv.setCellDetails(formatRecords, sharedStrings, this);
            return;
        }
    }

    RowRecord getRowRecord(int row)
        throws RowsExceededException
    {
        if(row >= 0x10000)
            throw new RowsExceededException();
        if(row >= rows.length)
        {
            RowRecord oldRows[] = rows;
            rows = new RowRecord[Math.max(oldRows.length + 10, row + 1)];
            System.arraycopy(oldRows, 0, rows, 0, oldRows.length);
            oldRows = null;
        }
        RowRecord rowrec = rows[row];
        if(rowrec == null)
        {
            rowrec = new RowRecord(row);
            rows[row] = rowrec;
        }
        return rowrec;
    }

    RowRecord getRowInfo(int r)
    {
        if(r < 0 || r > rows.length)
            return null;
        else
            return rows[r];
    }

    ColumnInfoRecord getColumnInfo(int c)
    {
        Iterator i = columnFormats.iterator();
        ColumnInfoRecord cir = null;
        boolean stop = false;
        do
        {
            if(!i.hasNext() || stop)
                break;
            cir = (ColumnInfoRecord)i.next();
            if(cir.getColumn() >= c)
                stop = true;
        } while(true);
        if(!stop)
            return null;
        else
            return cir.getColumn() != c ? null : cir;
    }

    public void setName(String n)
    {
        name = n;
    }

    public void setHidden(boolean h)
    {
        settings.setHidden(h);
    }

    public void setProtected(boolean prot)
    {
        settings.setProtected(prot);
    }

    public void setSelected()
    {
        settings.setSelected();
    }

    public boolean isHidden()
    {
        return settings.isHidden();
    }

    public void setColumnView(int col, int width)
    {
        CellView cv = new CellView();
        cv.setSize(width * 256);
        setColumnView(col, cv);
    }

    public void setColumnView(int col, int width, CellFormat format)
    {
        CellView cv = new CellView();
        cv.setSize(width * 256);
        cv.setFormat(format);
        setColumnView(col, cv);
    }

    public void setColumnView(int col, CellView view)
    {
        XFRecord xfr = (XFRecord)view.getFormat();
        if(xfr == null)
        {
            Styles styles = getWorkbook().getStyles();
            xfr = styles.getNormalStyle();
        }
        try
        {
            if(!xfr.isInitialized())
                formatRecords.addStyle(xfr);
            int width = view.depUsed() ? view.getDimension() * 256 : view.getSize();
            if(view.isAutosize())
                autosizedColumns.add(new Integer(col));
            ColumnInfoRecord cir = new ColumnInfoRecord(col, width, xfr);
            if(view.isHidden())
                cir.setHidden(true);
            if(!columnFormats.contains(cir))
            {
                columnFormats.add(cir);
            } else
            {
                columnFormats.remove(cir);
                columnFormats.add(cir);
            }
        }
        catch(NumFormatRecordsException e)
        {
            logger.warn("Maximum number of format records exceeded.  Using default format.");
            ColumnInfoRecord cir = new ColumnInfoRecord(col, view.getDimension() * 256, WritableWorkbook.NORMAL_STYLE);
            if(!columnFormats.contains(cir))
                columnFormats.add(cir);
        }
    }

    public void setRowView(int row, int height)
        throws RowsExceededException
    {
        setRowView(row, height, false);
    }

    public void setRowView(int row, boolean collapsed)
        throws RowsExceededException
    {
        RowRecord rowrec = getRowRecord(row);
        rowrec.setCollapsed(collapsed);
    }

    public void setRowView(int row, int height, boolean collapsed)
        throws RowsExceededException
    {
        RowRecord rowrec = getRowRecord(row);
        rowrec.setRowHeight(height);
        rowrec.setCollapsed(collapsed);
    }

    public void write()
        throws IOException
    {
        boolean dmod = drawingsModified;
        if(workbook.getDrawingGroup() != null)
            dmod |= workbook.getDrawingGroup().hasDrawingsOmitted();
        if(autosizedColumns.size() > 0)
            autosizeColumns();
        sheetWriter.setWriteData(rows, rowBreaks, columnBreaks, hyperlinks, mergedCells, columnFormats);
        sheetWriter.setDimensions(getRows(), getColumns());
        sheetWriter.setSettings(settings);
        sheetWriter.setPLS(plsRecord);
        sheetWriter.setDrawings(drawings, dmod);
        sheetWriter.setButtonPropertySet(buttonPropertySet);
        sheetWriter.setDataValidation(dataValidation, validatedCells);
        sheetWriter.write();
    }

    private void copyCells(Sheet s)
    {
        int cells = s.getRows();
        Cell row[] = null;
        Cell cell = null;
        for(int i = 0; i < cells; i++)
        {
            row = s.getRow(i);
            for(int j = 0; j < row.length; j++)
            {
                cell = row[j];
                CellType ct = cell.getType();
                try
                {
                    if(ct == CellType.LABEL)
                    {
                        Label l = new Label((LabelCell)cell);
                        addCell(l);
                        continue;
                    }
                    if(ct == CellType.NUMBER)
                    {
                        Number n = new Number((NumberCell)cell);
                        addCell(n);
                        continue;
                    }
                    if(ct == CellType.DATE)
                    {
                        DateTime dt = new DateTime((DateCell)cell);
                        addCell(dt);
                        continue;
                    }
                    if(ct == CellType.BOOLEAN)
                    {
                        Boolean b = new Boolean((BooleanCell)cell);
                        addCell(b);
                        continue;
                    }
                    if(ct == CellType.NUMBER_FORMULA)
                    {
                        ReadNumberFormulaRecord fr = new ReadNumberFormulaRecord((FormulaData)cell);
                        addCell(fr);
                        continue;
                    }
                    if(ct == CellType.STRING_FORMULA)
                    {
                        ReadStringFormulaRecord fr = new ReadStringFormulaRecord((FormulaData)cell);
                        addCell(fr);
                        continue;
                    }
                    if(ct == CellType.BOOLEAN_FORMULA)
                    {
                        ReadBooleanFormulaRecord fr = new ReadBooleanFormulaRecord((FormulaData)cell);
                        addCell(fr);
                        continue;
                    }
                    if(ct == CellType.DATE_FORMULA)
                    {
                        ReadDateFormulaRecord fr = new ReadDateFormulaRecord((FormulaData)cell);
                        addCell(fr);
                        continue;
                    }
                    if(ct == CellType.FORMULA_ERROR)
                    {
                        ReadErrorFormulaRecord fr = new ReadErrorFormulaRecord((FormulaData)cell);
                        addCell(fr);
                        continue;
                    }
                    if(ct == CellType.EMPTY && cell.getCellFormat() != null)
                    {
                        Blank b = new Blank(cell);
                        addCell(b);
                    }
                }
                catch(WriteException e)
                {
                    Assert.verify(false);
                }
            }

        }

    }

    private void copyCells(WritableSheet s)
    {
        int cells = s.getRows();
        Cell row[] = null;
        Cell cell = null;
        for(int i = 0; i < cells; i++)
        {
            row = s.getRow(i);
            for(int j = 0; j < row.length; j++)
            {
                cell = row[j];
                try
                {
                    WritableCell wc = ((WritableCell)cell).copyTo(cell.getColumn(), cell.getRow());
                    addCell(wc);
                }
                catch(WriteException e)
                {
                    Assert.verify(false);
                }
            }

        }

    }

    void copy(Sheet s)
    {
        settings = new SheetSettings(s.getSettings());
        SheetCopier si = new SheetCopier(s, this);
        si.setColumnFormats(columnFormats);
        si.setFormatRecords(formatRecords);
        si.setHyperlinks(hyperlinks);
        si.setMergedCells(mergedCells);
        si.setRowBreaks(rowBreaks);
        si.setColumnBreaks(columnBreaks);
        si.setSheetWriter(sheetWriter);
        si.setDrawings(drawings);
        si.setImages(images);
        si.copySheet();
        dataValidation = si.getDataValidation();
        comboBox = si.getComboBox();
        plsRecord = si.getPLSRecord();
        chartOnly = si.isChartOnly();
        buttonPropertySet = si.getButtonPropertySet();
    }

    void copy(WritableSheet s)
    {
        settings = new SheetSettings(s.getSettings());
        copyCells(s);
        ColumnInfoRecord cv;
        for(Iterator cfit = ((WritableSheetImpl)s).columnFormats.iterator(); cfit.hasNext(); columnFormats.add(cv))
            cv = new ColumnInfoRecord((ColumnInfoRecord)cfit.next());

        Range merged[] = s.getMergedCells();
        for(int i = 0; i < merged.length; i++)
            mergedCells.add(new SheetRangeImpl((SheetRangeImpl)merged[i], this));

        try
        {
            RowRecord copyRows[] = ((WritableSheetImpl)s).rows;
            RowRecord row = null;
            for(int i = 0; i < copyRows.length; i++)
            {
                row = copyRows[i];
                if(row != null && (!row.isDefaultHeight() || row.isCollapsed()))
                {
                    RowRecord rr = getRowRecord(i);
                    rr.setRowDetails(row.getRowHeight(), row.matchesDefaultFontHeight(), row.isCollapsed(), row.getStyle());
                }
            }

        }
        catch(RowsExceededException e)
        {
            Assert.verify(false);
        }
        WritableSheetImpl si = (WritableSheetImpl)s;
        rowBreaks = new ArrayList(si.rowBreaks);
        columnBreaks = new ArrayList(si.columnBreaks);
        DataValidation rdv = si.dataValidation;
        if(rdv != null)
            dataValidation = new DataValidation(rdv, workbook, workbook, workbookSettings);
        sheetWriter.setCharts(si.getCharts());
        DrawingGroupObject dr[] = si.getDrawings();
        for(int i = 0; i < dr.length; i++)
            if(dr[i] instanceof Drawing)
            {
                WritableImage wi = new WritableImage(dr[i], workbook.getDrawingGroup());
                drawings.add(wi);
                images.add(wi);
            }

        sheetWriter.setWorkspaceOptions(si.getWorkspaceOptions());
        if(si.plsRecord != null)
            plsRecord = new PLSRecord(si.plsRecord);
        if(si.buttonPropertySet != null)
            buttonPropertySet = new ButtonPropertySetRecord(si.buttonPropertySet);
    }

    final HeaderRecord getHeader()
    {
        return sheetWriter.getHeader();
    }

    final FooterRecord getFooter()
    {
        return sheetWriter.getFooter();
    }

    public boolean isProtected()
    {
        return settings.isProtected();
    }

    public Hyperlink[] getHyperlinks()
    {
        Hyperlink hl[] = new Hyperlink[hyperlinks.size()];
        for(int i = 0; i < hyperlinks.size(); i++)
            hl[i] = (Hyperlink)hyperlinks.get(i);

        return hl;
    }

    public Range[] getMergedCells()
    {
        return mergedCells.getMergedCells();
    }

    public WritableHyperlink[] getWritableHyperlinks()
    {
        WritableHyperlink hl[] = new WritableHyperlink[hyperlinks.size()];
        for(int i = 0; i < hyperlinks.size(); i++)
            hl[i] = (WritableHyperlink)hyperlinks.get(i);

        return hl;
    }

    public void removeHyperlink(WritableHyperlink h)
    {
        removeHyperlink(h, false);
    }

    public void removeHyperlink(WritableHyperlink h, boolean preserveLabel)
    {
        hyperlinks.remove(hyperlinks.indexOf(h));
        if(!preserveLabel)
        {
            Assert.verify(rows.length > h.getRow() && rows[h.getRow()] != null);
            rows[h.getRow()].removeCell(h.getColumn());
        }
    }

    public void addHyperlink(WritableHyperlink h)
        throws WriteException, RowsExceededException
    {
        Cell c = getCell(h.getColumn(), h.getRow());
        String contents = null;
        if(h.isFile() || h.isUNC())
        {
            String cnts = h.getContents();
            if(cnts == null)
                contents = h.getFile().getPath();
            else
                contents = cnts;
        } else
        if(h.isURL())
        {
            String cnts = h.getContents();
            if(cnts == null)
                contents = h.getURL().toString();
            else
                contents = cnts;
        } else
        if(h.isLocation())
            contents = h.getContents();
        if(c.getType() == CellType.LABEL)
        {

⌨️ 快捷键说明

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