Exemplo n.º 1
0
        // TODO: Consider how to deal with invalid sheetName. I presume xlSheetId will fail.
        // Perhaps throw a custom exception...?
        public ExcelReference(int rowFirst, int rowLast, int columnFirst, int columnLast, string sheetName)
        {
            ExcelReference sheetRef = (ExcelReference)XlCall.Excel(XlCall.xlSheetId, sheetName);

            this.sheetId = sheetRef.SheetId;
            rectangle    = new ExcelRectangle(rowFirst, rowLast, columnFirst, columnLast);
        }
Exemplo n.º 2
0
 // TODO: Consider how to deal with invalid sheetName. I presume xlSheetId will fail.
 // Perhaps throw a custom exception...?
 public ExcelReference(int rowFirst, int rowLast, int columnFirst, int columnLast, string sheetName)
 {
     ExcelReference sheetRef = (ExcelReference)XlCall.Excel(XlCall.xlSheetId, sheetName);
     this.sheetId = sheetRef.SheetId;
     ExcelRectangle rect = new ExcelRectangle(rowFirst, rowLast, columnFirst, columnLast);
     rectangles.Add(rect);
 }
Exemplo n.º 3
0
        public ExcelReference(int rowFirst, int rowLast, int columnFirst, int columnLast, IntPtr sheetId)
        {
            this.sheetId = sheetId;
            ExcelRectangle rect = new ExcelRectangle(rowFirst, rowLast, columnFirst, columnLast);

            rectangles.Add(rect);
        }
Exemplo n.º 4
0
 // CAUTION: These 'private' functions are called via reflection by the ExcelDna.Loader marshaler
 // Returns arrays containing all the inner rectangles (including the one we pretend is outside).
 private int[][] GetRectangles()
 {
     int[][] intRects = new int[rectangles.Count][];
     for (int i = 0; i < rectangles.Count; i++)
     {
         ExcelRectangle rect = rectangles[i];
         intRects[i] = new int[] { rect.RowFirst, rect.RowLast,
                                   rect.ColumnFirst, rect.ColumnLast };
     }
     return(intRects);
 }
Exemplo n.º 5
0
 bool Equals(ExcelRectangle other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(other.RowFirst == RowFirst && other.RowLast == RowLast && other.ColumnFirst == ColumnFirst && other.ColumnLast == ColumnLast);
 }
Exemplo n.º 6
0
        public ExcelReference(IEnumerable <ExcelReference> references)
        {
            int    refCount = 0;
            IntPtr sheetId  = IntPtr.Zero;
            Dictionary <int, int[]> rectangles = new Dictionary <int, int[]>();

            foreach (ExcelReference reference in references)
            {
                if (sheetId == IntPtr.Zero)
                {
                    sheetId = reference.SheetId;
                }

                if (sheetId != reference.SheetId)
                {
                    throw new ArgumentException("Not all references correspond to a single sheet.");
                }

                rectangles[refCount] = new[]
                {
                    reference.RowFirst,
                    reference.RowLast,
                    reference.ColumnFirst,
                    reference.ColumnLast
                };

                refCount++;
            }

            this.sheetId = sheetId;
            int rectCount = rectangles.Count;

            int[] rect = rectangles[0];
            rectangle = new ExcelRectangle(rect[0], rect[1], rect[2], rect[3]);

            int furtherRectangleCount = rectCount - 1;

            if (furtherRectangleCount > 0)
            {
                furtherRectangles = new ExcelRectangle[furtherRectangleCount];
                for (int i = 0; i < furtherRectangleCount; i++)
                {
                    rect = rectangles[i + 1];
                    Debug.Assert(rect.Length == 4);
                    furtherRectangles[i] = new ExcelRectangle(rect[0], rect[1], rect[2], rect[3]);
                }
            }
        }
Exemplo n.º 7
0
        // CAUTION: These 'private' functions are called via reflection by the ExcelDna.Loader marshaler
        // Returns arrays containing all the inner rectangles (including the one we pretend is outside).
        private int[][] GetRectangles()
        {
            int rectangleCount        = GetRectangleCount();
            int furtherRectangleCount = rectangleCount - 1;

            int[][] intRects = new int[rectangleCount][];
            intRects[0] = new int[] { RowFirst, RowLast, ColumnFirst, ColumnLast };
            for (int i = 0; i < furtherRectangleCount; i++)
            {
                // We only get here if there are further rectangles
                Debug.Assert(furtherRectangles != null);
                ExcelRectangle rect = furtherRectangles[i];
                intRects[i + 1] = new int[] { rect.RowFirst, rect.RowLast, rect.ColumnFirst, rect.ColumnLast };
            }
            return(intRects);
        }
Exemplo n.º 8
0
        public void AddReference(int rowFirst, int rowLast, int columnFirst, int columnLast)
        {
            ExcelRectangle rect = new ExcelRectangle(rowFirst, rowLast, columnFirst, columnLast);

            if (furtherRectangles == null)
            {
                furtherRectangles    = new ExcelRectangle[1];
                furtherRectangles[0] = rect;
                return;
            }
            if (furtherRectangles.Length >= ushort.MaxValue - 1)
            {
                throw new OverflowException("Maximum number of references exceeded");
            }

            ExcelRectangle[] newRectangles = new ExcelRectangle[furtherRectangles.Length + 1];
            Array.Copy(furtherRectangles, newRectangles, furtherRectangles.Length);
            newRectangles[newRectangles.Length - 1] = rect;
            furtherRectangles = newRectangles;
        }
Exemplo n.º 9
0
        public ExcelReference(int[][] rectangles, IntPtr sheetId)
        {
            this.sheetId = sheetId;
            int rectCount = rectangles.Length;

            int[] rect = rectangles[0];
            rectangle = new ExcelRectangle(rect[0], rect[1], rect[2], rect[3]);

            int furtherRectangleCount = rectCount - 1;

            if (furtherRectangleCount > 0)
            {
                furtherRectangles = new ExcelRectangle[furtherRectangleCount];
                for (int i = 0; i < furtherRectangleCount; i++)
                {
                    rect = rectangles[i + 1];
                    Debug.Assert(rect.Length == 4);
                    furtherRectangles[i] = new ExcelRectangle(rect[0], rect[1], rect[2], rect[3]);
                }
            }
        }
Exemplo n.º 10
0
		public ExcelReference(int rowFirst, int rowLast, int columnFirst, int columnLast, IntPtr sheetId)
		{
			this.sheetId = sheetId;
			ExcelRectangle rect = new ExcelRectangle(rowFirst, rowLast, columnFirst, columnLast);
			rectangles.Add(rect);
		}
Exemplo n.º 11
0
 bool Equals(ExcelRectangle other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return other.RowFirst == RowFirst && other.RowLast == RowLast && other.ColumnFirst == ColumnFirst && other.ColumnLast == ColumnLast;
 }