1
Vote

InsertParagraphs inserts same paragraph multiple times

description

  1. Make a string with multiple paragraphs separated by newlines
  2. Call doc.InsertParagraphs(text)
Expected: Returns a Paragraph[] with each paragraph
Actual: Returns a Paragraph[] with the whole string duplicated in every paragraph

This code in DocX.cs:
public Paragraph[] InsertParagraphs(string text)
        {
            String[] textArray = text.Split('\n');
            List<Paragraph> paragraphs = new List<Paragraph>();
            foreach (var textForParagraph in textArray)
            {
                Paragraph p = base.InsertParagraph(text);
                p.PackagePart = mainPart;
                paragraphs.Add(p);
            }
            return paragraphs.ToArray();
        }
should be
public Paragraph[] InsertParagraphs(string text)
        {
            String[] textArray = text.Split('\n');
            List<Paragraph> paragraphs = new List<Paragraph>();
            foreach (var textForParagraph in textArray)
            {
                Paragraph p = base.InsertParagraph(textForParagraph);
                p.PackagePart = mainPart;
                paragraphs.Add(p);
            }
            return paragraphs.ToArray();
        }
Note the line Paragraph p = base.InsertParagraph(textForParagraph);.

comments