Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to fill data from application (get from database) to fields in .doc file which i was remarked.
That mean i want to change report flexibility.
Pls help me!

Thanks all!
I load data into datatable with columns: ID, EmpName, DayOfBirth, Sex, Note. A .doc file designed with fields same in datatable. I want to fill data from datable into .doc file.
P/S:
1. If datatable have n rows so the .doc file will have n pages.
2. If i want to fill the Note field into 3 lines in .doc file, what i should do? That mean the data cannot overflow 3 lines.
Posted
Updated 23-May-12 22:26pm
v2

The best I can recommend is that you export using the WOrd Interopt. This is almost definatly not the answer you want becuase it will be some work.
 
Share this answer
 
Comments
Nguyễn Minh Phúc 24-May-12 4:37am    
Can you give me code to do this? Thank!
Go through the below link, this may helps you

Here[^]

Thanks
--RA
 
Share this answer
 
Comments
Nguyễn Minh Phúc 24-May-12 21:38pm    
Dear friend,
I think you are misunderstanding my question. I want to fill data from datatable which i get from database.
Thank your reply!
You can always output the data in a CSV, and set your word document up as a mail merge.
 
Share this answer
 
Comments
Nguyễn Minh Phúc 24-May-12 23:05pm    
Pls guide clearly!
 
Share this answer
 
Comments
Clifford Nelson 23-May-12 23:36pm    
Interesting and good link, but does not really answer the question since want to export to Word document.
Here is my code:
VB
Public Class Form1
    Dim db As New DBDataContext
    Private Sub btnInsert_Click(sender As System.Object, e As System.EventArgs) Handles btnInsert.Click
        Dim c = (From c1 In db.CustomerDetails
                Select c1).FirstOrDefault
        Dim oWord As Application
        Dim oDoc As Document
        oWord = CreateObject("Word.Application")
        oDoc = oWord.Documents.Add()
        oDoc.Application.Selection.Range.InsertFile(Environment.CurrentDirectory & "\Doc1.doc")
        oDoc.Bookmarks("cust_name").Range.Text = c.cust_name
        oDoc.Bookmarks("cust_address").Range.Text = c.cust_address
        oDoc.Bookmarks("cust_contact").Range.Text = c.cust_contact

        oDoc.ActiveWindow.Selection.WholeStory()
        oDoc.ActiveWindow.Selection.Copy()
        oWord.Visible = True
    End Sub
End Class


I wish i can fill all data row in c object into .doc file. So i will remove FirstOrDefault then loop it, i am expected a resulting which many pages was created. But it error!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900