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.

Sat Mar 02, 2019 3:09 am

How can i do this in Spire.DOC in .NET

aksh0614
 
Posts: 23
Joined: Mon Jul 02, 2018 3:53 am

Mon Mar 04, 2019 2:03 am

Hello,

Thank you for contacting us.
Our Spire.Doc supports creating mail merge and merging the value, please refer to the tutorial (How to create mail merge and merge the text value) to achieve it. If there is any question, just feel free to write back.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Mon Mar 04, 2019 3:23 am

Can u provide a code for previous sample i want same design in doc through code

aksh0614
 
Posts: 23
Joined: Mon Jul 02, 2018 3:53 am

Mon Mar 04, 2019 5:52 am

Hello,

Thanks for your quick responce.
Please refer to the following sample code to achieve the same design like your screenshot. Any other question, just feel free to contact us.
Code: Select all
static void Main(string[] args)
{
    Document doc = new Document();
    Section sec = doc.AddSection();
    //create a table
    Table table = sec.AddTable(true);
    table.ResetCells(2, 2);
    table.Rows[0].Height = 25;
    table.TableFormat.Borders.Vertical.BorderType = Spire.Doc.Documents.BorderStyle.None;
    table.TableFormat.Borders.Horizontal.Color = Color.LightGray;
    table.TableFormat.Borders.Color = Color.LightGray;
    //add content for table
    TextRange range = table[0, 0].AddParagraph().AppendText("Dealership");
    range.CharacterFormat.Bold = true;
    Paragraph textPara = table[1, 0].AddParagraph();
    Paragraph fieldPara = table[1, 1].AddParagraph();
    ParagraphStyle stylefieldPara = new ParagraphStyle(doc);
    stylefieldPara.Name = "fieldPara";
    stylefieldPara.CharacterFormat.TextColor = Color.FromArgb(91, 197, 149);
    doc.Styles.Add(stylefieldPara);
    fieldPara.ApplyStyle("fieldPara");
    string[] fieldName = { "Dealership/Company operating as", "Address:", "City or Town", "Province", "Postal Code", "Business Phone#", "Cell Phone #" };
    for (int i = 0; i < fieldName.Length; i++)
    {
        appendTextAndField(textPara,fieldPara, fieldName[i]);
    }
    string[] fieldValue = { "Bob's Dealership", "123 Address Street","Edmonton","Alberta","T5L5L5","780 123 4567","780 234 5678"};
    //do mail merge
    doc.MailMerge.Execute(fieldName, fieldValue);
    //save to file
    doc.SaveToFile("result.docx", Spire.Doc.FileFormat.Docx);
}
private static void appendTextAndField(Paragraph textPara, Paragraph fieldPara, string text)
{
    textPara.AppendText(text);
    textPara.AppendBreak(BreakType.LineBreak);
    fieldPara.AppendField(text, FieldType.FieldMergeField);
    fieldPara.AppendBreak(BreakType.LineBreak);
}

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Mon Mar 04, 2019 7:27 am

thank you it is working :D

aksh0614
 
Posts: 23
Joined: Mon Jul 02, 2018 3:53 am

Mon Mar 04, 2019 7:41 am

Hello,

Glad to hear that. Just feel free to contact us if you need other helps. Have a nice day.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Fri Mar 08, 2019 6:26 am

Spire doc loses formatting when converting from docx to pdf

aksh0614
 
Posts: 23
Joined: Mon Jul 02, 2018 3:53 am

Fri Mar 08, 2019 6:49 am

Hi,

Thanks for your inquiry.
To help us reproduce your issue on our side, please provide your input Word file and generated PDF file which shows us the missing format issue. You could send them to us via email (support@e-iceblue.com). Thanks in advance.

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Fri Mar 08, 2019 8:16 am

Sample doc and PDF

aksh0614
 
Posts: 23
Joined: Mon Jul 02, 2018 3:53 am

Fri Mar 08, 2019 8:39 am

Hi,

Thanks for your sharing.
I have reproduced the issue and logged it into our bug tracking system. If it is fixed or there is any update, I will notify you. Apologize for the inconvenience caused.

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Return to Spire.Doc