Adding multiple rows to a docx files with OpenXML

  Uncategorised

I am using TemplateEngine.Docx, Template engine for generating Word docx in Visual Studio for C#. Basically I am trying to add multiple rows to an edited word document using a for loop. However when I loop through the if statement it will just rewrite the data that was just read. Here is my code:

if (fieldName == "examrubric")
            {

                for (; ; )
                {
                    Console.WriteLine("To enter a row to the tabel type 'yes'n");
                    string choice = Console.ReadLine();

                    if (choice == "yes")
                    {

                        Console.WriteLine("Enter a value for the question number:n");
                        string qnum = Console.ReadLine();
                        Console.WriteLine("Enter a value for what the question is out of:n");
                        string score = Console.ReadLine();
                        Console.WriteLine("Enter a value for how much was scored:n");
                        string qscore = Console.ReadLine();
                        Console.WriteLine("Enter a value for score:n");
                        string score2 = Console.ReadLine();
                        Console.WriteLine("Enter the total mark:n");
                        string total = Console.ReadLine();


                        valuesToFill = new Content(
                                       new TableContent("examrubric")
                                       .AddRow(
                                       new FieldContent("qnum", qnum),
                                       new FieldContent("score", score),
                                       new FieldContent("qscore", qscore),
                                       new FieldContent("score2", score2),
                                       new FieldContent("total", total)));
                    }

                    else
                    {
                        break;
                    }
                }
            }

Source: Visual Studio Questions

LEAVE A COMMENT