Export a database in word

lcroito

New member
Joined
Oct 24, 2003
Messages
3
Location
Romania
I have a datatable with fields Name and Function.

I want to open or create a Word document with text:
"My name is ______________ and I am ____________ in this company."
In line I want to write Name and Function from datatable, for each line -> one page.

Please give me one example in C#.

Thank you

Lucian
 
Lucian,

Here is an example in VB.NET:

Dim oldCI As System.Globalization.CultureInfo = _
System.Threading.Thread.CurrentThread.CurrentCulture

System.Threading.Thread.CurrentThread.CurrentCulture = _
New System.Globalization.CultureInfo("en-US")

Dim wapp As Word.Application
Dim wdoc As Word.Document
Dim dbe As DAO.DBEngine
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strDbFullPath As String
Dim strText As String

wapp = New Word.Application()
wapp.Visible = True
wdoc = wapp.Documents.Add

strDbFullPath = "c:\temp\testDb.mdb"
dbe = New DAO.DBEngine()
dbs = dbe.OpenDatabase(strDbFullPath)
rst = dbs.OpenRecordset("tblTest", DAO.RecordsetTypeEnum.dbOpenSnapshot)
While Not rst.EOF
strText = "My name is " & rst.Fields("Name").Value & _
" and I am " & rst.Fields("Function").Value & " in this company."
With (wapp.Selection)
.TypeText(strText)
.TypeParagraph()

rst.MoveNext()
If Not rst.EOF Then .InsertBreak(Type:=Word.WdBreakType.wdPageBreak)
End With
End While
dbs.Close()

wdoc.SaveAs("c:\temp\doc1.doc")
Dim idoc As Word._Document
idoc = wdoc
idoc.Close()
Dim iapp As Word._Application
iapp = wapp
iapp.Quit()
wapp = Nothing

GC.Collect()

System.Threading.Thread.CurrentThread.CurrentCulture = oldCI

Do you want it translated to C#?

HTH,
Shamil
 
Back
Top