Esempio n. 1
0
        /// <summary>
        /// Updates a supplied list with defined name information if there is any.
        /// </summary>
        /// <param name="mapCoOrdinate">A <see cref="ExcelMapCoOrdinate"/></param>
        /// <param name="sheetName">A worksheet name</param>
        /// <param name="values">The <see cref="List<ExcelDefinedNameInfo>"/> to be updated</param>
        internal static void UpdateDefinedNameList(ExcelMapCoOrdinate mapCoOrdinate, string sheetName, ref List <ExcelDefinedNameInfo> values)
        {
            if (values == null)
            {
                throw new ArgumentNullException("values");
            }

            if (mapCoOrdinate == null)
            {
                return;
            }

            if (!string.IsNullOrEmpty(mapCoOrdinate.DefinedName))
            {
                var info = new ExcelDefinedNameInfo
                {
                    DefinedName      = mapCoOrdinate.DefinedName,
                    StartRowIndex    = (uint)mapCoOrdinate.ExcelRowStart,
                    EndRowIndex      = (uint)mapCoOrdinate.ExcelRowEnd,
                    StartColumnIndex = (uint)mapCoOrdinate.ExcelColumnStart,
                    EndColumnIndex   = (uint)mapCoOrdinate.ExcelColumnEnd,
                    SheetName        = sheetName,
                };

                values.Add(info);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Sets the parent of this <see cref="ExcelMapCoOrdinate"/>
 /// </summary>
 /// <param name="parent">The parent/container <see cref="ExcelMapCoOrdinate"/></param>
 internal void SetParent(ExcelMapCoOrdinate parent)
 {
     if (parent == null)
     {
         throw new ArgumentNullException("parent");
     }
     this.parent = parent;
 }
Esempio n. 3
0
 /// <summary>
 /// Adds a keyed element to a list of keyed elements in a <see cref="ExcelMapCoOrdinate"/> derived class.
 /// </summary>
 /// <param name="key"></param>
 /// <param name="element"></param>
 internal static void AddKeyedElement(this ExcelMapCoOrdinate map, string key, BaseMap element)
 {
     if (map.KeyedElements == null)
     {
         map.KeyedElements = new List <KeyValuePair <string, BaseMap> >();
     }
     map.KeyedElements.Add(new KeyValuePair <string, BaseMap>(key, element));
 }
Esempio n. 4
0
        /// <summary>
        /// Returns the cell at an explicit column and row index.<br/>
        /// This takes into consideration that there may be nested elements.
        /// </summary>
        /// <param name="columnIndex"></param>
        /// <param name="rowIndex"></param>
        /// <returns></returns>
        public ExcelMapCoOrdinateCell GetCell(uint columnIndex, uint rowIndex)
        {
            var cellListKey = new System.Drawing.Point((int)columnIndex, (int)rowIndex);

            if (this.cells.ContainsKey(cellListKey))
            {
                ExcelMapCoOrdinate element = this.cells[cellListKey];
            }
            return(null);
        }
Esempio n. 5
0
 /// <summary>
 /// Finds the first keyed element of a specified <see cref="BaseMap"/> derived type which matches a specified key.<br/>
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="key"></param>
 /// <returns></returns>
 internal static T FirstKeyedElementOfType <T>(this ExcelMapCoOrdinate map, string key) where T : BaseMap
 {
     if (map.KeyedElements != null)
     {
         foreach (KeyValuePair <string, BaseMap> kvp in map.KeyedElements.FindAll(kvp => kvp.Key.CompareTo(key) == 0))
         {
             if (kvp.Value is T)
             {
                 return((T)kvp.Value);
             }
         }
     }
     return(null);
 }
Esempio n. 6
0
 /// <summary>
 /// Appends a <see cref="RowOrColumnInfo"/> to the end of this <see cref="RowOrColumnsModel"/>.
 /// </summary>
 /// <param name="map">A <see cref="ExcelMapCoOrdinate"/> which relates to the <see cref="RowOrColumnInfo"/> being added.</param>
 internal void Add(ExcelMapCoOrdinate map)
 {
     if (this.first == null)
     {
         this.first = RowOrColumnInfo.Create(map, this.isRowModel);
         this.last  = this.first;
     }
     else
     {
         RowOrColumnInfo newInfo = RowOrColumnInfo.Create(map, this.isRowModel);
         this.last.Next = newInfo;
         this.last      = newInfo;
     }
 }
        /// <summary>
        /// Update/Insert - Checks if a co-ordinate record exists for the supplied <see cref="System.Drawing.Point"/>.<br/>
        /// If not, creates and adds to this dictionary using the <see cref="System.Drawing.Point"/> as a key,<br/>
        /// then associates adds the <see cref="ExcelMapCoOrdinate"/> with that co-ordinate to an internal list.
        /// </summary>
        /// <param name="idx"></param>
        /// <param name="mapCoOrddinate"></param>
        public void Upsert(System.Drawing.Point coOrdinate, ExcelMapCoOrdinate mapCoOrddinate)
        {
            LayeredCellInfo info;

            if (this.ContainsKey(coOrdinate))
            {
                info = this[coOrdinate];
            }
            else
            {
                info = new LayeredCellInfo();
                this.Add(coOrdinate, info);
            }
            info.LayeredMaps.Add(mapCoOrddinate);
        }
Esempio n. 8
0
        /// <summary>
        /// Finds the first instance of an element of a specified type derived from <see cref="BaseMap"/> in this <see cref="BaseMap"/><br/>
        /// which has a specified key, includint this instance.<br/>
        /// If none found, goes to parent (Ancestor), and tries again, until we either reach the root or find a descendent with the correct type and key.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="excelMap"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        internal static T FirstAncendentKeyedElementOfType <T>(this ExcelMapCoOrdinate excelMap, string key) where T : BaseMap
        {
            // Attempts to find the first keyed element within this map, including descendents
            T item = excelMap.FirstDescendentKeyedElementOfType <T>(key);

            if (item != null)
            {
                return(item);
            }
            else if (excelMap.Parent != null)
            {
                return(excelMap.Parent.FirstAncendentKeyedElementOfType <T>(key));
            }
            return(null);
        }
Esempio n. 9
0
        /// <summary>
        /// Adds a map to this <see cref="RowOrColumnInfo"/>
        /// </summary>
        /// <param name="map">An <see cref="ExcelMapCoOrdinate"/> to be associated with this column</param>
        public void AddMap(ExcelMapCoOrdinate map)
        {
            // Adds map to the column (if not already there)
            this.Maps.AddDistinct(map);

            // Add the column to the map
            if (this.IsRow)
            {
                map.Rows.AddDistinct(this);
            }
            else
            {
                map.Columns.AddDistinct(this);
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Update/Insert - Checks if a column index record exists.<br/>
        /// If not, creates and adds to this dictionary using the index as a key,<br/>
        /// then adds the <see cref="ExcelMapCoOrdinate"/> which is associated with that column to an internal list.
        /// </summary>
        /// <param name="idx">The index of the column (Excel column index)</param>
        /// <param name="mapCoOrddinate">The <see cref="ExcelMapCoOrdinate"/> based entity which is participating in this column</param>
        public void Upsert(uint idx, ExcelMapCoOrdinate mapCoOrddinate)
        {
            LayeredColumnInfo info;

            if (this.ContainsKey(idx))
            {
                info = this[idx];
            }
            else
            {
                info = new LayeredColumnInfo();
                this.Add(idx, info);
            }

            info.Maps.Add(mapCoOrddinate);
        }
Esempio n. 11
0
        /// <summary>
        /// Creates and returns a new instance of the <see cref="RowOrColumnInfo" /> class.
        /// </summary>
        /// <param name="map">The <see cref="ExcelMapCoOrdinate"/> which is the source for this column</param>
        /// <param name="isRow">If true, the <see cref="RowOrColumnInfo" /> created relates a row, otherwise a column.</param>
        /// <returns>A new instance of a <see cref="RowOrColumnInfo"/> class</returns>
        public static RowOrColumnInfo Create(ExcelMapCoOrdinate map, bool isRow)
        {
            var info = new RowOrColumnInfo(isRow);

            if (isRow)
            {
                info.HeightOrWidth = map.AssignedHeight;
                info.Hidden        = map.RowIsHidden;
            }
            else
            {
                info.HeightOrWidth = map.AssignedWidth;
                info.Hidden        = map.ColumnIsHidden;
            }

            info.AddMap(map);

            return(info);
        }
Esempio n. 12
0
        /// <summary>
        /// Adds all the entites that this element holds, plus this element itself,<br/>
        /// to the supplied <see cref="LayeredCellsDictionary">cellsDictionary</see><br/>
        /// for all worksheet row/column index postions that this entity covers.
        /// </summary>
        /// <param name="cellsDictionary">The <see cref="LayeredCellsDictionary"/> to be updated</param>
        internal override void UpdateLayeredCells(ref LayeredCellsDictionary cellsDictionary)
        {
            // Consider each element in maps
            for (uint colIdx = 1; colIdx <= this.mapColumnCount; colIdx++)
            {
                for (uint rowIdx = 1; rowIdx <= this.mapRowCount; rowIdx++)
                {
                    // Use System.Drawing.Point as key as it has a very efficient hashing algorithm
                    var cellListKey = new System.Drawing.Point((int)colIdx, (int)rowIdx);
                    if (this.cells.ContainsKey(cellListKey))
                    {
                        ExcelMapCoOrdinate element = this.cells[cellListKey];
                        element.UpdateLayeredCells(ref cellsDictionary);
                    }
                }
            }

            // Add this as a layer
            base.UpdateLayeredCells(ref cellsDictionary);
        }
Esempio n. 13
0
        /// <summary>
        /// Build and return a list of <see cref="ExcelDefinedNameInfo"/> which represents
        /// worksheet defined names that are present in this container.
        /// </summary>
        /// <param name="definedNameList"></param>
        internal void UpdateDefinedNameList(ref List <ExcelDefinedNameInfo> definedNameList, string sheetName)
        {
            // Update list if this container has a defined name.
            ExcelMapCoOrdinate.UpdateDefinedNameList(this, sheetName, ref definedNameList);

            // Check contained maps.
            foreach (var cell in this.cells)
            {
                if (cell.Value is ExcelMapCoOrdinateCell)
                {
                    // Each cell can have a defined name
                    ExcelMapCoOrdinate.UpdateDefinedNameList(cell.Value, sheetName, ref definedNameList);
                }
                else if (cell.Value is ExcelMapCoOrdinateContainer)
                {
                    // Each container can have a defined name
                    (cell.Value as ExcelMapCoOrdinateContainer).UpdateDefinedNameList(ref definedNameList, sheetName);
                }
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Ctor. Initialises and updates a new instance of a <see cref="ExcelCellStyleInfo"/> with supplied cell information
        /// </summary>
        /// <param name="Row"></param>
        public ExcelCellStyleInfo(ExcelMapCoOrdinate cell)
        {
            if (cell == null)
            {
                throw new ArgumentNullException("cell");
            }

            if (cell is ExcelMapCoOrdinateCell)
            {
                this.ApplyCellStyles(((ExcelMapCoOrdinateCell)cell).Styles);
            }
            if (cell is ExcelMapCoOrdinateContainer)
            {
                if (cell.Styles != null)
                {
                    foreach (var style in cell.Styles)
                    {
                        this.ApplyContainerStyles(((ExcelMapCoOrdinateContainer)cell).Styles);
                    }
                }
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Sets an <see cref="ExelMapCoOrdinate"/> at the current location.
        /// </summary>
        /// <param name="excelMapCoOrdinate"></param>
        internal void SetExcelMapCoOrdinate(ExcelMapCoOrdinate exelMapCoOrdinate)
        {
            if (this.currentRowIndex < 1)
            {
                throw new InvalidOperationException("CurrentRow can not be < 1");
            }
            if (this.currentColumnIndex < 1)
            {
                throw new InvalidOperationException("CurrentColumn can not be < 1");
            }

            var key = new System.Drawing.Point((int)this.currentColumnIndex, (int)this.currentRowIndex);

            if (this.cells.ContainsKey(key))
            {
                this.cells[key] = exelMapCoOrdinate;
            }
            else
            {
                this.cells.Add(key, exelMapCoOrdinate);
            }
            exelMapCoOrdinate.SetParent(this);
        }
Esempio n. 16
0
        /// <summary>
        /// Builds a model of the rows within this entity.
        /// </summary>
        internal override RowOrColumnsModel BuildRowsModel()
        {
            var rowsModel = new RowOrColumnsModel(true);

            // Consider all elements in the container on a column-by-column basis.
            for (uint colIdx = 1; colIdx <= this.mapColumnCount; colIdx++)
            {
                // Create a RowsModel for the column
                var columnRowsModel = new RowOrColumnsModel(true);

                for (uint rowIdx = 1; rowIdx <= this.mapRowCount; rowIdx++)
                {
                    // Use System.Drawing.Point as key as it has a very efficient hashing algorithm
                    var cellListKey = new System.Drawing.Point((int)colIdx, (int)rowIdx);
                    if (this.cells.ContainsKey(cellListKey))
                    {
                        ExcelMapCoOrdinate element          = this.cells[cellListKey];
                        RowOrColumnsModel  elementRowsModel = element.BuildRowsModel();

                        columnRowsModel.AppendModel(elementRowsModel);
                    }
                }

                // Merge the columns model generated for the row with the model for the container.
                rowsModel.MergeModel(columnRowsModel);

                // Add this container into the column (if not already there)
                RowOrColumnInfo rowInfo = rowsModel.First;
                while (rowInfo != null)
                {
                    rowInfo.AddMap(this);
                    rowInfo = rowInfo.Next;
                }
            }

            return(rowsModel);
        }
Esempio n. 17
0
        /// <summary>
        /// Finds the first instance of an element of a specified type derived from <see cref="BaseMap"/> in this <see cref="BaseMap"/><br/>
        /// which has a specified key. This includes this instance.
        /// </summary>
        /// <param name="excelMap">The <see cref="ExcelMapCoOrdinate"/> derived entity to search</param>
        /// <param name="key">The key of the typed item that we require</param>
        /// <typeparam name="T">The type of <see cref="BaseMap"/> that we wish to find the first instance of</typeparam>
        /// <returns>The first instance of type <typeparamref name="T"/> found in the hierarchy, or null if none found.</returns>
        internal static T FirstDescendentKeyedElementOfType <T>(this ExcelMapCoOrdinate excelMap, string key) where T : BaseMap
        {
            // Attempts to find the first keyed element within this map
            T item = excelMap.FirstKeyedElementOfType <T>(key);

            if (item != null)
            {
                return(item);
            }
            else if (excelMap is ExcelMapCoOrdinateContainer)
            {
                var container = excelMap as ExcelMapCoOrdinateContainer;

                foreach (var mapKeyValue in container.Cells)
                {
                    T cellItem = mapKeyValue.Value.FirstDescendentKeyedElementOfType <T>(key);
                    if (cellItem != null)
                    {
                        return(cellItem);
                    }
                }
            }
            return(null);
        }