protected override void ManageTemplateWithoutLinkedTemplates()
        {
            ExcelInterop.Range     firstCell   = currentRenderingTo;
            ExcelInterop.Worksheet worksheetTo = currentRenderingTo.Worksheet;
            int cptElements = 0;

            int nbrOfElement = bindingContextPart.ElementsToRender.Count();
            int localWidth   = partToRenderDefinition.Width * nbrOfElement;
            int localHeight  = partToRenderDefinition.Height;

            if (nbrOfElement > 0)
            {
                ExcelInterop.Range workingRange = currentRenderingTo.Resize[localHeight, localWidth];

                partToRenderDefinition.DefinitionCells.Copy(workingRange);
                currentRenderingTo = worksheetTo.Cells[currentRenderingTo.Row + localHeight, currentRenderingTo.Column + localWidth];

                for (int rowId = 0; rowId < partToRenderDefinition.Height; rowId++)
                {
                    Parent.DataRows.Add(new List <IBindingContextItem>());
                }

                foreach (IBindingContextElement contextElement in bindingContextPart.ElementsToRender)
                {
                    int cptItems = 0;
                    for (int rowId = 0; rowId < partToRenderDefinition.Height; rowId++)
                    {
                        for (int colId = 0; colId < partToRenderDefinition.Width; colId++)
                        {
                            IBindingContextItem item = partToRenderDefinition.DefinitionParts[rowId, colId] == null ? null : contextElement.BindingContextItems[cptItems++];
                            if (item != null && ((item.BindingDefinition != null && item.BindingDefinition.IsEnum && !item.BindingDefinition.IsReadOnly) || item is IExcelControl))
                            {
                                ExcelInterop.Range range = worksheetTo.Cells[firstCell.Row + rowId, firstCell.Column + colId + cptElements * partToRenderDefinition.Width];
                                if (item.BindingDefinition.IsEnum)
                                {
                                    enumManager.CreateControl(item, ref range);
                                }
                                else
                                {
                                    ((IExcelControl)item).CreateControl(range);
                                }
                                range = null;
                            }
                            Parent.DataRows[rowId].Add(item);
                        }
                    }
                    if (useDecorator && ((ExcelTemplateDefinition)this.partToRenderDefinition.Parent).Decorator != null)
                    {
                        ExcelInterop.Range elementRange = firstCell.Offset[0, cptElements];
                        elementRange = elementRange.Resize[localHeight, 1];

                        Parent.RootRenderer.RowDecorators.Add(new ExcelElementDecorator(elementRange, ((ExcelTemplateDefinition)partToRenderDefinition.Parent).Decorator, contextElement));
                    }
                    cptElements++;
                }
                workingRange = null;
                //ExcelApplication.ReleaseComObject(workingRange);
            }

            // To take into account the min number of elements to render.
            if (Parent.MinOccurencesMethod != null)
            {
                IBindingContextElement parentElement = null;
                if (bindingContextPart.ParentContext != null)
                {
                    parentElement = bindingContextPart.ParentContext.Parent;
                }

                int minElementsToRender = LinkedTemplateDefinition.ResolveMinOccurences(Parent.MinOccurencesMethod, parentElement);
                if (minElementsToRender > nbrOfElement)
                {
                    localWidth = partToRenderDefinition.Width * minElementsToRender;
                    IBindingContextItem[] toAdd = new IBindingContextItem[minElementsToRender - nbrOfElement];

                    if (Parent.DataRows.Count == 0)
                    {
                        for (int rowId = 0; rowId < partToRenderDefinition.Height; rowId++)
                        {
                            Parent.DataRows.Add(new List <IBindingContextItem>());
                        }
                    }
                    for (int rowId = 0; rowId < partToRenderDefinition.Height; rowId++)
                    {
                        Parent.DataRows[rowId].AddRange(toAdd);
                    }
                }
            }

            Width += localWidth;
            if (Height < localHeight)
            {
                Height = localHeight;
            }

            ExcelApplication.ReleaseComObject(worksheetTo);
            firstCell = null;
        }
        protected override void ManageTemplateWithoutLinkedTemplates()
        {
            ExcelInterop.Range     firstCell   = currentRenderingTo;
            ExcelInterop.Worksheet worksheetTo = currentRenderingTo.Worksheet;
            int cptElements = 0;

            int nbrOfElement = bindingContextPart.ElementsToRender.Count();
            int localWidth   = partToRenderDefinition.Width;
            int localHeight  = partToRenderDefinition.Height * nbrOfElement;

            if (localHeight > 0)
            {
                ExcelInterop.Range workingRange = currentRenderingTo.Resize[localHeight, localWidth];

                partToRenderDefinition.DefinitionCells.Copy(workingRange);
                currentRenderingTo = worksheetTo.Cells[currentRenderingTo.Row + localHeight, currentRenderingTo.Column + localWidth];

                foreach (IBindingContextElement contextElement in bindingContextPart.ElementsToRender)
                {
                    int cptItems = 0;
                    for (int rowId = 0; rowId < partToRenderDefinition.Height; rowId++)
                    {
                        List <IBindingContextItem> row = new List <IBindingContextItem>();
                        Parent.DataRows.Add(row);
                        for (int colId = 0; colId < partToRenderDefinition.Width; colId++)
                        {
                            IBindingContextItem item = partToRenderDefinition.DefinitionParts[rowId, colId] == null ? null : contextElement.BindingContextItems[cptItems++];
                            if (item != null)
                            {
                                if (item is ExcelBindingSearchContextItem)
                                {
                                    ExcelInterop.Range range = worksheetTo.Cells[firstCell.Row + rowId + cptElements * partToRenderDefinition.Height, firstCell.Column + colId];
                                    ((ExcelBindingSearchContextItem)item).SetRange(ref range);
                                    range = null;
                                }
                                else if (item is IExcelControl)
                                {
                                    ExcelInterop.Range range = worksheetTo.Cells[firstCell.Row + rowId + cptElements * partToRenderDefinition.Height, firstCell.Column + colId];
                                    ((IExcelControl)item).CreateControl(range);
                                    range = null;
                                }
                                else if (item.BindingDefinition != null)
                                {
                                    if (item.BindingDefinition.IsEnum && !item.BindingDefinition.IsReadOnly)
                                    {
                                        ExcelInterop.Range range = worksheetTo.Cells[firstCell.Row + rowId + cptElements * partToRenderDefinition.Height, firstCell.Column + colId];
                                        enumManager.CreateControl(item, ref range);
                                        range = null;
                                    }
                                    if (item.BindingDefinition.OnAfterRendering != null)
                                    {
                                        ExcelInterop.Range range = worksheetTo.Cells[firstCell.Row + rowId + cptElements * partToRenderDefinition.Height, firstCell.Column + colId];
                                        AddAfterRenderingAction(item.BindingDefinition, range);
                                        range = null;
                                    }
                                }
                            }
                            row.Add(item);
                        }
                    }
                    if (useDecorator && ((ExcelTemplateDefinition)partToRenderDefinition.Parent).Decorator != null)
                    {
                        ExcelInterop.Range elementRange = firstCell.Offset[cptElements, 0];
                        elementRange = elementRange.Resize[1, localWidth];

                        Parent.RootRenderer.RowDecorators.Add(new ExcelElementDecorator(elementRange, ((ExcelTemplateDefinition)partToRenderDefinition.Parent).Decorator, contextElement));
                    }
                    cptElements++;
                }
                //ExcelApplication.ReleaseComObject(workingRange);
                workingRange = null;
            }

            // To take into account the min number of elements to render.
            if (Parent.MinOccurencesMethod != null)
            {
                IBindingContextElement parentElement = null;
                if (bindingContextPart.ParentContext != null)
                {
                    parentElement = bindingContextPart.ParentContext.Parent;
                }

                int minElementsToRender = LinkedTemplateDefinition.ResolveMinOccurences(Parent.MinOccurencesMethod, parentElement);
                if (minElementsToRender > nbrOfElement)
                {
                    localHeight = partToRenderDefinition.Height * minElementsToRender;
                }
            }

            Height += localHeight;
            if (Width < localWidth)
            {
                Width = localWidth;
            }

            firstCell = null;
            ExcelApplication.ReleaseComObject(worksheetTo);
            worksheetTo = null;
        }