Beispiel #1
0
 internal TVirtualCellList(ExcelFile aXls, TWorkbook aWorkbook)
 {
     FWorkbook  = aWorkbook;
     FXls       = aXls;
     ArrayFmlas = new Dictionary <TOneCellRef, TFormulaRecord>();
     TableFmlas = new Dictionary <TOneCellRef, TFormulaRecord>();
 }
Beispiel #2
0
        internal void InsertSheets(int CopyFrom, int InsertBefore, int SheetCount, TWorkbook SourceWorkbook)
        {
            if (SourceWorkbook == null)
            {
                SourceWorkbook = this;
            }
            if (CopyFrom >= SourceWorkbook.Sheets.Count)
            {
                XlsMessages.ThrowException(XlsErr.ErrInvalidSheetNo, CopyFrom, -1, SourceWorkbook.Sheets.Count - 1);
            }
            if (InsertBefore > Sheets.Count)
            {
                XlsMessages.ThrowException(XlsErr.ErrInvalidSheetNo, InsertBefore, 0, Sheets.Count);
            }

            TSheet aSheet      = null;
            int    OptionFlags = 0;

            if (CopyFrom >= 0)
            {
                aSheet      = SourceWorkbook.Sheets[CopyFrom];
                OptionFlags = SourceWorkbook.Globals.SheetOptionFlags(CopyFrom);
            }

            int NewCopyFrom = CopyFrom;

            if (SourceWorkbook == this && CopyFrom >= InsertBefore)
            {
                NewCopyFrom += SheetCount;
            }
            Globals.InsertSheets(CopyFrom, InsertBefore, OptionFlags, XlsMessages.GetString(XlsErr.BaseSheetName), SheetCount, SourceWorkbook.Sheets);

            TSheetInfo SheetInfo = new TSheetInfo(-1, -1, -1, SourceWorkbook.Globals, Globals, aSheet, null, false);

            for (int i = 0; i < SheetCount; i++)
            {
                SheetInfo.InsSheet           = InsertBefore + i;
                SheetInfo.SourceFormulaSheet = NewCopyFrom;
                SheetInfo.DestFormulaSheet   = InsertBefore;
                SheetInfo.DestSheet          = null; //keep it null, since the reference does not exist yet.

                if (aSheet == null)
                {
                    Sheets.Insert(InsertBefore, TWorkSheet.CreateFromData(Globals, Globals.Workbook.XlsBiffVersion, Globals.Workbook.ExcelFileFormat));
                }
                else
                {
                    SheetInfo.DestFormulaSheet = InsertBefore + i;
                    Globals.Names.InsertSheets(NewCopyFrom, InsertBefore + i, 1, SheetInfo, SourceWorkbook == this); //names must be inserted before the sheet is cloned, so formulas can refer to them.
                    Sheets.Insert(InsertBefore + i, TSheet.Clone(aSheet, SheetInfo));
                    SheetInfo.DestSheet = Sheets[InsertBefore + i];
                    Sheets[InsertBefore + i].ArrangeCopySheet(SheetInfo);
                }
            }
        }
Beispiel #3
0
 internal void DeleteSheets(int SheetIndex, int SheetCount, TWorkbook Workbook)
 {
     if (HasMacro)
     {
         XlsMessages.ThrowException(XlsErr.ErrCantDeleteSheetWithMacros);            //If we delete a sheet that has a corresponding macro on the vba stream, Excel 2000 will crash when opening the file. Excel Xp seems to handle this ok.
     }
     for (int i = 0; i < SheetCount; i++)
     {
         FBoundSheets.DeleteSheet(SheetIndex);
     }
     FReferences.InsertSheets(SheetIndex, -SheetCount);
     FNames.DeleteSheets(SheetIndex, SheetCount, Workbook);
 }
Beispiel #4
0
        internal void CleanUnusedNames(TWorkbook Workbook)
        {
            TDeletedRanges DeletedRanges = Workbook.FindUnreferencedRanges(-1, 0);

            for (int i = DeletedRanges.Count - 1; i >= 0; i--)
            {
                if (!DeletedRanges.Referenced(i) && !this[i].HasFormulaData && CanDeleteName(i))                  //don't delete internal names, or macro names.
                {
                    FList.RemoveAt(i);
                    DeletedRanges.AddNameForDelete(i);
                }
            }

            if (DeletedRanges.NeedsUpdate)
            {
                Workbook.UpdateDeletedRanges(-1, 0, DeletedRanges);
            }
        }
Beispiel #5
0
        internal void DeleteName(int Index, TWorkbook Workbook)
        {
            if (Index < 0 || Index >= Count)
            {
                XlsMessages.ThrowException(XlsErr.ErrXlsIndexOutBounds, Index, "Index", 0, Count - 1);
            }

            TDeletedRanges DeletedRanges = Workbook.FindUnreferencedRanges(-1, 0);

            if (!DeletedRanges.Referenced(Index) && CanDeleteName(Index))              //don't delete internal names, or macro names.
            {
                FList.RemoveAt(Index);
                DeletedRanges.AddNameForDelete(Index);
                Workbook.UpdateDeletedRanges(-1, 0, DeletedRanges);
            }
            else
            {
                ClearName(Index);
            }
        }
Beispiel #6
0
        internal void DeleteSheets(int SheetIndex, int SheetCount, TWorkbook Workbook)
        {
            TDeletedRanges DeletedRanges = Workbook.FindUnreferencedRanges(SheetIndex, SheetCount);

            for (int i = Count - 1; i >= 0; i--)
            {
                if ((this[i].RangeSheet >= SheetIndex) && (this[i].RangeSheet < SheetIndex + SheetCount))
                {
                    /* We cannot just delete the range, or formulas referring this range would crash (or refer to the wrong name).
                     * To actually delete here, we need to first find out whether this range is used.
                     * If it is not, go through all the formulas, charts, pivot tables, etc, and update the references to
                     * ranges less than this one to one less.
                     */

                    if (!DeletedRanges.Referenced(i) && CanDeleteName(i))  //don't delete internal names, or macro names.
                    {
                        FList.RemoveAt(i);
                        DeletedRanges.AddNameForDelete(i);
                    }
                    else
                    {
                        EnsureUniqueGlobalName(i);
                        this[i].RangeSheet = -1;
                    }
                }
                else
                {
                    this[i].ArrangeInsertSheets(SheetIndex, -SheetCount);
                }
            }

            if (DeletedRanges.NeedsUpdate)
            {
                Workbook.UpdateDeletedRanges(SheetIndex, SheetCount, DeletedRanges); //Update formulas, charts, etc.
            }
        }
Beispiel #7
0
 public TVirtualReader(ExcelFile aXls, TWorkbook aWorkbook)
 {
     CellList      = new TVirtualCellList(aXls, aWorkbook);
     ArrayFormulas = new T2dCellList();
     Xls           = aXls;
 }
Beispiel #8
0
 internal void MergeFromPxlWorkbook(TWorkbook SourceWorkbook)
 {
     FGlobals.MergeFromPxlGlobals(SourceWorkbook.FGlobals);
     FSheets.MergeFromPxlSheets(SourceWorkbook.FSheets);
 }