protected virtual void ClearRenderingData() { if (HeaderPartRenderer != null) { HeaderPartRenderer.Dispose(); HeaderPartRenderer = null; } if (BodyPartRenderer != null) { BodyPartRenderer.Dispose(); BodyPartRenderer = null; } if (FooterPartRenderer != null) { FooterPartRenderer.Dispose(); FooterPartRenderer = null; } foreach (ExcelRenderer nestedRenderer in NestedRenderer) { nestedRenderer.ClearRenderingData(); } NestedRenderer.Clear(); DataRows.Clear(); RenderedRange = null; contextItems = null; cells = null; }
public virtual void Render() { int[] xs = new int[3]; int[] ys = new int[3]; ExcelInterop.Range nextFirstOutputCell = null; if (templateDefinition.Header != null) { HeaderPartRenderer = ExcelPartRenderer.CreateInstance(this, (ExcelTemplateDefinitionPart)templateDefinition.Header, bindingContext.Header, firstOutputCell, false); HeaderPartRenderer.Render(); if (HeaderPartRenderer.RenderedArea != null && HeaderPartRenderer.RenderedArea.Width != 0) { xs[0] = HeaderPartRenderer.RenderedArea.Width; ys[0] = HeaderPartRenderer.RenderedArea.Height; int xOffset = templateDefinition.Orientation == Orientation.Horizontal ? xs[0] : 0; int yOffset = templateDefinition.Orientation == Orientation.Horizontal ? 0 : ys[0]; nextFirstOutputCell = firstOutputCell.Offset[yOffset, xOffset]; } } if (templateDefinition.Body != null) { BodyPartRenderer = ExcelPartRenderer.CreateInstance(this, (ExcelTemplateDefinitionPart)templateDefinition.Body, bindingContext.Body, nextFirstOutputCell ?? firstOutputCell, true); BodyPartRenderer.Render(); if (BodyPartRenderer.RenderedArea != null && BodyPartRenderer.RenderedArea.Width != 0) { xs[1] = BodyPartRenderer.RenderedArea.Width; ys[1] = BodyPartRenderer.RenderedArea.Height; int xOffset = templateDefinition.Orientation == Orientation.Horizontal ? xs[1] : 0; int yOffset = templateDefinition.Orientation == Orientation.Horizontal ? 0 : ys[1]; nextFirstOutputCell = (nextFirstOutputCell ?? firstOutputCell).Offset[yOffset, xOffset]; } } if (templateDefinition.Footer != null) { FooterPartRenderer = ExcelPartRenderer.CreateInstance(this, (ExcelTemplateDefinitionPart)templateDefinition.Footer, bindingContext.Footer, nextFirstOutputCell ?? firstOutputCell, false); FooterPartRenderer.Render(); if (FooterPartRenderer.RenderedArea != null && FooterPartRenderer.RenderedArea.Width != 0) { xs[2] = FooterPartRenderer.RenderedArea.Width; ys[2] = FooterPartRenderer.RenderedArea.Height; } } int width = templateDefinition.Orientation == Orientation.Vertical ? xs.Max() : xs.Sum(); int height = templateDefinition.Orientation == Orientation.Vertical ? ys.Sum() : ys.Max(); if (width > 0 && height > 0) { RenderedArea = new RenderedArea(firstOutputCell.Column, firstOutputCell.Row, width, height); RenderedRange = firstOutputCell.Resize[height, width]; Width = width; Height = height; } }