Ejemplo n.º 1
0
        public void Can_Render_DateTime()
        {
            var token  = Parser.Parse(@"{""created_at"": ""2016-09-13T20:40:41Z""}");
            var result = ExcelRenderer.Render(token["created_at"], "http://api.test.com/numbers", true);

            Assert.AreEqual(new DateTime(2016, 9, 13, 20, 40, 41), result);
        }
Ejemplo n.º 2
0
        public void Can_Render_Simple_Array_of_Arrays()
        {
            var token  = Parser.Parse(@"[[1,2,3],[4,5,6]]");
            var result = ExcelRenderer.Render(token, "http://api.test.com/numbers", true);

            Assert.AreEqual(new object[, ] {
                { 1, 2, 3 }, { 4, 5, 6 }
            }, result);
        }
Ejemplo n.º 3
0
        public void Can_Render_Array_With_Object()
        {
            var token  = Parser.Parse(@"[1,2, {""a"": 5}]");
            var result = ExcelRenderer.Render(token, "http://api.test.com/numbers", true);

            Assert.AreEqual(new object[, ] {
                { 1 }, { 2 }, { "http://api.test.com/numbers#2" }
            }, result);
        }
Ejemplo n.º 4
0
        public void Can_Render_Simple_Array()
        {
            var token  = Parser.Parse(@"[1,2,3,4,5,6]");
            var result = ExcelRenderer.Render(token, "http://api.test.com/numbers", true);

            Assert.AreEqual(new object[, ] {
                { 1 }, { 2 }, { 3 }, { 4 }, { 5 }, { 6 }
            }, result);
        }
Ejemplo n.º 5
0
        public byte[] ToExcel()
        {
            IRenderer renderer = new ExcelRenderer();

            return(renderer.Render(_report));
        }
        private ActionResult Execute(string key, string opt, string ext, bool download, bool printing)
        {
            if (key.IsEmptyOrNull())
            {
                throw new ArgumentNullException(nameof(key));
            }

            var reportInfo = ReportRegistry.GetReport(key);

            if (reportInfo == null)
            {
                throw new ArgumentOutOfRangeException(nameof(key));
            }

            if (reportInfo.Permission != null)
            {
                Context.Permissions.ValidatePermission(reportInfo.Permission, Context.Localizer);
            }

            var report = ActivatorUtilities.CreateInstance(HttpContext.RequestServices, reportInfo.Type) as IReport;
            var json   = opt.TrimToNull();

            if (json != null)
            {
                JsonConvert.PopulateObject(json, report);
            }

            byte[] renderedBytes = null;

            if (report is IDataOnlyReport dataOnlyReport)
            {
                ext           = "xlsx";
                renderedBytes = ExcelRenderer.Render(dataOnlyReport);
            }
            else if (report is IExternalReport)
            {
                var url = report.GetData() as string;
                if (string.IsNullOrEmpty(url))
                {
                    throw new InvalidProgramException("External reports must return a URL string from GetData() method!");
                }

                return(new RedirectResult(url));
            }
            else
            {
                ext = (ext ?? "html").ToLowerInvariant();

                if (ext == "htm" || ext == "html")
                {
                    var result = RenderAsHtml(report, download, printing, ref renderedBytes);
                    if (!download)
                    {
                        return(result);
                    }
                }
                else if (ext == "pdf")
                {
                    renderedBytes = RenderAsPdf(report, key, opt);
                }
                else
                {
                    throw new ArgumentOutOfRangeException(nameof(ext));
                }
            }

            return(PrepareFileResult(report, ext, download, renderedBytes, reportInfo));
        }