コード例 #1
0
        protected override void FillCopyProperties(IExcelPanel panel)
        {
            var dataItemPanel = panel as ExcelDataItemPanel;

            dataItemPanel.DataItem = DataItem;
            base.FillCopyProperties(panel);
        }
コード例 #2
0
        private void AllocateSpaceForData(IExcelPanel templatePanel, int dataItemsCount)
        {
            if (ShiftType == ShiftType.NoShift)
            {
                return;
            }

            IXLRange range = templatePanel.Range;

            if (Type == PanelType.Vertical)
            {
                int rowCount = (dataItemsCount - 1) * Range.RowCount();
                if (ShiftType == ShiftType.Row)
                {
                    range.Worksheet.Row(range.LastRow().RowNumber()).InsertRowsBelow(rowCount);
                }
                else
                {
                    range.InsertRowsBelow(rowCount, false);
                }
            }
            else
            {
                int columnCount = (dataItemsCount - 1) * Range.ColumnCount();
                if (ShiftType == ShiftType.Row)
                {
                    range.Worksheet.Column(range.LastColumn().ColumnNumber()).InsertColumnsAfter(columnCount);
                }
                else
                {
                    range.InsertColumnsAfter(columnCount, false);
                }
            }
        }
コード例 #3
0
        private void MoveTemplatePanel(IExcelPanel templatePanel)
        {
            AddressShift shift = Type == PanelType.Vertical
                ? new AddressShift(_templatePanelRowCount, 0)
                : new AddressShift(0, _templatePanelColumnCount);

            templatePanel.Move(ExcelHelper.ShiftCell(templatePanel.Range.FirstCell(), shift));
        }
コード例 #4
0
        protected override void FillCopyProperties(IExcelPanel panel)
        {
            var dataSourcePanel = panel as ExcelDataSourcePanel;

            dataSourcePanel.GroupBy = GroupBy;
            dataSourcePanel.BeforeDataItemRenderMethodName = BeforeDataItemRenderMethodName;
            dataSourcePanel.AfterDataItemRenderMethodName  = AfterDataItemRenderMethodName;

            base.FillCopyProperties(panel);
        }
コード例 #5
0
        public static void RemoveAllNamesRecursive(IExcelPanel panel)
        {
            foreach (IExcelPanel p in panel.Children)
            {
                RemoveAllNamesRecursive(p);
            }

            IExcelNamedPanel namedChild = panel as IExcelNamedPanel;

            namedChild?.RemoveName();
        }
コード例 #6
0
        private IDictionary <string, (IExcelPanel, string)> GetPanelsFlatView(IEnumerable <IXLNamedRange> panelsNamedRanges)
        {
            var panelFactory = new ExcelPanelFactory(Report, TemplateProcessor, PanelParsingSettings);
            IDictionary <string, (IExcelPanel, string)> panels = new Dictionary <string, (IExcelPanel, string)>();

            foreach (IXLNamedRange namedRange in panelsNamedRanges)
            {
                IDictionary <string, string> panelProperties = PanelPropertiesParser.Parse(namedRange.Comment);
                IExcelPanel panel = panelFactory.Create(namedRange, panelProperties);
                panelProperties.TryGetValue("ParentPanel", out string parentPanelName);
                panels[namedRange.Name] = (panel, parentPanelName);
            }
            return(panels);
        }
コード例 #7
0
        protected IExcelNamedPanel GetNearestNamedParent()
        {
            IExcelPanel parent = Parent;

            while (parent != null)
            {
                if (parent is IExcelNamedPanel namedParent)
                {
                    return(namedParent);
                }
                parent = parent.Parent;
            }
            return(null);
        }
コード例 #8
0
        private void FillPanelProperties(IExcelPanel panel)
        {
            if (!_properties.Any())
            {
                return;
            }

            PropertyInfo[] externalProperties = panel.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public)
                                                .Where(p => p.IsDefined(typeof(ExternalPropertyAttribute), true)).ToArray();
            foreach (KeyValuePair <string, string> prop in _properties)
            {
                PropertyInfo externalProp = externalProperties.SingleOrDefault(p => p.Name == prop.Key);
                if (externalProp != null)
                {
                    var externalPropAttr = Extensions.CustomAttributeExtensions.GetCustomAttribute <ExternalPropertyAttribute>(externalProp);
                    externalProp.SetValue(panel, ConvertProperty(prop.Value, externalPropAttr.Converter), null);
                }
            }
        }
コード例 #9
0
        protected override void FillCopyProperties(IExcelPanel panel)
        {
            var dataSourceDynamicPanel = panel as ExcelDataSourceDynamicPanel;

            dataSourceDynamicPanel.BeforeHeadersRenderMethodName         = BeforeHeadersRenderMethodName;
            dataSourceDynamicPanel.AfterHeadersRenderMethodName          = AfterHeadersRenderMethodName;
            dataSourceDynamicPanel.BeforeNumbersRenderMethodName         = BeforeNumbersRenderMethodName;
            dataSourceDynamicPanel.AfterNumbersRenderMethodName          = AfterNumbersRenderMethodName;
            dataSourceDynamicPanel.BeforeDataTemplatesRenderMethodName   = BeforeDataTemplatesRenderMethodName;
            dataSourceDynamicPanel.AfterDataTemplatesRenderMethodName    = AfterDataTemplatesRenderMethodName;
            dataSourceDynamicPanel.BeforeDataRenderMethodName            = BeforeDataRenderMethodName;
            dataSourceDynamicPanel.AfterDataRenderMethodName             = AfterDataRenderMethodName;
            dataSourceDynamicPanel.BeforeTotalsTemplatesRenderMethodName = BeforeTotalsTemplatesRenderMethodName;
            dataSourceDynamicPanel.AfterTotalsTemplatesRenderMethodName  = AfterTotalsTemplatesRenderMethodName;
            dataSourceDynamicPanel.BeforeTotalsRenderMethodName          = BeforeTotalsRenderMethodName;
            dataSourceDynamicPanel.AfterTotalsRenderMethodName           = AfterTotalsRenderMethodName;

            base.FillCopyProperties(panel);
        }
コード例 #10
0
        private void SetResultRange(IExcelPanel panel, IXLRange range)
        {
            PropertyInfo prop = panel.GetType().GetProperty(nameof(IExcelPanel.ResultRange));

            prop.SetValue(panel, range);
        }
コード例 #11
0
 protected void DeletePanel(IExcelPanel panel)
 {
     RemoveAllNamesRecursive(panel);
     panel.Delete();
 }
コード例 #12
0
 protected override IExcelPanel CopyChild(IExcelPanel fromChild, IXLCell cell)
 {
     return(fromChild is IExcelNamedPanel namedChild?namedChild.Copy(cell, $"{_copiedPanelName}_{namedChild.Name}") : fromChild.Copy(cell));
 }
コード例 #13
0
        public void TestCopy()
        {
            XLWorkbook   wb                = new XLWorkbook();
            IXLWorksheet ws                = wb.AddWorksheet("Test");
            var          excelReport       = Substitute.For <object>();
            var          templateProcessor = Substitute.For <ITemplateProcessor>();

            IXLRange range             = ws.Range(1, 1, 3, 4);
            IXLRange childRange        = ws.Range(2, 1, 3, 4);
            IXLRange childOfChildRange = ws.Range(3, 1, 3, 4);

            var panel = new ExcelPanel(range, excelReport, templateProcessor)
            {
                BeforeRenderMethodName = "BeforeMethod",
                AfterRenderMethodName  = "AfterRender",
                Type           = PanelType.Horizontal,
                ShiftType      = ShiftType.Row,
                RenderPriority = 1,
                Children       = new List <IExcelPanel>
                {
                    new ExcelPanel(childRange, excelReport, templateProcessor)
                    {
                        BeforeRenderMethodName = "BeforeMethod_child",
                        AfterRenderMethodName  = "AfterRender_child",
                        Type           = PanelType.Vertical,
                        ShiftType      = ShiftType.NoShift,
                        RenderPriority = 2,
                        Children       = new List <IExcelPanel>
                        {
                            new ExcelPanel(childOfChildRange, excelReport, templateProcessor)
                            {
                                BeforeRenderMethodName = "BeforeMethod_child_child",
                                AfterRenderMethodName  = "AfterRender_child_child",
                                Type           = PanelType.Horizontal,
                                ShiftType      = ShiftType.Row,
                                RenderPriority = 3,
                            }
                        }
                    }
                }
            };

            IExcelPanel copiedPanel = panel.Copy(ws.Cell(5, 5));

            Assert.AreSame(excelReport, copiedPanel.GetType().GetField("_report", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(copiedPanel));
            Assert.AreSame(templateProcessor, copiedPanel.GetType().GetField("_templateProcessor", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(copiedPanel));
            Assert.AreEqual(ws.Cell(5, 5), copiedPanel.Range.FirstCell());
            Assert.AreEqual(ws.Cell(7, 8), copiedPanel.Range.LastCell());
            Assert.IsNull(copiedPanel.Parent);
            Assert.AreEqual(panel.BeforeRenderMethodName, copiedPanel.BeforeRenderMethodName);
            Assert.AreEqual(panel.AfterRenderMethodName, copiedPanel.AfterRenderMethodName);
            Assert.AreEqual(panel.Type, copiedPanel.Type);
            Assert.AreEqual(panel.ShiftType, copiedPanel.ShiftType);
            Assert.AreEqual(panel.RenderPriority, copiedPanel.RenderPriority);

            Assert.AreEqual(1, copiedPanel.Children.Count());
            Assert.AreSame(excelReport, copiedPanel.Children.First().GetType().GetField("_report", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(copiedPanel.Children.First()));
            Assert.AreSame(templateProcessor, copiedPanel.GetType().GetField("_templateProcessor", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(copiedPanel.Children.First()));
            Assert.AreEqual(ws.Cell(6, 5), copiedPanel.Children.First().Range.FirstCell());
            Assert.AreEqual(ws.Cell(7, 8), copiedPanel.Children.First().Range.LastCell());
            Assert.AreSame(copiedPanel, copiedPanel.Children.First().Parent);
            Assert.AreEqual(panel.Children.First().BeforeRenderMethodName, copiedPanel.Children.First().BeforeRenderMethodName);
            Assert.AreEqual(panel.Children.First().AfterRenderMethodName, copiedPanel.Children.First().AfterRenderMethodName);
            Assert.AreEqual(panel.Children.First().Type, copiedPanel.Children.First().Type);
            Assert.AreEqual(panel.Children.First().ShiftType, copiedPanel.Children.First().ShiftType);
            Assert.AreEqual(panel.Children.First().RenderPriority, copiedPanel.Children.First().RenderPriority);

            Assert.AreEqual(1, copiedPanel.Children.First().Children.Count());
            Assert.AreSame(excelReport, copiedPanel.Children.First().Children.First().GetType().GetField("_report", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(copiedPanel.Children.First().Children.First()));
            Assert.AreSame(templateProcessor, copiedPanel.Children.First().Children.First().GetType().GetField("_templateProcessor", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(copiedPanel.Children.First().Children.First()));
            Assert.AreEqual(ws.Cell(7, 5), copiedPanel.Children.First().Children.First().Range.FirstCell());
            Assert.AreEqual(ws.Cell(7, 8), copiedPanel.Children.First().Children.First().Range.LastCell());
            Assert.AreSame(copiedPanel.Children.First(), copiedPanel.Children.First().Children.First().Parent);
            Assert.AreEqual(panel.Children.First().Children.First().BeforeRenderMethodName, copiedPanel.Children.First().Children.First().BeforeRenderMethodName);
            Assert.AreEqual(panel.Children.First().Children.First().AfterRenderMethodName, copiedPanel.Children.First().Children.First().AfterRenderMethodName);
            Assert.AreEqual(panel.Children.First().Children.First().Type, copiedPanel.Children.First().Children.First().Type);
            Assert.AreEqual(panel.Children.First().Children.First().ShiftType, copiedPanel.Children.First().Children.First().ShiftType);
            Assert.AreEqual(panel.Children.First().Children.First().RenderPriority, copiedPanel.Children.First().Children.First().RenderPriority);

            IExcelPanel globalParent = new ExcelPanel(ws.Range(1, 1, 20, 20), excelReport, templateProcessor);

            range = ws.Range(1, 1, 3, 4);
            IXLRange childRange1 = ws.Range(1, 1, 1, 4);
            IXLRange childRange2 = ws.Range(2, 1, 3, 4);

            childOfChildRange = ws.Range(3, 1, 3, 4);

            panel = new ExcelPanel(range, excelReport, templateProcessor)
            {
                Parent   = globalParent,
                Children = new List <IExcelPanel>
                {
                    new ExcelPanel(childRange1, excelReport, templateProcessor),
                    new ExcelPanel(childRange2, excelReport, templateProcessor)
                    {
                        Children = new List <IExcelPanel>
                        {
                            new ExcelPanel(childOfChildRange, excelReport, templateProcessor)
                        }
                    },
                },
            };

            copiedPanel = panel.Copy(ws.Cell(5, 5));
            Assert.AreEqual(ws.Cell(5, 5), copiedPanel.Range.FirstCell());
            Assert.AreEqual(ws.Cell(7, 8), copiedPanel.Range.LastCell());
            Assert.AreSame(globalParent, copiedPanel.Parent);

            Assert.AreEqual(2, copiedPanel.Children.Count());
            Assert.AreEqual(ws.Cell(5, 5), copiedPanel.Children.First().Range.FirstCell());
            Assert.AreEqual(ws.Cell(5, 8), copiedPanel.Children.First().Range.LastCell());
            Assert.AreSame(copiedPanel, copiedPanel.Children.First().Parent);
            Assert.AreEqual(ws.Cell(6, 5), copiedPanel.Children.Last().Range.FirstCell());
            Assert.AreEqual(ws.Cell(7, 8), copiedPanel.Children.Last().Range.LastCell());
            Assert.AreSame(copiedPanel, copiedPanel.Children.Last().Parent);

            Assert.AreEqual(1, copiedPanel.Children.Last().Children.Count());
            Assert.AreEqual(ws.Cell(7, 5), copiedPanel.Children.Last().Children.First().Range.FirstCell());
            Assert.AreEqual(ws.Cell(7, 8), copiedPanel.Children.Last().Children.First().Range.LastCell());
            Assert.AreSame(copiedPanel.Children.Last(), copiedPanel.Children.Last().Children.First().Parent);

            globalParent = new ExcelPanel(ws.Range(1, 1, 7, 7), excelReport, templateProcessor);
            range        = ws.Range(1, 1, 3, 4);
            childRange1  = ws.Range(1, 1, 1, 4);
            panel        = new ExcelPanel(range, excelReport, templateProcessor)
            {
                Parent   = globalParent,
                Children = new List <IExcelPanel> {
                    new ExcelPanel(childRange1, excelReport, templateProcessor)
                },
            };

            copiedPanel = panel.Copy(ws.Cell(5, 5));
            Assert.AreEqual(ws.Cell(5, 5), copiedPanel.Range.FirstCell());
            Assert.AreEqual(ws.Cell(7, 8), copiedPanel.Range.LastCell());
            Assert.IsNull(copiedPanel.Parent);

            Assert.AreEqual(1, copiedPanel.Children.Count());
            Assert.AreEqual(ws.Cell(5, 5), copiedPanel.Children.First().Range.FirstCell());
            Assert.AreEqual(ws.Cell(5, 8), copiedPanel.Children.First().Range.LastCell());
            Assert.AreSame(copiedPanel, copiedPanel.Children.First().Parent);

            globalParent = new ExcelPanel(ws.Range(1, 1, 7, 8), excelReport, templateProcessor);
            panel.Parent = globalParent;
            copiedPanel  = panel.Copy(ws.Cell(5, 5), false);
            Assert.AreEqual(ws.Cell(5, 5), copiedPanel.Range.FirstCell());
            Assert.AreEqual(ws.Cell(7, 8), copiedPanel.Range.LastCell());
            Assert.AreSame(globalParent, copiedPanel.Parent);
            Assert.AreEqual(0, copiedPanel.Children.Count());

            //wb.SaveAs("test.xlsx");
        }