diff --git a/Excel.TemplateEngine.Tests/ObjectPrintingTests/ExcelParsingTests.cs b/Excel.TemplateEngine.Tests/ObjectPrintingTests/ExcelParsingTests.cs index d033ce6..97cdec9 100644 --- a/Excel.TemplateEngine.Tests/ObjectPrintingTests/ExcelParsingTests.cs +++ b/Excel.TemplateEngine.Tests/ObjectPrintingTests/ExcelParsingTests.cs @@ -65,6 +65,25 @@ public void TestSimpleWithEnumerable() }); } + [Test] + public void TestInvalidUris() + { + var (model, mappingForErrors) = Parse("simpleWithEnumerable_template.xlsx", "simpleWithEnumerable_targetWithInvalidUri.xlsx"); + + mappingForErrors["Type"].Should().Be("C3"); + mappingForErrors["Items[0].Id"].Should().Be("B13"); + mappingForErrors["Items[0].Name"].Should().Be("C13"); + mappingForErrors["Items[1].Id"].Should().Be("B14"); + mappingForErrors["Items[1].Name"].Should().Be("C14"); + + model.Type.Should().Be("email@email.email>"); + model.Items.Should().BeEquivalentTo(new[] + { + new Item {Id = "2311129000009", Name = "СЫР ГОЛЛАНДСКИЙ МОЖГА 1КГ"}, + new Item {Id = "2311131000004", Name = "СЫР РОССИЙСКИЙ МОЖГА 1КГ"}, + }); + } + [Test] public void TestLazyParse() { diff --git a/Excel.TemplateEngine.Tests/ObjectPrintingTests/Files/simpleWithEnumerable_targetWithInvalidUri.xlsx b/Excel.TemplateEngine.Tests/ObjectPrintingTests/Files/simpleWithEnumerable_targetWithInvalidUri.xlsx new file mode 100644 index 0000000..9115874 Binary files /dev/null and b/Excel.TemplateEngine.Tests/ObjectPrintingTests/Files/simpleWithEnumerable_targetWithInvalidUri.xlsx differ diff --git a/Excel.TemplateEngine/FileGenerating/Primitives/Implementations/ExcelDocument.cs b/Excel.TemplateEngine/FileGenerating/Primitives/Implementations/ExcelDocument.cs index 3906f15..27e3a8e 100644 --- a/Excel.TemplateEngine/FileGenerating/Primitives/Implementations/ExcelDocument.cs +++ b/Excel.TemplateEngine/FileGenerating/Primitives/Implementations/ExcelDocument.cs @@ -32,7 +32,11 @@ public ExcelDocument([NotNull] byte[] template, [NotNull] ILog logger) documentMemoryStream = new MemoryStream(); documentMemoryStream.Write(template, 0, template.Length); - spreadsheetDocument = SpreadsheetDocument.Open(documentMemoryStream, true); + var settings = new OpenSettings + { + RelationshipErrorHandlerFactory = RelationshipErrorHandler.CreateRewriterFactory((_, _, val) => " ") + }; + spreadsheetDocument = SpreadsheetDocument.Open(documentMemoryStream, true, settings); var theme = GetEmptyTheme(); documentStyle = new ExcelDocumentStyle(spreadsheetDocument.GetOrCreateSpreadsheetStyles(), spreadsheetDocument.WorkbookPart?.ThemePart?.Theme ?? theme, this.logger);