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

📄 writablesheetimpl.java

📁 实现JAVA界面的代码GWT
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            Label l = (Label)c;
            l.setString(contents);
            l.setCellFormat(WritableWorkbook.HYPERLINK_STYLE);
        } else
        {
            Label l = new Label(h.getColumn(), h.getRow(), contents, WritableWorkbook.HYPERLINK_STYLE);
            addCell(l);
        }
        for(int i = h.getRow(); i <= h.getLastRow(); i++)
        {
            for(int j = h.getColumn(); j <= h.getLastColumn(); j++)
                if(i != h.getRow() && j != h.getColumn() && rows[i] != null)
                    rows[i].removeCell(j);

        }

        h.initialize(this);
        hyperlinks.add(h);
    }

    public Range mergeCells(int col1, int row1, int col2, int row2)
        throws WriteException, RowsExceededException
    {
        if(col2 < col1 || row2 < row1)
            logger.warn("Cannot merge cells - top left and bottom right incorrectly specified");
        if(col2 >= numColumns || row2 >= numRows)
            addCell(new Blank(col2, row2));
        SheetRangeImpl range = new SheetRangeImpl(this, col1, row1, col2, row2);
        mergedCells.add(range);
        return range;
    }

    public void unmergeCells(Range r)
    {
        mergedCells.unmergeCells(r);
    }

    public void setHeader(String l, String c, String r)
    {
        HeaderFooter header = new HeaderFooter();
        header.getLeft().append(l);
        header.getCentre().append(c);
        header.getRight().append(r);
        settings.setHeader(header);
    }

    public void setFooter(String l, String c, String r)
    {
        HeaderFooter footer = new HeaderFooter();
        footer.getLeft().append(l);
        footer.getCentre().append(c);
        footer.getRight().append(r);
        settings.setFooter(footer);
    }

    public void setPageSetup(PageOrientation p)
    {
        settings.setOrientation(p);
    }

    public void setPageSetup(PageOrientation p, double hm, double fm)
    {
        settings.setOrientation(p);
        settings.setHeaderMargin(hm);
        settings.setFooterMargin(fm);
    }

    public void setPageSetup(PageOrientation p, PaperSize ps, double hm, double fm)
    {
        settings.setPaperSize(ps);
        settings.setOrientation(p);
        settings.setHeaderMargin(hm);
        settings.setFooterMargin(fm);
    }

    public SheetSettings getSettings()
    {
        return settings;
    }

    WorkbookSettings getWorkbookSettings()
    {
        return workbookSettings;
    }

    public void addRowPageBreak(int row)
    {
        Iterator i = rowBreaks.iterator();
        boolean found = false;
        do
        {
            if(!i.hasNext() || found)
                break;
            if(((Integer)i.next()).intValue() == row)
                found = true;
        } while(true);
        if(!found)
            rowBreaks.add(new Integer(row));
    }

    public void addColumnPageBreak(int col)
    {
        Iterator i = columnBreaks.iterator();
        boolean found = false;
        do
        {
            if(!i.hasNext() || found)
                break;
            if(((Integer)i.next()).intValue() == col)
                found = true;
        } while(true);
        if(!found)
            columnBreaks.add(new Integer(col));
    }

    private Chart[] getCharts()
    {
        return sheetWriter.getCharts();
    }

    private DrawingGroupObject[] getDrawings()
    {
        DrawingGroupObject dr[] = new DrawingGroupObject[drawings.size()];
        dr = (DrawingGroupObject[])drawings.toArray(dr);
        return dr;
    }

    void checkMergedBorders()
    {
        sheetWriter.setWriteData(rows, rowBreaks, columnBreaks, hyperlinks, mergedCells, columnFormats);
        sheetWriter.setDimensions(getRows(), getColumns());
        sheetWriter.checkMergedBorders();
    }

    private WorkspaceInformationRecord getWorkspaceOptions()
    {
        return sheetWriter.getWorkspaceOptions();
    }

    void rationalize(IndexMapping xfMapping, IndexMapping fontMapping, IndexMapping formatMapping)
    {
        ColumnInfoRecord cir;
        for(Iterator i = columnFormats.iterator(); i.hasNext(); cir.rationalize(xfMapping))
            cir = (ColumnInfoRecord)i.next();

        for(int i = 0; i < rows.length; i++)
            if(rows[i] != null)
                rows[i].rationalize(xfMapping);

        Chart charts[] = getCharts();
        for(int c = 0; c < charts.length; c++)
            charts[c].rationalize(xfMapping, fontMapping, formatMapping);

    }

    WritableWorkbookImpl getWorkbook()
    {
        return workbook;
    }

    public CellFormat getColumnFormat(int col)
    {
        return getColumnView(col).getFormat();
    }

    public int getColumnWidth(int col)
    {
        return getColumnView(col).getDimension();
    }

    public int getRowHeight(int row)
    {
        return getRowView(row).getDimension();
    }

    boolean isChartOnly()
    {
        return chartOnly;
    }

    public CellView getRowView(int row)
    {
        CellView cv = new CellView();
        RowRecord rr = getRowRecord(row);
        if(rr == null || rr.isDefaultHeight())
        {
            cv.setDimension(settings.getDefaultRowHeight());
            cv.setSize(settings.getDefaultRowHeight());
        } else
        if(rr.isCollapsed())
        {
            cv.setHidden(true);
        } else
        {
            cv.setDimension(rr.getRowHeight());
            cv.setSize(rr.getRowHeight());
        }
        return cv;
        RowsExceededException e;
        e;
        cv.setDimension(settings.getDefaultRowHeight());
        cv.setSize(settings.getDefaultRowHeight());
        return cv;
    }

    public CellView getColumnView(int col)
    {
        ColumnInfoRecord cir = getColumnInfo(col);
        CellView cv = new CellView();
        if(cir != null)
        {
            cv.setDimension(cir.getWidth() / 256);
            cv.setSize(cir.getWidth());
            cv.setHidden(cir.getHidden());
            cv.setFormat(cir.getCellFormat());
        } else
        {
            cv.setDimension(settings.getDefaultColumnWidth() / 256);
            cv.setSize(settings.getDefaultColumnWidth());
        }
        return cv;
    }

    public void addImage(WritableImage image)
    {
        boolean supported = false;
        File imageFile = image.getImageFile();
        String fileType = "?";
        if(imageFile != null)
        {
            String fileName = imageFile.getName();
            int fileTypeIndex = fileName.lastIndexOf(46);
            fileType = fileTypeIndex == -1 ? "" : fileName.substring(fileTypeIndex + 1);
            for(int i = 0; i < imageTypes.length && !supported; i++)
                if(fileType.equalsIgnoreCase(imageTypes[i]))
                    supported = true;

        } else
        {
            supported = true;
        }
        if(supported)
        {
            workbook.addDrawing(image);
            drawings.add(image);
            images.add(image);
        } else
        {
            StringBuffer message = new StringBuffer("Image type ");
            message.append(fileType);
            message.append(" not supported.  Supported types are ");
            message.append(imageTypes[0]);
            for(int i = 1; i < imageTypes.length; i++)
            {
                message.append(", ");
                message.append(imageTypes[i]);
            }

            logger.warn(message.toString());
        }
    }

    public int getNumberOfImages()
    {
        return images.size();
    }

    public WritableImage getImage(int i)
    {
        return (WritableImage)images.get(i);
    }

    public Image getDrawing(int i)
    {
        return (Image)images.get(i);
    }

    public void removeImage(WritableImage wi)
    {
        drawings.remove(wi);
        images.remove(wi);
        drawingsModified = true;
        workbook.removeDrawing(wi);
    }

    private String validateName(String n)
    {
        if(n.length() > 31)
        {
            logger.warn("Sheet name " + n + " too long - truncating");
            n = n.substring(0, 31);
        }
        if(n.charAt(0) == '\'')
        {
            logger.warn("Sheet naming cannot start with ' - removing");
            n = n.substring(1);
        }
        for(int i = 0; i < illegalSheetNameCharacters.length; i++)
        {
            String newname = n.replace(illegalSheetNameCharacters[i], '@');
            if(n != newname)
                logger.warn(illegalSheetNameCharacters[i] + " is not a valid character within a sheet name - replacing");
            n = newname;
        }

        return n;
    }

    void addDrawing(DrawingGroupObject o)
    {
        drawings.add(o);
        Assert.verify(!(o instanceof Drawing));
    }

    void removeDrawing(DrawingGroupObject o)
    {
        int origSize = drawings.size();
        drawings.remove(o);
        int newSize = drawings.size();
        drawingsModified = true;
        Assert.verify(newSize == origSize - 1);
    }

    public int[] getRowPageBreaks()
    {
        int rb[] = new int[rowBreaks.size()];
        int pos = 0;
        for(Iterator i = rowBreaks.iterator(); i.hasNext();)
        {
            rb[pos] = ((Integer)i.next()).intValue();
            pos++;
        }

        return rb;
    }

    public int[] getColumnPageBreaks()
    {
        int rb[] = new int[columnBreaks.size()];
        int pos = 0;
        for(Iterator i = columnBreaks.iterator(); i.hasNext();)
        {
            rb[pos] = ((Integer)i.next()).intValue();
            pos++;
        }

        return rb;
    }

    void addValidationCell(CellValue cv)
    {
        validatedCells.add(cv);
    }

    ComboBox getComboBox()
    {
        return comboBox;
    }

    void setComboBox(ComboBox cb)
    {
        comboBox = cb;
    }

    public DataValidation getDataValidation()
    {
        return dataValidation;
    }

    private void autosizeColumns()
    {
        Integer col;
        for(Iterator i = autosizedColumns.iterator(); i.hasNext(); autosizeColumn(col.intValue()))
            col = (Integer)i.next();

    }

    private void autosizeColumn(int col)
    {
        int maxWidth = 0;
        ColumnInfoRecord cir = getColumnInfo(col);
        Font columnFont = cir.getCellFormat().getFont();
        Font defaultFont = WritableWorkbook.NORMAL_STYLE.getFont();
        for(int i = 0; i < numRows; i++)
        {
            Cell cell = null;
            if(rows[i] != null)
                cell = rows[i].getCell(col);
            if(cell == null)
                continue;
            String contents = cell.getContents();
            Font font = cell.getCellFormat().getFont();
            Font activeFont = font.equals(defaultFont) ? columnFont : font;
            int pointSize = activeFont.getPointSize();
            int numChars = contents.length();
            if(activeFont.isItalic() || activeFont.getBoldWeight() > 400)
                numChars += 2;
            int points = numChars * pointSize;
            maxWidth = Math.max(maxWidth, points * 256);
        }

        cir.setWidth(maxWidth / defaultFont.getPointSize());
    }

    void importSheet(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.importSheet();
        dataValidation = si.getDataValidation();
        comboBox = si.getComboBox();
        plsRecord = si.getPLSRecord();
        chartOnly = si.isChartOnly();
        buttonPropertySet = si.getButtonPropertySet();
    }

    static Class class$(String x0)
    {
        return Class.forName(x0);
        ClassNotFoundException x1;
        x1;
        throw new NoClassDefFoundError(x1.getMessage());
    }

    static 
    {
        logger = Logger.getLogger(class$jxl$write$biff$WritableSheetImpl != null ? class$jxl$write$biff$WritableSheetImpl : (class$jxl$write$biff$WritableSheetImpl = class$("jxl.write.biff.WritableSheetImpl")));
    }

// Unreferenced inner classes:

/* anonymous class */
    static class _cls1
    {
    }

}

⌨️ 快捷键说明

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