I'm looking for help on how to populate a Word 2003 template from a DataSet, insert bookmarks with the correct formatting and how to access the bookmark collection.the bookmark insertion points at the location for the recipient and name and address.i have 2 or 3 tables and i have populate dataset with different field.than that field must be populate
to template file .and this field i have to set bookmark name and location.how to do that in C# windows forms???
how to make data set with different field and populate template file with bookmark???
Please help me, I have VB 6 code, but I don't how to do in C# Windows Forms?
Private Sub Document_Open()
Dim Conn As New ADODB.Connection
Dim rsInvoices As New Recordset
Dim objDoc As Document
Dim objTable As Table
Dim strUserTemplates As String
Dim strConnection As String
Dim strCustomer As String
Dim strDBPath As String
Dim strSQL As String
Dim intNumRows As Integer
Dim i As Integer
On Error Resume Next
strDBPath = "C:\Program Files\Microsoft OfficeXP" & _ "\Office10\Samples\Northwind.mdb"
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Persist Security Info=False;" & _ "Data Source=" & strDBPath
Conn.Open strConnection
strSQL = "SELECT * FROM Invoices " & _ "WHERE (((Orders.ShipName)='QUICK-Stop'))" rsInvoices.Open strSQL, Conn, adOpenStatic, adLockReadOnly strUserTemplates = Options.DefaultFilePath(wdUserTemplatesPath) Set objDoc = Documents.Add(strUserTemplates & _ "\Simple Invoice.dot")
SetBookmark ActiveDocument, "CoName", _ rsInvoices("Customers.CompanyName").Value
SetBookmark ActiveDocument, "CoAddress", _ rsInvoices("Address").Value
SetBookmark ActiveDocument, "CoCity", _ rsInvoices("City").Value
If IsNull(rsInvoices("Region").Value)
Then
SetBookmark ActiveDocument, "CoState", _ ""
Else
SetBookmark ActiveDocument, "CoState", _ rsInvoices("Region").Value
End If
SetBookmark ActiveDocument, "CoZip", _ rsInvoices("PostalCode").Value
SetBookmark ActiveDocument, "BillToName", _ rsInvoices("Salesperson").Value
SetBookmark ActiveDocument, "BillToCompany", _ rsInvoices("ShipName").Value
SetBookmark ActiveDocument, "BillToAddress", _ rsInvoices("ShipAddress").Value
SetBookmark ActiveDocument, "BillToCity", _ rsInvoices("ShipCity").Value
If IsNull(rsInvoices("ShipRegion").Value)
Then
SetBookmark ActiveDocument, "BillToState", _ "" Else
SetBookmark ActiveDocument, "BillToState", _ rsInvoices("ShipRegion").Value
End If
SetBookmark ActiveDocument, "BillToZip", _ rsInvoices("ShipPostalCode").Value
Set objTable = ActiveDocument.Tables(3) i = 1
objTable.Cell(i, 1).Range.Text = "Description"
objTable.Cell(i, 2).Range.Text = "Amount"
Do While Not rsInvoices.EOF i = i + 1
objTable.Cell(i, 1).Range.Text = rsInvoices("ProductName")
objTable.Cell(i, 2).Range.Text = Format(rsInvoices("ExtendedPrice"), "Currency") rsInvoices.MoveNext Loop ‘ Clean up.
Set objDoc = Nothing
Set objTable - Nothing End Sub Public Sub SetBookmark(objDoc As Document, sBookmark As String, sValue As String)
If objDoc.Bookmarks.Exists(sBookmark)
Then
objDoc.Bookmarks(sBookmark).Range.Text = sValue
End If
End Sub