public void TestColumnsSwitching()
        {
            using (var templateDocument = ExcelDocumentFactory.CreateFromTemplate(File.ReadAllBytes(GetFilePath("columnsSwitching.xlsx")), logger))
                using (var targetDocument = ExcelDocumentFactory.CreateFromTemplate(File.ReadAllBytes(GetFilePath("empty.xlsx")), logger))
                {
                    var template       = new ExcelTable(templateDocument.GetWorksheet(0));
                    var templateEngine = new SkbKontur.Excel.TemplateEngine.TemplateEngine(template, logger);

                    var target         = new ExcelTable(targetDocument.GetWorksheet(0));
                    var tableNavigator = new TableNavigator(new CellPosition("A1"), logger);
                    var tableBuilder   = new TableBuilder(target, tableNavigator, new Style(template.GetCell(new CellPosition("A1"))));
                    templateEngine.Render(tableBuilder, new { A = "First", B = true, C = "Third", D = new[] { 1, 2, 3 }, E = "Fifth" });

                    var filename = "output.xlsx";
                    File.WriteAllBytes(filename, targetDocument.CloseAndGetDocumentBytes());

                    var path = "file:///" + Path.GetFullPath(filename).Replace("\\", "/");
                    Assert.Fail($"Please manually open file '{path}' and check values:\n" +
                                string.Join("\n", new[]
                    {
                        "C5: First",
                        "D5: <empty>",
                        "E5: Third",
                        "F5: 1",
                        "F6: 2",
                        "F7: 3",
                        "G5: Fifth",
                        "Флажок 1: checked",
                    }) + "\n");
                }
        }
示例#2
0
        public void MultipleObjectsPrintingTest()
        {
            var model = new Document
            {
                Buyer = new Organization
                {
                    Address = "BuyerAddress",
                    Name    = "BuyerName"
                },
                Supplier = new Organization
                {
                    Address = "SupplierAddress",
                    Name    = "SupplierName",
                    Inn     = 90238192,
                    Kpp     = "0832309812"
                },
                Payer = new Organization
                {
                    Address = "PayerAddress",
                    Name    = "PayerAddress"
                },
                DeliveryParty = new Organization
                {
                    Address = "DeliveryPartyAddress",
                    Name    = "DeliveryPartyName"
                },
                Vehicle = new VehicleInfo
                {
                    NameOfCarrier = "Евкакий",
                    TransportMode = "Agressive",
                    VehicleBrand  = "Tauria",
                    VehicleNumber = "A777AB"
                },
                TypeName = "ORDERS"
            };

            var templateDocument = ExcelDocumentFactory.CreateFromTemplate(File.ReadAllBytes(GetFilePath("complexTemplate.xlsx")), logger);
            var template         = new ExcelTable(templateDocument.GetWorksheet(0));
            var templateEngine   = new SkbKontur.Excel.TemplateEngine.TemplateEngine(template, logger);

            var targetDocument = ExcelDocumentFactory.CreateFromTemplate(File.ReadAllBytes(GetFilePath("empty.xlsx")), logger);

            targetDocument.AddWorksheet("Лист2");

            var target       = new ExcelTable(targetDocument.GetWorksheet(0));
            var tableBuilder = new TableBuilder(target, new TableNavigator(new CellPosition("B2"), logger), new Style(template.GetCell(new CellPosition("A1"))));

            templateEngine.Render(tableBuilder, model);

            target       = new ExcelTable(targetDocument.GetWorksheet(1));
            tableBuilder = new TableBuilder(target, new TableNavigator(new CellPosition("A1"), logger), new Style(template.GetCell(new CellPosition("A1"))));
            templateEngine.Render(tableBuilder, model);

            var result = targetDocument.CloseAndGetDocumentBytes();

            File.WriteAllBytes("output.xlsx", result);

            templateDocument.Dispose();
            targetDocument.Dispose();
        }
        public void WithNullArrayTest()
        {
            var model = new DocumentWithArray
            {
                Array    = null,
                NonArray = "StringValue"
            };
            var stringTemplate = new[]
            {
                new[] { "", "Template:RootTemplate:A2:D4", "", "" },
                new[] { "", "Адреса:", "Имена:", "" },
                new[] { "", "Value::Array[].Address", "Value::Array[].Name", "" },
                new[] { "Value::NonArray", "", "", "" }
            };

            var template = FakeTable.GenerateFromStringArray(stringTemplate);

            var target         = new FakeTable(100, 100);
            var tableBuilder   = new TableBuilder(target, new TableNavigator(new CellPosition("B2"), logger));
            var templateEngine = new SkbKontur.Excel.TemplateEngine.TemplateEngine(template, logger);

            templateEngine.Render(tableBuilder, model);

            target.GetCell(new CellPosition("C2")).StringValue.Should().Be("Адреса:");
            target.GetCell(new CellPosition("D2")).StringValue.Should().Be("Имена:");
            target.GetCell(new CellPosition("C3")).StringValue.Should().BeEmpty();
            target.GetCell(new CellPosition("D3")).StringValue.Should().BeEmpty();
            target.GetCell(new CellPosition("B4")).StringValue.Should().Be("StringValue");

            DebugPrinting(target, new CellPosition(1, 1), new CellPosition(20, 20));
        }
        public void SimpleTestWithArray()
        {
            var model = new[] { "a", "b", "c", "d", "e" };

            var template = new FakeTable(1, 1);
            var cell     = template.InsertCell(new CellPosition(1, 1));

            cell.StringValue = "Template:RootTemplate:A1:A1";

            var templateEngine = new SkbKontur.Excel.TemplateEngine.TemplateEngine(template, logger);

            var target       = new FakeTable(10, 10);
            var tableBuilder = new TableBuilder(target, new TableNavigator(new CellPosition("B2"), logger), new Style(new FakeCell(new CellPosition("A1"))
            {
                StyleId = "(1,1)"
            }));

            templateEngine.Render(tableBuilder, model);

            target.GetCell(new CellPosition("B2")).StringValue.Should().Be("a");
            target.GetCell(new CellPosition("B3")).StringValue.Should().Be("b");
            target.GetCell(new CellPosition("B4")).StringValue.Should().Be("c");
            target.GetCell(new CellPosition("B5")).StringValue.Should().Be("d");
            target.GetCell(new CellPosition("B6")).StringValue.Should().Be("e");

            DebugPrinting(target, new CellPosition(1, 1), new CellPosition(10, 10));
        }
示例#5
0
        public void FormControlsPrintingTest()
        {
            var model = new
            {
                BoolValue1 = false,
                BoolValue2 = true,
                String1    = "Value1",
                Dict       = new Dictionary <string, bool> {
                    { "TestKey", false }
                },
            };

            var templateDocument = ExcelDocumentFactory.CreateFromTemplate(File.ReadAllBytes(GetFilePath("formControlsTemplate.xlsx")), logger);
            var template         = new ExcelTable(templateDocument.GetWorksheet(0));
            var templateEngine   = new SkbKontur.Excel.TemplateEngine.TemplateEngine(template, logger);

            var targetDocument = ExcelDocumentFactory.CreateFromTemplate(File.ReadAllBytes(GetFilePath("empty.xlsx")), logger);

            var target       = new ExcelTable(targetDocument.GetWorksheet(0));
            var tableBuilder = new TableBuilder(target, new TableNavigator(new CellPosition("A1"), logger), new Style(template.GetCell(new CellPosition("A1"))));

            templateEngine.Render(tableBuilder, model);

            var result = targetDocument.CloseAndGetDocumentBytes();

            File.WriteAllBytes("output.xlsx", result);

            templateDocument.Dispose();
            targetDocument.Dispose();
        }
示例#6
0
        public void TestImportAfterCreate(string extension)
        {
            byte[] bytes;

            using (var templateDocument = ExcelDocumentFactory.CreateFromTemplate(File.ReadAllBytes(GetFilePath("importAfterCreate_template.xlsx")), logger))
                using (var targetDocument = ExcelDocumentFactory.CreateFromTemplate(File.ReadAllBytes(GetFilePath($"empty.{extension}")), logger))
                {
                    var template       = new ExcelTable(templateDocument.GetWorksheet(0));
                    var templateEngine = new SkbKontur.Excel.TemplateEngine.TemplateEngine(template, logger);

                    var target         = new ExcelTable(targetDocument.GetWorksheet(0));
                    var tableNavigator = new TableNavigator(new CellPosition("A1"), logger);
                    var tableBuilder   = new TableBuilder(target, tableNavigator, new Style(template.GetCell(new CellPosition("A1"))));

                    templateEngine.Render(tableBuilder, new { Type = "Значение 2", TestFlag1 = false, TestFlag2 = true });

                    target.InsertCell(new CellPosition("C16"));

                    bytes = targetDocument.CloseAndGetDocumentBytes();
                }

            var(model, mappingForErrors) = Parse <PriceList>(File.ReadAllBytes(GetFilePath("importAfterCreate_template.xlsx")), bytes);
            mappingForErrors["TestFlag1"].Should().Be("CheckBoxName1");
            mappingForErrors["TestFlag2"].Should().Be("CheckBoxName2");
            mappingForErrors["Type"].Should().Be("C3");
            model.TestFlag1.Should().BeFalse();
            model.TestFlag2.Should().BeTrue();
            model.Type.Should().Be("Значение 2");
        }
        public void TestPrintingDropDownFromTheOtherWorksheet()
        {
            using (var templateDocument = ExcelDocumentFactory.CreateFromTemplate(File.ReadAllBytes(GetFilePath("printingDropDownFromTheOtherWorksheet.xlsx")), logger))
                using (var targetDocument = ExcelDocumentFactory.CreateFromTemplate(File.ReadAllBytes(GetFilePath("empty.xlsx")), logger))
                {
                    targetDocument.CopyVbaInfoFrom(templateDocument);

                    foreach (var index in Enumerable.Range(1, templateDocument.GetWorksheetCount() - 1))
                    {
                        var worksheet           = templateDocument.GetWorksheet(index);
                        var name                = templateDocument.GetWorksheetName(index);
                        var innerTemplateEngine = new SkbKontur.Excel.TemplateEngine.TemplateEngine(new ExcelTable(worksheet), logger);
                        var targetWorksheet     = targetDocument.AddWorksheet(name);
                        var innerTableBuilder   = new TableBuilder(new ExcelTable(targetWorksheet), new TableNavigator(new CellPosition("A1"), logger));
                        innerTemplateEngine.Render(innerTableBuilder, new {});
                    }

                    var template       = new ExcelTable(templateDocument.GetWorksheet(0));
                    var templateEngine = new SkbKontur.Excel.TemplateEngine.TemplateEngine(template, logger);

                    var target         = new ExcelTable(targetDocument.GetWorksheet(0));
                    var tableNavigator = new TableNavigator(new CellPosition("A1"), logger);
                    var tableBuilder   = new TableBuilder(target, tableNavigator, new Style(template.GetCell(new CellPosition("A1"))));
                    templateEngine.Render(tableBuilder, new { Type = "Значение 2" });

                    var filename = "output.xlsx";
                    File.WriteAllBytes(filename, targetDocument.CloseAndGetDocumentBytes());

                    var path = "file:///" + Path.GetFullPath(filename).Replace("\\", "/");
                    Assert.Fail($"Please manually open file '{path}' and check that dropdown on the first sheet has value 'Значение 2'");
                }
        }
        public void TestDataValidationsFromTheOtherWorksheet()
        {
            using (var templateDocument = ExcelDocumentFactory.CreateFromTemplate(File.ReadAllBytes(GetFilePath("otherSheetDataValidations.xlsx")), logger))
                using (var targetDocument = ExcelDocumentFactory.CreateFromTemplate(File.ReadAllBytes(GetFilePath("empty.xlsx")), logger))
                {
                    targetDocument.CopyVbaInfoFrom(templateDocument);

                    foreach (var index in Enumerable.Range(1, templateDocument.GetWorksheetCount() - 1))
                    {
                        var worksheet           = templateDocument.GetWorksheet(index);
                        var name                = templateDocument.GetWorksheetName(index);
                        var innerTemplateEngine = new SkbKontur.Excel.TemplateEngine.TemplateEngine(new ExcelTable(worksheet), logger);
                        var targetWorksheet     = targetDocument.AddWorksheet(name);
                        var innerTableBuilder   = new TableBuilder(new ExcelTable(targetWorksheet), new TableNavigator(new CellPosition("A1"), logger));
                        innerTemplateEngine.Render(innerTableBuilder, new {});
                    }

                    var template       = new ExcelTable(templateDocument.GetWorksheet(0));
                    var templateEngine = new SkbKontur.Excel.TemplateEngine.TemplateEngine(template, logger);

                    var target         = new ExcelTable(targetDocument.GetWorksheet(0));
                    var tableNavigator = new TableNavigator(new CellPosition("A1"), logger);
                    var tableBuilder   = new TableBuilder(target, tableNavigator, new Style(template.GetCell(new CellPosition("A1"))));
                    templateEngine.Render(tableBuilder, new {});

                    var filename = "output.xlsx";
                    File.WriteAllBytes(filename, targetDocument.CloseAndGetDocumentBytes());

                    var path = "file:///" + Path.GetFullPath(filename).Replace("\\", "/");
                    Assert.Fail($"Please manually open file '{path}' and check that D4-D7 has data validation with values from the second worksheet and G4-G7 has data validation with values from K1:K6");
                }
        }
        public void ObjectWithArrayPrintingTest()
        {
            var model = new DocumentWithArray
            {
                Array = new[]
                {
                    new Organization
                    {
                        Address = "Address1",
                        Name    = "Name1"
                    },
                    new Organization
                    {
                        Address = "Address2",
                        Name    = "Name2"
                    },
                    new Organization
                    {
                        Address = "Address3",
                        Name    = "Name3"
                    },
                    new Organization
                    {
                        Address = "Address4",
                        Name    = "Name4"
                    }
                },
                NonArray = "StringValue"
            };
            var stringTemplate = new[]
            {
                new[] { "", "Template:RootTemplate:A2:D4", "", "" },
                new[] { "", "Адреса:", "Имена:", "" },
                new[] { "", "Value::Array[].Address", "Value::Array[].Name", "" },
                new[] { "Value::NonArray", "", "", "" }
            };

            var template = FakeTable.GenerateFromStringArray(stringTemplate);

            var target         = new FakeTable(100, 100);
            var tableBuilder   = new TableBuilder(target, new TableNavigator(new CellPosition("B2"), logger));
            var templateEngine = new SkbKontur.Excel.TemplateEngine.TemplateEngine(template, logger);

            templateEngine.Render(tableBuilder, model);

            target.GetCell(new CellPosition("C2")).StringValue.Should().Be("Адреса:");
            target.GetCell(new CellPosition("D2")).StringValue.Should().Be("Имена:");
            target.GetCell(new CellPosition("C3")).StringValue.Should().Be("Address1");
            target.GetCell(new CellPosition("C4")).StringValue.Should().Be("Address2");
            target.GetCell(new CellPosition("C5")).StringValue.Should().Be("Address3");
            target.GetCell(new CellPosition("C6")).StringValue.Should().Be("Address4");
            target.GetCell(new CellPosition("D3")).StringValue.Should().Be("Name1");
            target.GetCell(new CellPosition("D4")).StringValue.Should().Be("Name2");
            target.GetCell(new CellPosition("D5")).StringValue.Should().Be("Name3");
            target.GetCell(new CellPosition("D6")).StringValue.Should().Be("Name4");
            target.GetCell(new CellPosition("B7")).StringValue.Should().Be("StringValue");

            DebugPrinting(target, new CellPosition(1, 1), new CellPosition(20, 20));
        }
        public void SimpleObjectPrintingTest()
        {
            var model = new Document
            {
                Buyer = new Organization
                {
                    Address = "BuyerAddress",
                    Name    = "BuyerName"
                },
                Supplier = new Organization
                {
                    Address = "SupplierAddress",
                    Name    = "SupplierName"
                },
                TypeName = "ORDERS"
            };

            var stringTemplate = new[]
            {
                new[] { "", "", "", "", "" },
                new[] { "", "", "", "", "" },
                new[] { "", "Template:RootTemplate:B4:D5", "", "", "" },
                new[] { "", "Покупатель:", "Поставщик:", "", "" },
                new[] { "", "Value:Organization:Buyer", "Value:Organization:Supplier", "Value::TypeName", "" },
                new[] { "", "", "", "", "" },
                new[] { "Template:Organization:A8:A9", "", "", "", "" },
                new[] { "Value::Name", "", "", "", "" },
                new[] { "Value::Address", "", "", "", "" }
            };
            var template = FakeTable.GenerateFromStringArray(stringTemplate);

            var target         = new FakeTable(100, 100);
            var tableBuilder   = new TableBuilder(target, new TableNavigator(new CellPosition("A1"), logger));
            var templateEngine = new SkbKontur.Excel.TemplateEngine.TemplateEngine(template, logger);

            templateEngine.Render(tableBuilder, model);

            target.GetCell(new CellPosition("A1")).StringValue.Should().Be("Покупатель:");
            target.GetCell(new CellPosition("B1")).StringValue.Should().Be("Поставщик:");
            target.GetCell(new CellPosition("A2")).StringValue.Should().Be("BuyerName");
            target.GetCell(new CellPosition("B2")).StringValue.Should().Be("SupplierName");
            target.GetCell(new CellPosition("C2")).StringValue.Should().Be("ORDERS");
            target.GetCell(new CellPosition("A3")).StringValue.Should().Be("BuyerAddress");
            target.GetCell(new CellPosition("B3")).StringValue.Should().Be("SupplierAddress");

            ((FakeCell)target.GetCell(new CellPosition("A1"))).StyleId.Should().Be("B4");
            ((FakeCell)target.GetCell(new CellPosition("B1"))).StyleId.Should().Be("C4");
            ((FakeCell)target.GetCell(new CellPosition("A2"))).StyleId.Should().Be("A8");
            ((FakeCell)target.GetCell(new CellPosition("B2"))).StyleId.Should().Be("A8");
            ((FakeCell)target.GetCell(new CellPosition("C2"))).StyleId.Should().Be("D5");
            ((FakeCell)target.GetCell(new CellPosition("A3"))).StyleId.Should().Be("A9");
            ((FakeCell)target.GetCell(new CellPosition("B3"))).StyleId.Should().Be("A9");

            DebugPrinting(target, new CellPosition(1, 1), new CellPosition(10, 10));
        }
        public void StringValuePrintingTest()
        {
            var template = new FakeTable(1, 1);
            var cell     = template.InsertCell(new CellPosition(1, 1));

            cell.StringValue = "Template:RootTemplate:A1:A1";

            var templateEngine = new SkbKontur.Excel.TemplateEngine.TemplateEngine(template, logger);

            var target       = new FakeTable(10, 10);
            var tableBuilder = new TableBuilder(target, new TableNavigator(new CellPosition("B2"), logger), new Style(new FakeCell(new CellPosition("A1"))
            {
                StyleId = "(1,1)"
            }));

            templateEngine.Render(tableBuilder, "TestStringValue");

            target.GetCell(new CellPosition("B2")).StringValue.Should().Be("TestStringValue");

            ((FakeCell)target.GetCell(new CellPosition("B2"))).StyleId.Should().Be("(1,1)");
        }
        public void TestPrintingCommentsWithSeveralAuthors()
        {
            using (var templateDocument = ExcelDocumentFactory.CreateFromTemplate(File.ReadAllBytes(GetFilePath("commentsWithSeveralAuthors.xlsx")), logger))
                using (var targetDocument = ExcelDocumentFactory.CreateFromTemplate(File.ReadAllBytes(GetFilePath("empty.xlsx")), logger))
                {
                    var template       = new ExcelTable(templateDocument.GetWorksheet(0));
                    var templateEngine = new SkbKontur.Excel.TemplateEngine.TemplateEngine(template, logger);

                    var target         = new ExcelTable(targetDocument.GetWorksheet(0));
                    var tableNavigator = new TableNavigator(new CellPosition("A1"), logger);
                    var tableBuilder   = new TableBuilder(target, tableNavigator, new Style(template.GetCell(new CellPosition("A1"))));
                    templateEngine.Render(tableBuilder, new {});

                    var filename = "output.xlsx";
                    File.WriteAllBytes(filename, targetDocument.CloseAndGetDocumentBytes());

                    var path         = "file:///" + Path.GetFullPath(filename).Replace("\\", "/");
                    var templatePath = "file:///" + Path.GetFullPath("ExcelObjectPrinterTests/Files/commentsWithSeveralAuthors.xlsx").Replace("\\", "/");
                    Assert.Fail($"Please manually open file:\n{path}\nand check that cells has same comments as in\n{templatePath}\n");
                }
        }
        public void TestPrintingVbaMacros()
        {
            using (var templateDocument = ExcelDocumentFactory.CreateFromTemplate(File.ReadAllBytes(GetFilePath("printingVbaMacros.xlsm")), logger))
                using (var targetDocument = ExcelDocumentFactory.CreateFromTemplate(File.ReadAllBytes(GetFilePath("empty.xlsm")), logger))
                {
                    targetDocument.CopyVbaInfoFrom(templateDocument);

                    var template       = new ExcelTable(templateDocument.GetWorksheet(0));
                    var templateEngine = new SkbKontur.Excel.TemplateEngine.TemplateEngine(template, logger);

                    var target         = new ExcelTable(targetDocument.GetWorksheet(0));
                    var tableNavigator = new TableNavigator(new CellPosition("A1"), logger);
                    var tableBuilder   = new TableBuilder(target, tableNavigator, new Style(template.GetCell(new CellPosition("A1"))));
                    templateEngine.Render(tableBuilder, new { Type = "123" });

                    var filename = "output.xlsm";
                    File.WriteAllBytes(filename, targetDocument.CloseAndGetDocumentBytes());

                    var path = "file:///" + Path.GetFullPath(filename).Replace("\\", "/");
                    Assert.Fail($"Please manually open file '{path}' and check that clicking on the right checkbox leads to changes in both checkbox");
                }
        }
        public void TestDataValidations()
        {
            using (var templateDocument = ExcelDocumentFactory.CreateFromTemplate(File.ReadAllBytes(GetFilePath("dataValidations.xlsx")), logger))
                using (var targetDocument = ExcelDocumentFactory.CreateFromTemplate(File.ReadAllBytes(GetFilePath("empty.xlsx")), logger))
                {
                    var template       = new ExcelTable(templateDocument.GetWorksheet(0));
                    var templateEngine = new SkbKontur.Excel.TemplateEngine.TemplateEngine(template, logger);

                    var target         = new ExcelTable(targetDocument.GetWorksheet(0));
                    var tableNavigator = new TableNavigator(new CellPosition("A1"), logger);
                    var tableBuilder   = new TableBuilder(target, tableNavigator, new Style(template.GetCell(new CellPosition("A1"))));
                    templateEngine.Render(tableBuilder, new { Test = "b" });

                    var filename = "output.xlsx";
                    File.WriteAllBytes(filename, targetDocument.CloseAndGetDocumentBytes());

                    var path = "file:///" + Path.GetFullPath(filename).Replace("\\", "/");
                    Assert.Fail($"Please manually open file '{path}' and check that:\n\n" +
                                "Cell C4 has validation with variants abc, cde and lalala\n" +
                                "Cell E6 has validation with variants a, b, c and value b\n");
                }
        }
示例#15
0
        private void MakeTest(object model, string templateFileName, Action <ExcelTable> resultValidationFunc = null)
        {
            var templateDocument = ExcelDocumentFactory.CreateFromTemplate(File.ReadAllBytes(GetFilePath(templateFileName)), logger);
            var template         = new ExcelTable(templateDocument.GetWorksheet(0));

            var targetDocument = ExcelDocumentFactory.CreateFromTemplate(File.ReadAllBytes(GetFilePath("empty.xlsx")), logger);
            var target         = new ExcelTable(targetDocument.GetWorksheet(0));

            var tableBuilder   = new TableBuilder(target, new TableNavigator(new CellPosition("B2"), logger), new Style(template.GetCell(new CellPosition("A1"))));
            var templateEngine = new SkbKontur.Excel.TemplateEngine.TemplateEngine(template, logger);

            templateEngine.Render(tableBuilder, model);

            var result = targetDocument.CloseAndGetDocumentBytes();

            File.WriteAllBytes("output.xlsx", result);

            resultValidationFunc?.Invoke(target);

            templateDocument.Dispose();
            targetDocument.Dispose();
        }
        public void WithNullFiledsTest()
        {
            var model = new Organization
            {
                Address = null,
                Name    = "Name",
            };
            var stringTemplate = new[]
            {
                new[] { "Template:RootTemplate:A2:B2", "" },
                new[] { "Value::Address", "Value::Name" }
            };

            var template = FakeTable.GenerateFromStringArray(stringTemplate);

            var target         = new FakeTable(100, 100);
            var tableBuilder   = new TableBuilder(target, new TableNavigator(new CellPosition("B2"), logger));
            var templateEngine = new SkbKontur.Excel.TemplateEngine.TemplateEngine(template, logger);

            templateEngine.Render(tableBuilder, model);

            DebugPrinting(target, new CellPosition(1, 1), new CellPosition(20, 20));
        }
示例#17
0
        public void NonExistentFieldPrintingTest()
        {
            var model = new
            {
                A = false,
                B = true,
            };

            using (var templateDocument = ExcelDocumentFactory.CreateFromTemplate(File.ReadAllBytes(GetFilePath("template.xlsx")), logger))
            {
                var template       = new ExcelTable(templateDocument.GetWorksheet(0));
                var templateEngine = new SkbKontur.Excel.TemplateEngine.TemplateEngine(template, logger);

                using (var targetDocument = ExcelDocumentFactory.CreateFromTemplate(File.ReadAllBytes(GetFilePath("empty.xlsx")), logger))
                {
                    var target       = new ExcelTable(targetDocument.GetWorksheet(0));
                    var tableBuilder = new TableBuilder(target, new TableNavigator(new CellPosition("A1"), logger), new Style(template.GetCell(new CellPosition("A1"))));

                    Action rendering = () => templateEngine.Render(tableBuilder, model);
                    rendering.Should().Throw <InvalidOperationException>();
                }
            }
        }
        public void WithTemplateDecompositionTest()
        {
            var model = new Document
            {
                Buyer = new Organization
                {
                    Address = "BuyerAddress",
                    Name    = "BuyerName"
                },
                Supplier = new Organization
                {
                    Address = "SupplierAddress",
                    Name    = "SupplierName",
                    Inn     = "90238192038",
                    Kpp     = "0832309812"
                },
                Payer = new Organization
                {
                    Address = "PayerAddress",
                    Name    = "PayerName"
                },
                DeliveryParty = new Organization
                {
                    Address = "DeliveryPartyAddress",
                    Name    = "DeliveryPartyName"
                },
                Vehicle = new VehicleInfo
                {
                    NameOfCarrier = "Евкакий",
                    TransportMode = "Agressive",
                    VehicleBrand  = "Tauria",
                    VehicleNumber = "A777AB"
                },
                TypeName = "ORDERS"
            };

            var stringTemplate = new[]
            {
                new[] { "Template:RootTemplate:A2:D5", "", "", "", "", "" },
                new[] { "Покупатель:", "", "Поставщик:", "", "", "" },
                new[] { "Value:Organization:Buyer", "Value::TypeName", "Value:DetailedOrganization:Supplier", "", "", "" },
                new[] { "Плательщик:", "Средство доставки:", "", "Доставка:", "", "" },
                new[] { "Value:Organization:Payer", "Value:VehicleInfo:Vehicle", "Value:Organization:DeliveryParty", "", "", "" },
                new[] { "", "", "", "", "", "" },
                new[] { "Template:Organization:A8:A9", "", "", "", "", "" },
                new[] { "Value::Name", "", "", "", "", "" },
                new[] { "Value::Address", "", "", "", "", "" },
                new[] { "", "", "", "", "", "" },
                new[] { "Template:VehicleInfo:A12:B13", "", "", "", "", "" },
                new[] { "Value::NameOfCarrier", "Value::VehicleBrand", "", "", "", "" },
                new[] { "Value::TransportMode", "Value::VehicleNumber", "", "", "", "" },
                new[] { "", "", "", "", "", "" },
                new[] { "Template:DetailedOrganization:A16:B17", "", "", "", "", "" },
                new[] { "Value::Name", "Value::Inn", "", "", "", "" },
                new[] { "Value::Address", "Value::Kpp", "", "", "", "" }
            };

            var template = FakeTable.GenerateFromStringArray(stringTemplate);

            var target         = new FakeTable(100, 100);
            var tableBuilder   = new TableBuilder(target, new TableNavigator(new CellPosition("A1"), logger));
            var templateEngine = new SkbKontur.Excel.TemplateEngine.TemplateEngine(template, logger);

            templateEngine.Render(tableBuilder, model);

            target.GetCell(new CellPosition("A1")).StringValue.Should().Be("Покупатель:");
            target.GetCell(new CellPosition("C1")).StringValue.Should().Be("Поставщик:");
            target.GetCell(new CellPosition("A2")).StringValue.Should().Be("BuyerName");
            target.GetCell(new CellPosition("A3")).StringValue.Should().Be("BuyerAddress");
            target.GetCell(new CellPosition("B2")).StringValue.Should().Be("ORDERS");
            target.GetCell(new CellPosition("C2")).StringValue.Should().Be("SupplierName");
            target.GetCell(new CellPosition("D2")).StringValue.Should().Be("90238192038");
            target.GetCell(new CellPosition("C3")).StringValue.Should().Be("SupplierAddress");
            target.GetCell(new CellPosition("D3")).StringValue.Should().Be("0832309812");
            target.GetCell(new CellPosition("A4")).StringValue.Should().Be("Плательщик:");
            target.GetCell(new CellPosition("B4")).StringValue.Should().Be("Средство доставки:");
            target.GetCell(new CellPosition("D4")).StringValue.Should().Be("Доставка:");
            target.GetCell(new CellPosition("A5")).StringValue.Should().Be("PayerName");
            target.GetCell(new CellPosition("A6")).StringValue.Should().Be("PayerAddress");
            target.GetCell(new CellPosition("B5")).StringValue.Should().Be("Евкакий");
            target.GetCell(new CellPosition("C5")).StringValue.Should().Be("Tauria");
            target.GetCell(new CellPosition("B6")).StringValue.Should().Be("Agressive");
            target.GetCell(new CellPosition("C6")).StringValue.Should().Be("A777AB");
            target.GetCell(new CellPosition("D5")).StringValue.Should().Be("DeliveryPartyName");
            target.GetCell(new CellPosition("D6")).StringValue.Should().Be("DeliveryPartyAddress");

            DebugPrinting(target, new CellPosition(1, 1), new CellPosition(20, 20));
        }