sheet.java

来自「EXCEL read and write」· Java 代码 · 共 1,758 行 · 第 1/5 页

JAVA
1,758
字号
                                 rec.getLeftColumn(), (byte)rec.getActivePane(), windowTwo.getFreezePanes());    }    public SelectionRecord getSelection()    {        return selection;    }    public void setSelection( SelectionRecord selection )    {        this.selection = selection;    }    /**     * creates a Protect record with protect set to false.     */    private static ProtectRecord createProtect() {        if (log.check( POILogger.DEBUG )) {            log.log(POILogger.DEBUG, "create protect record with protection disabled");        }        ProtectRecord retval = new ProtectRecord();        retval.setProtect(false); // TODO - supply param to constructor        return retval;    }    /**     * creates an ObjectProtect record with protect set to false.     */    private static ObjectProtectRecord createObjectProtect() {        if (log.check( POILogger.DEBUG ))            log.log(POILogger.DEBUG, "create protect record with protection disabled");        ObjectProtectRecord retval = new ObjectProtectRecord();        retval.setProtect(false);        return retval;    }    /**     * creates a ScenarioProtect record with protect set to false.     */    private static ScenarioProtectRecord createScenarioProtect() {        if (log.check( POILogger.DEBUG ))            log.log(POILogger.DEBUG, "create protect record with protection disabled");        ScenarioProtectRecord retval = new ScenarioProtectRecord();        retval.setProtect(false);        return retval;    }    /** Returns the ProtectRecord.     * If one is not contained in the sheet, then one is created.     */    public ProtectRecord getProtect()    {        if (protect == null) {            protect = createProtect();            // Insert the newly created protect record just before DefaultColWidthRecord            int loc = findFirstRecordLocBySid(DefaultColWidthRecord.sid);            records.add(loc, protect);        }        return protect;    }    /** Returns the PasswordRecord.     * If one is not contained in the sheet, then one is created.     */    public PasswordRecord getPassword()    {        if (password == null) {            password = createPassword();            //Insert the newly created password record at the end of the record (just before the EOF)            int loc = findFirstRecordLocBySid(EOFRecord.sid);            records.add(loc, password);        }        return password;    }    /**     * creates a Password record with password set to 00.     */    private static PasswordRecord createPassword() {        if (log.check( POILogger.DEBUG )) {            log.log(POILogger.DEBUG, "create password record with 00 password");        }        PasswordRecord retval = new PasswordRecord();        retval.setPassword((short)00);        return retval;    }    /**    /**     * Sets whether the gridlines are shown in a viewer.     * @param show whether to show gridlines or not     */    public void setDisplayGridlines(boolean show) {        windowTwo.setDisplayGridlines(show);    }    /**     * Returns if gridlines are displayed.     * @return whether gridlines are displayed     */    public boolean isDisplayGridlines() {    return windowTwo.getDisplayGridlines();    }    /**     * Sets whether the formulas are shown in a viewer.     * @param show whether to show formulas or not     */    public void setDisplayFormulas(boolean show) {        windowTwo.setDisplayFormulas(show);    }    /**     * Returns if formulas are displayed.     * @return whether formulas are displayed     */    public boolean isDisplayFormulas() {    return windowTwo.getDisplayFormulas();    }    /**     * Sets whether the RowColHeadings are shown in a viewer.     * @param show whether to show RowColHeadings or not     */    public void setDisplayRowColHeadings(boolean show) {        windowTwo.setDisplayRowColHeadings(show);    }    /**     * Returns if RowColHeadings are displayed.     * @return whether RowColHeadings are displayed     */    public boolean isDisplayRowColHeadings() {        return windowTwo.getDisplayRowColHeadings();    }    /**     * @return whether an uncalced record must be inserted or not at generation     */    public boolean getUncalced() {        return _isUncalced;    }    /**     * @param uncalced whether an uncalced record must be inserted or not at generation     */    public void setUncalced(boolean uncalced) {        this._isUncalced = uncalced;    }    /**     * Finds the DrawingRecord for our sheet, and     *  attaches it to the DrawingManager (which knows about     *  the overall DrawingGroup for our workbook).     * If requested, will create a new DrawRecord     *  if none currently exist     * @param drawingManager The DrawingManager2 for our workbook     * @param createIfMissing Should one be created if missing?     */    public int aggregateDrawingRecords(DrawingManager2 drawingManager, boolean createIfMissing)    {        int loc = findFirstRecordLocBySid(DrawingRecord.sid);        boolean noDrawingRecordsFound = (loc == -1);        if (noDrawingRecordsFound)        {            if(!createIfMissing) {                // None found, and not allowed to add in                return -1;            }            EscherAggregate aggregate = new EscherAggregate( drawingManager );            loc = findFirstRecordLocBySid(EscherAggregate.sid);            if (loc == -1)            {                loc = findFirstRecordLocBySid( WindowTwoRecord.sid );            }            else            {                getRecords().remove(loc);            }            getRecords().add( loc, aggregate );            return loc;        }        else        {            List records = getRecords();            EscherAggregate r = EscherAggregate.createAggregate( records, loc, drawingManager );            int startloc = loc;            while ( loc + 1 < records.size()                    && records.get( loc ) instanceof DrawingRecord                    && records.get( loc + 1 ) instanceof ObjRecord )            {                loc += 2;            }            int endloc = loc-1;            for(int i = 0; i < (endloc - startloc + 1); i++)                records.remove(startloc);            records.add(startloc, r);            return startloc;        }    }    /**     * Perform any work necessary before the sheet is about to be serialized.     * For instance the escher aggregates size needs to be calculated before     * serialization so that the dgg record (which occurs first) can be written.     */    public void preSerialize()    {        for ( Iterator iterator = getRecords().iterator(); iterator.hasNext(); )        {            RecordBase r = (RecordBase) iterator.next();            if (r instanceof EscherAggregate)                r.getRecordSize();   // Trigger flatterning of user model and corresponding update of dgg record.        }    }    public PageSettingsBlock getPageSettings() {        if (_psBlock == null) {            _psBlock = new PageSettingsBlock();            RecordOrderer.addNewSheetRecord(records, _psBlock);        }        return _psBlock;    }    public void setColumnGroupCollapsed(int columnNumber, boolean collapsed) {        if (collapsed) {            _columnInfos.collapseColumn(columnNumber);        } else {            _columnInfos.expandColumn(columnNumber);        }    }    /**     * protect a spreadsheet with a password (not encypted, just sets protect     * flags and the password.     * @param password to set     * @param objects are protected     * @param scenarios are protected     */    public void protectSheet( String password, boolean objects, boolean scenarios ) {        int protIdx = -1;        ProtectRecord prec = getProtect();        PasswordRecord pass = getPassword();        prec.setProtect(true);        pass.setPassword(PasswordRecord.hashPassword(password));        if((objprotect == null && objects) || (scenprotect != null && scenarios)) {            protIdx = records.indexOf( protect );        }        if(objprotect == null && objects) {            ObjectProtectRecord rec = createObjectProtect();            rec.setProtect(true);            records.add(protIdx+1,rec);            objprotect = rec;        }        if(scenprotect == null && scenarios) {            ScenarioProtectRecord srec = createScenarioProtect();            srec.setProtect(true);            records.add(protIdx+2,srec);            scenprotect = srec;        }    }    /**     * unprotect objects in the sheet (will not protect them, but any set to false are     * unprotected.     * @param sheet is unprotected (false = unprotect)     * @param objects are unprotected (false = unprotect)     * @param scenarios are unprotected (false = unprotect)     */    public void unprotectSheet( boolean sheet, boolean objects, boolean scenarios ) {        if (!sheet) {           ProtectRecord prec = getProtect();           prec.setProtect(sheet);           PasswordRecord pass = getPassword();           pass.setPassword((short)00);        }        if(objprotect != null && !objects) {            objprotect.setProtect(false);        }        if(scenprotect != null && !scenarios) {            scenprotect.setProtect(false);        }    }    /**     * @return {sheet is protected, objects are proteced, scenarios are protected}     */    public boolean[] isProtected() {        return new boolean[] { (protect != null && protect.getProtect()),                             (objprotect != null && objprotect.getProtect()),                             (scenprotect != null && scenprotect.getProtect())};    }    public void groupRowRange(int fromRow, int toRow, boolean indent)    {        for (int rowNum = fromRow; rowNum <= toRow; rowNum++)        {            RowRecord row = getRow( rowNum );            if (row == null)            {                row = RowRecordsAggregate.createRow(rowNum);                addRow( row );            }            int level = row.getOutlineLevel();            if (indent) level++; else level--;            level = Math.max(0, level);            level = Math.min(7, level);            row.setOutlineLevel((short) ( level ));        }        recalcRowGutter();    }    private void recalcRowGutter()    {        int maxLevel = 0;        Iterator iterator = _rowsAggregate.getIterator();        while ( iterator.hasNext() )        {            RowRecord rowRecord = (RowRecord) iterator.next();            maxLevel = Math.max(rowRecord.getOutlineLevel(), maxLevel);        }        // Grab the guts record, adding if needed        GutsRecord guts = getGutsRecord();        // Set the levels onto it        guts.setRowLevelMax( (short) ( maxLevel + 1 ) );        guts.setLeftRowGutter( (short) ( 29 + (12 * (maxLevel)) ) );    }    public DataValidityTable getOrCreateDataValidityTable() {        if (_dataValidityTable == null) {            DataValidityTable result = new DataValidityTable();            RecordOrderer.addNewSheetRecord(records, result);            _dataValidityTable = result;        }        return _dataValidityTable;    }}

⌨️ 快捷键说明

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