UNIT6-open / TemplateEngine.Docx

Smart docx template engine for .NET
Other
406 stars 137 forks source link

Error 'Sequence contains no elements' when TableContent have not rows. (count == 0) #35

Closed ildarnm closed 7 years ago

ildarnm commented 7 years ago

callstack:

at System.Linq.Enumerable.First[TSource](IEnumerable1 source) at TemplateEngine.Docx.Processors.TableProcessor.GetPrototype(XContainer tableContentControl, IEnumerable1 fieldNames) at TemplateEngine.Docx.Processors.TableProcessor.FillContent(XContainer contentControl, IContentItem item) at TemplateEngine.Docx.Processors.TableProcessor.FillContent(XElement contentControl, IEnumerable1 items) at TemplateEngine.Docx.Processors.ContentProcessor.FillContent(XElement content, IEnumerable1 data) at TemplateEngine.Docx.Processors.ContentProcessor.FillContent(XElement content, Content data) at TemplateEngine.Docx.TemplateProcessor.FillContent(Content content)

abatar1 commented 7 years ago

Fixed it.

ildarnm commented 7 years ago

@abatar1 Bug in TableProcessor method GetPrototype line where is Enumerable.First When fieldNames list is empty it return error

abatar1 commented 7 years ago

Could you please write your code where you construct Content to be filled in TemplateProcessor? I don't get this error when I only try to create Content with TableContent with no rows.

ildarnm commented 7 years ago
using (var document = new TemplateProcessor("Assets/OutputDocument.docx")
                .SetRemoveContentControls(true))
            {
                var content = new Content(new TableContent("TestTable"));

                document.FillContent(content);
                document.SaveChanges();
            }

In template should be token "TestTable".

ildarnm commented 7 years ago

@abatar1 I figured out. It is happens only if use Repeat Section Content Control in Word