Exemplo n.º 1
0
 private void CreateAutoFilterInfoRecord(HSSFSheet sheet, int insertPos, Area3DPtg ptg)
 {
     //look for the AutoFilterInfo Record
     NPOI.HSSF.Record.Record record = sheet.Sheet.FindFirstRecordBySid(AutoFilterInfoRecord.sid);
     AutoFilterInfoRecord info;
     if (record == null)
     {
         info = new AutoFilterInfoRecord();
         sheet.Sheet.Records.Insert(insertPos, info);
     }
     else
     {
         info = record as AutoFilterInfoRecord;
     }
     info.NumEntries = (short)(ptg.LastColumn - ptg.FirstColumn + 1);
 }
Exemplo n.º 2
0
 /**
  * @return <c>true</c> if this Ptg needed to be changed
  */
 private Ptg AdjustPtgDueToRowMove(Ptg ptg, int currentExternSheetIx)
 {
     if (ptg is RefPtg)
     {
         if (currentExternSheetIx != _externSheetIndex)
         {
             // local refs on other sheets are unaffected
             return(null);
         }
         RefPtg rptg = (RefPtg)ptg;
         return(RowMoveRefPtg(rptg));
     }
     if (ptg is Ref3DPtg)
     {
         Ref3DPtg rptg = (Ref3DPtg)ptg;
         if (_externSheetIndex != rptg.ExternSheetIndex)
         {
             // only move 3D refs that refer to the sheet with cells being moved
             // (currentExternSheetIx is irrelevant)
             return(null);
         }
         return(RowMoveRefPtg(rptg));
     }
     if (ptg is Area2DPtgBase)
     {
         if (currentExternSheetIx != _externSheetIndex)
         {
             // local refs on other sheets are unaffected
             return(ptg);
         }
         return(RowMoveAreaPtg((Area2DPtgBase)ptg));
     }
     if (ptg is Area3DPtg)
     {
         Area3DPtg aptg = (Area3DPtg)ptg;
         if (_externSheetIndex != aptg.ExternSheetIndex)
         {
             // only move 3D refs that refer to the sheet with cells being moved
             // (currentExternSheetIx is irrelevant)
             return(null);
         }
         return(RowMoveAreaPtg(aptg));
     }
     return(null);
 }
Exemplo n.º 3
0
        private static Ptg CreateDeletedRef(Ptg ptg)
        {
            if (ptg is RefPtg)
            {
                return(new RefErrorPtg());
            }
            if (ptg is Ref3DPtg)
            {
                Ref3DPtg rptg = (Ref3DPtg)ptg;
                return(new DeletedRef3DPtg(rptg.ExternSheetIndex));
            }
            if (ptg is AreaPtg)
            {
                return(new AreaErrPtg());
            }
            if (ptg is Area3DPtg)
            {
                Area3DPtg area3DPtg = (Area3DPtg)ptg;
                return(new DeletedArea3DPtg(area3DPtg.ExternSheetIndex));
            }

            throw new ArgumentException("Unexpected ref ptg class (" + ptg.GetType().Name + ")");
        }
Exemplo n.º 4
0
        public HSSFAutoFilter SetAutoFilter(CellRangeAddress range)
        {
            InternalWorkbook workbook = _workbook.Workbook;
            int sheetIndex = _workbook.GetSheetIndex(this);

            NameRecord name = workbook.GetSpecificBuiltinRecord(NameRecord.BUILTIN_FILTER_DB, sheetIndex + 1);

            if (name == null)
            {
                name = workbook.CreateBuiltInName(NameRecord.BUILTIN_FILTER_DB, sheetIndex + 1);
            }

            // The built-in name must consist of a single Area3d Ptg.
            Area3DPtg ptg = new Area3DPtg(range.FirstRow, range.LastRow,
                    range.FirstColumn, range.LastColumn,
                    false, false, false, false, sheetIndex);
            name.NameDefinition = (new Ptg[] { ptg });

            AutoFilterInfoRecord r = new AutoFilterInfoRecord();
            // the number of columns that have AutoFilter enabled.
            int numcols = 1 + range.LastColumn - range.FirstColumn;
            r.NumEntries = (short)numcols;
            int idx = _sheet.FindFirstRecordLocBySid(DimensionsRecord.sid);
            _sheet.Records.Insert(idx, r);

            //create a combobox control for each column
            HSSFPatriarch p = (HSSFPatriarch)CreateDrawingPatriarch();
            for (int col = range.FirstColumn; col <= range.LastColumn; col++)
            {
                p.CreateComboBox(new HSSFClientAnchor(0, 0, 0, 0,
                        (short)col, range.FirstRow, (short)(col + 1), range.FirstRow + 1));
            }

            return new HSSFAutoFilter(this);
        }
Exemplo n.º 5
0
        /**
         *
         * @param sheetIden may be <code>null</code>
         * @param part1
         * @param part2 may be <code>null</code>
         */
        private ParseNode CreateAreaRefParseNode(SheetIdentifier sheetIden, SimpleRangePart part1,
                SimpleRangePart part2)
        {
            int extIx;
            if (sheetIden == null)
            {
                extIx = Int32.MinValue;
            }
            else
            {
                String sName = sheetIden.SheetID.Name;
                if (sheetIden.BookName == null)
                {
                    extIx = book.GetExternalSheetIndex(sName);
                }
                else
                {
                    extIx = book.GetExternalSheetIndex(sheetIden.BookName, sName);
                }
            }
            Ptg ptg;
            if (part2 == null)
            {
                CellReference cr = part1.getCellReference();
                if (sheetIden == null)
                {
                    ptg = new RefPtg(cr);
                }
                else
                {
                    ptg = new Ref3DPtg(cr, extIx);
                }
            }
            else
            {
                AreaReference areaRef = CreateAreaRef(part1, part2);

                if (sheetIden == null)
                {
                    ptg = new AreaPtg(areaRef);
                }
                else
                {
                    ptg = new Area3DPtg(areaRef, extIx);
                }
            }
            return new ParseNode(ptg);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Sets the repeating rows and columns for a sheet (as found in
        /// File-&gt;PageSetup-&gt;Sheet).  This Is function Is included in the workbook
        /// because it Creates/modifies name records which are stored at the
        /// workbook level.
        /// </summary>
        /// <param name="sheetIndex">0 based index to sheet.</param>
        /// <param name="startColumn">0 based start of repeating columns.</param>
        /// <param name="endColumn">0 based end of repeating columns.</param>
        /// <param name="startRow">0 based start of repeating rows.</param>
        /// <param name="endRow">0 based end of repeating rows.</param>
        /// <example>
        /// To set just repeating columns:
        /// workbook.SetRepeatingRowsAndColumns(0,0,1,-1-1);
        /// To set just repeating rows:
        /// workbook.SetRepeatingRowsAndColumns(0,-1,-1,0,4);
        /// To remove all repeating rows and columns for a sheet.
        /// workbook.SetRepeatingRowsAndColumns(0,-1,-1,-1,-1);
        /// </example>
        public void SetRepeatingRowsAndColumns(int sheetIndex,
                                               int startColumn, int endColumn,
                                               int startRow, int endRow)
        {
            // Check arguments
            if (startColumn == -1 && endColumn != -1) throw new ArgumentException("Invalid column range specification");
            if (startRow == -1 && endRow != -1) throw new ArgumentException("Invalid row range specification");
            if (startColumn < -1 || startColumn >= 0xFF) throw new ArgumentException("Invalid column range specification");
            if (endColumn < -1 || endColumn >= 0xFF) throw new ArgumentException("Invalid column range specification");
            if (startRow < -1 || startRow > 65535) throw new ArgumentException("Invalid row range specification");
            if (endRow < -1 || endRow > 65535) throw new ArgumentException("Invalid row range specification");
            if (startColumn > endColumn) throw new ArgumentException("Invalid column range specification");
            if (startRow > endRow) throw new ArgumentException("Invalid row range specification");

            HSSFSheet sheet = GetSheetAt(sheetIndex);
            int externSheetIndex = Workbook.CheckExternSheet(sheetIndex);

            bool settingRowAndColumn =
                    startColumn != -1 && endColumn != -1 && startRow != -1 && endRow != -1;
            bool removingRange =
                    startColumn == -1 && endColumn == -1 && startRow == -1 && endRow == -1;

            bool IsNewRecord = false;


            int rowColHeaderNameIndex = FindExistingBuiltinNameRecordIdx(sheetIndex, NameRecord.BUILTIN_PRINT_TITLE);
            if (removingRange)
            {
                if (rowColHeaderNameIndex >= 0)
                {
                    workbook.RemoveName(rowColHeaderNameIndex);
                }
                return;
            }
            NameRecord nameRecord;
            if (rowColHeaderNameIndex < 0)
            {
                //does a lot of the house keeping for builtin records, like setting lengths to zero etc
                nameRecord = workbook.CreateBuiltInName(NameRecord.BUILTIN_PRINT_TITLE, sheetIndex + 1);
                IsNewRecord = true;
            }
            else
            {
                nameRecord = workbook.GetNameRecord(rowColHeaderNameIndex);
                IsNewRecord = false;
            }


            ArrayList temp = new ArrayList();
            if (settingRowAndColumn)
            {
                int exprsSize = 2 * 11 + 1; // 2 * Area3DPtg.SIZE + UnionPtg.SIZE
                temp.Add(new MemFuncPtg(exprsSize));
            }
            if (startColumn >= 0)
            {
                Area3DPtg colArea = new Area3DPtg(0, MAX_ROW, startColumn, endColumn,
                        false, false, false, false, externSheetIndex);
                temp.Add(colArea);
            }
            if (startRow >= 0)
            {
                Area3DPtg rowArea = new Area3DPtg(startRow, endRow, 0, MAX_COLUMN,
                        false, false, false, false, externSheetIndex);
                temp.Add(rowArea);
            }
            if (settingRowAndColumn)
            {
                temp.Add(UnionPtg.instance);
            }
            Ptg[] ptgs = (Ptg[])temp.ToArray(typeof(Ptg));
            nameRecord.NameDefinition = ptgs;

            if (IsNewRecord)
            {
                HSSFName newName = new HSSFName(this, nameRecord);
                names.Add(newName);
            }

            HSSFPrintSetup printSetup = sheet.PrintSetup;
            printSetup.ValidSettings = (false);

            sheet.IsActive = (true);
        }
Exemplo n.º 7
0
 private LinkedDataRecord CreateCategoriesLinkedDataRecord()
 {
     LinkedDataRecord r = new LinkedDataRecord();
     r.LinkType = (LinkedDataRecord.LINK_TYPE_CATEGORIES);
     r.ReferenceType = (LinkedDataRecord.REFERENCE_TYPE_WORKSHEET);
     r.IsCustomNumberFormat = (false);
     r.IndexNumberFmtRecord = ((short)0);
     Area3DPtg p = new Area3DPtg(0, 31, 1, 1,
             false, false, false, false, 0);
     r.FormulaOfLink = (new Ptg[] { p, });
     return r;
 }
Exemplo n.º 8
0
        /** Sets the reference , the area only (range)
         * @param ref1 area reference
         */
        public void SetAreaReference(String ref1){
        //Trying to Find if what ptg do we need
        RangeAddress ra = new RangeAddress(ref1);
        Ptg oldPtg;

        if (field_13_name_definition.Length < 1)
        {
            oldPtg = CreateNewPtg();
        }
        else
        {
            //Trying to find extern sheet index
            oldPtg = field_13_name_definition[0];
        }

        int externSheetIndex = 0;

        if (oldPtg.GetType() == typeof(Area3DPtg)){
            externSheetIndex =  ((Area3DPtg) oldPtg).ExternSheetIndex;

        } else if (oldPtg.GetType() == typeof(Ref3DPtg)){
            externSheetIndex =  ((Ref3DPtg) oldPtg).ExternSheetIndex;
        }
        ArrayList temp = new ArrayList();
        if (ra.HasRange) {
        	// Is it contiguous or not?
        	AreaReference[] refs = 
        		AreaReference.GenerateContiguous(ref1);

            // Add the area reference(s) 
        	for(int i=0; i<refs.Length; i++) {
                Ptg ptg1 = new Area3DPtg(refs[i].FormatAsString(), externSheetIndex);
                temp.Add(ptg1);
        	}
        	// And then a Union if we had more than one area
        	if(refs.Length > 1) {
                Ptg ptg = UnionPtg.instance;
                temp.Add(ptg);
        	}
        } else {
            Ref3DPtg ptg = new Ref3DPtg(ra.FromCell, externSheetIndex);
            temp.Add(ptg);
        }
        Ptg[] ptgs = new Ptg[temp.Count];
        ptgs=(Ptg[])temp.ToArray(typeof(Ptg));
        field_13_name_definition = ptgs;
    }