Problem with find and replace text in Word Doc with a table

Hi,

I am trying to create a table from a list in asp.net core application but I have challenges implementing it

The variable "bene" is holding a list which I want to append to the table and replace with  placeholder " XfactorX"

I having challenges implementing that

  WTable BeneTable = new WTable(document);

                BeneTable.ResetCells(1, bene.Count + 1);
                BeneTable[0, 0].Width = 52f;
                BeneTable[0, 0].AddParagraph().AppendText("FirstName");
                BeneTable[0, 1].Width = 128f;
                BeneTable[0, 1].AddParagraph().AppendText("LastName");
                    for (int i = 1; i < bene.Count; i++)
                    {
                        BeneTable[0, i].AddParagraph().AppendText(bene[i].FirstName);
                        BeneTable[0, i+1].AddParagraph().AppendText(bene[i].FirstName);
                    }
                BeneTable.ApplyStyle(BuiltinTableStyle.MediumShading1Accent1);
                //Replaces the table placeholder text with a new table
                TextBodyPart bodyPart = new TextBodyPart(document);
                bodyPart.BodyItems.Add(BeneTable);
                document.Replace("XfactorX", bodyPart, true, true, true);

Thanks




2 Replies

SB Suriya Balamurugan Syncfusion Team June 7, 2022 08:35 AM UTC

Hi Adedokun,

From the given details, we have found that your end requirement is to create table from the list of data and replace the text in the Word document with that table.

We have prepared a sample application using your code snippet. Please refer to the sample from the below attachment.

If we misunderstood any of your requirement, then kindly provide us sample or modified sample of above along with input template, and screenshot/output Word document of the expected result which will be helpful to provide you the appropriate solution at the earliest.

Regards,
Suriya Balamurugan.


Attachment: Findandreplacetextwithtable_a252181d.zip


AB Adedokun Bamigboye June 7, 2022 09:47 AM UTC

Hi Suriya,

Thanks for taking the time to do this for me.

I have resolved it after looking at the sample solution. 


Regards




Loader.
Up arrow icon