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.

Tue May 19, 2015 10:30 am

Hello There,

I have a table in db lets assume its student records, now I want to create Icards for all the students, I created a format in wordTemplate, and I want to create this icard for all the students how can I do that??

Here is my Template

Image

I want Output like this

Image

Thanks in Advance.

ankitspire
 
Posts: 2
Joined: Tue Jan 13, 2015 6:16 am

Wed May 20, 2015 4:52 am

Hi Everyone,

Does anyone have the solution for this??? Is this even possible using spire.doc?? I need this urgently, please provide me some hint, it will be a great help.

Thanks

ankitspire
 
Posts: 2
Joined: Tue Jan 13, 2015 6:16 am

Wed May 20, 2015 5:59 am

Hello,

Thanks for your inquiry. Can you please attach your template here(firstly zip) or send it to us(support@e-iceblue.com) via email?

Thanks in advance,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Wed May 20, 2015 8:08 am

Hello,

Here are the method for your reference.
Code: Select all
Document document = new Document();
document.LoadFromFile("MergeTables.docx");
Table table = null;
        foreach (Section sec in document.Sections)
        {
            table = (sec.Tables[0] as Table).Clone();
           
        }
        DataTable dt = InitializeData();
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            document.Replace("#StudentName#", dt.Rows[i]["Student Name"].ToString(), true, true);
            document.Replace("#FathersName#", dt.Rows[i]["Father Name"].ToString(), true, true);
            document.Replace("#Std#", dt.Rows[i]["std"].ToString(), true, true);
            document.Replace("#Sec#", dt.Rows[i]["Sec"].ToString(), true, true);
            document.Replace("#MobNo#", dt.Rows[i]["MobNo"].ToString(), true, true);
            document.Replace("#Address#", dt.Rows[i]["Address"].ToString(), true, true);
            Table ta = table.Clone();
            if (i == 0)
            {
                ta.TableFormat.Positioning.HorizRelationTo = HorizontalRelation.Page;
                ta.TableFormat.Positioning.HorizPosition = ta.Width;
                ta.TableFormat.Positioning.VertRelationTo = VerticalRelation.Paragraph;
            }
            else if (i % 2 == 0 && i != 0)
            {

                ta.TableFormat.Positioning.HorizRelationTo = HorizontalRelation.Page;
                ta.TableFormat.Positioning.HorizPosition = ta.Width;
                ta.TableFormat.Positioning.VertRelationTo = VerticalRelation.Paragraph;

            }
            else
            {
                document.Sections[0].Body.AddParagraph();
                ta.TableFormat.Positioning.HorizRelationTo = HorizontalRelation.Column;
                ta.TableFormat.Positioning.HorizPosition = 0;
                ta.TableFormat.Positioning.VertRelationTo = VerticalRelation.Paragraph;
            }
            if (i < dt.Rows.Count - 1)
            {
                int index=document.Sections[0].Body.ChildObjects.IndexOf(document.Sections[0].Body.ChildObjects.LastItem);
                document.Sections[0].Body.ChildObjects.Insert(index,ta);
            }

        }
        document.SaveToFile( "MergeTables.docx", FileFormat.Docx);

If there are any quesions, please supply us your template.
Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Return to Spire.Doc