Search code examples
c#winformsms-worddocxxceed

Dynamic cell in word Xceed


I have a list of items in a listbox that I am trying to insert dynamically into a table in a word document, the table in word has one row but I need it to add more if there are multiple items in the listbox.

I'm currently adding the items to the table like so ("Item Description" is a custom property that I set in word):

            template.AddCustomProperty(new Xceed.Document.NET.CustomProperty("Item Description", item.ProdName));
            template.AddCustomProperty(new Xceed.Document.NET.CustomProperty("Quantity", item.Quantity));
            template.AddCustomProperty(new Xceed.Document.NET.CustomProperty("Unit Price", item.Price));
            template.AddCustomProperty(new Xceed.Document.NET.CustomProperty("Total Per Item", Total ));

I've done my research but so far I couldn't find anything
Hopefully someone could guide me in the right direction

Thanks for your help in advance.


Solution

  • In the end i figured it out myself.
    I insert the items into the table like so:

                foreach (listItem item in descriptionclb.Items)
                {
                    ItemTable.Rows[i].Cells[j].Paragraphs[0].Append(item.ProdName);
                    j++;
                    ItemTable.Rows[i].Cells[j].Paragraphs[0].Append(item.ProdName);
                    j++;
                    ItemTable.Rows[i].Cells[j].Paragraphs[0].Append(item.Quantity.ToString());
                    j++;
                    ItemTable.Rows[i].Cells[j].Paragraphs[0].Append(item.Price.ToString());
                    j++;
                    ItemTable.Rows[i].Cells[j].Paragraphs[0].Append(Total.ToString());
    
                    i++;
                    j = 0;
                }