Create Table From ListView

I'm trying to create a Word Doc using Syncfusion .NET Maui DocIO that takes the data from a ListView and converts it into a Word Table.


Here is my code:

    PatientRepository patientRepository = new PatientRepository();
    var patList = patientRepository.GetPatients();




    // Sample data
    var patients = new List<Patient>();


    foreach (var item in patList)
    {
        patients.Add(new Patient{pid=item.pid, FullName = item.FullName, DOB = item.DOB, sex=item.xxx, maritalstatus = item.maritalstatus, Address1=item.Address1,Address2=item.Address2,
        City=item.City,State=item.State,zipcode=item.zipcode,homephone=item.homephone,email=item.email,ssn=item.ssn});
    }




personListView.ItemsSource = patients;

I want to create the Word doc/table using the above data.?





4 Replies 1 reply marked as answer

DS Dharanya Sakthivel Syncfusion Team September 5, 2024 10:19 AM UTC

Hi Frederick,

We have prepared and attached the sample to get the data from list and add into the table. We can achieve this by performing a mail merge (which is the process of merging data from a data source into a Word template document) using merge fields (placeholders that can be replaced with data during document generation).

To do mail merge, it is needed to design template Word document with merge fields. You can insert merge fields either DocIO programmatically or using Microsoft Word application.


Here are the steps to design a template Word document for executing a mail merge using Microsoft Word:

  1. Insert Merge fields in Word document.

2. The merge field "EmployeeName" will now be added to the Word document as like below.

                 

In your requirement, we have achieved this using  ExecuteGroup method to perform Mail merge within a group. The records are inserted between merge fields marked as start and end table, and this process is repeated for every record in the list.


Kindly refer the below links to know about mail merge in DocIO.
Documentation-working-with-mail-merge
GitHub-sample-Mail-merge
KB-mail-merge
mail-merge-word-csharp-ultimate-guide

Regards,
Dharanya.



Attachment: Mailmergetable_72178fe8.zip


FS Frederick Switzer replied to Dharanya Sakthivel September 5, 2024 01:20 PM UTC

Thank you Dharanya, but I'm really looking for a solution to my problem that just converts the List into a Standard Word Doc, where the data is appended to a paragraph or something like that using the Syncfusion DocIO library.




DS Dharanya Sakthivel Syncfusion Team September 9, 2024 12:11 PM UTC

Frederick,

We have created a sample that demonstrates how to convert data from a ListView into a Word table using Syncfusion DocIO. Kindly refer the attached sample in the below attachment.

In the attached sample, we have done the following things:

  1. Create and add the patient data to a list (patients).
  2. Displayed the patient data in a ListView.
  3. Created a new Word document using Syncfusion DocIO.
  4. Created a single-column table where each row holds all details of a patient.
  5. Inserted each patient’s details into one cell per row in the Word table.
  6. Saved the document.


If the provided solution does not meet your requirements, kindly share the expected output and any additional details about your requirement. This will help us provide a solution.


Regards,
Dharanya.


Attachment: Listviewwordtable_e2dfebdc.zip

Marked as answer

FS Frederick Switzer replied to Dharanya Sakthivel September 9, 2024 01:48 PM UTC

Dharanya,


Thank you, that is exactly what I was looking for.

Nice example.

FTS


Loader.
Up arrow icon