Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Thu Dec 12, 2019 10:58 am

Hello,

can you please help me with my problem. I need to render bill for my company, and i have managed to create bill
with placeholders and document.Replace, but now i have to render list in my bill.
I have data like this:

List<Billing>()
{
new Billing()
{
ClientId = 1,
ObjectIdExternal = 12887,
ClientVAT = 789456,
Kbr = "70 59",
ClientName = "Joseph Smith",
BillingAccountWasteContainers = new List<BillingAccountWasteContainer>()
{
new BillingAccountWasteContainer()
{
WasteId = 1,
Quantity = 7,
Volumen = 180
},
new BillingAccountWasteContainer()
{
WasteId = 2,
Quantity = 5,
Volumen = 550
}
}
},
new Billing()
{
ClientId = 2,
ObjectIdExternal = 123437,
ClientVAT = 711456,
Kbr = "73 22",
ClientName = Steve Tailor",
BillingAccountWasteContainers = new List<BillingAccountWasteContainer>()
{
new BillingAccountWasteContainer()
{
WasteId = 3,
Quantity = 7,
Volumen = 320
},
new BillingAccountWasteContainer()
{
WasteId = 4,
Quantity = 7,
Volumen = 640
}
}
}
}

How from this data i can get something like this file in attachment.

Thank you very much in advance,
Danilo

mosurovicdanilo
 
Posts: 2
Joined: Wed Sep 11, 2019 10:49 am

Fri Dec 13, 2019 10:56 am

Hi,

Thanks for your inquiry.
According to your information, I think MailMerge function could meet your requirement. Please refer to attached files and below code:
Code: Select all
            List<DictionaryEntry> list = new List<DictionaryEntry>();
            DataSet dsData = new DataSet();

            dsData.ReadXml(FilePath + @"data19924.xml");

            //Create word document
            Document document = new Document();
            document.LoadFromFile(FilePath + @"19942Sample.docx");

            DictionaryEntry dictionaryEntry = new DictionaryEntry("Client", string.Empty);
            list.Add(dictionaryEntry);

            dictionaryEntry = new DictionaryEntry("Waste", "Client_Id = %Client.Client_Id%");
            list.Add(dictionaryEntry);

            document.MailMerge.ExecuteWidthNestedRegion(dsData, list);

            //Save as docx file.
            document.SaveToFile("result.docx", FileFormat.Docx);


Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.Doc

cron