Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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?

VB
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" 'Open a connection to the Northwind database. 
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") 'Retrieve and set company information. 
SetBookmark ActiveDocument, "CoName", _ rsInvoices("Customers.CompanyName").Value 
SetBookmark ActiveDocument, "CoAddress", _ rsInvoices("Address").Value 
SetBookmark ActiveDocument, "CoCity", _ rsInvoices("City").Value ' To handle Nulls in this field. 
If IsNull(rsInvoices("Region").Value) 
Then 
SetBookmark ActiveDocument, "CoState", _ "" 
Else 
SetBookmark ActiveDocument, "CoState", _ rsInvoices("Region").Value 
End If 

SetBookmark ActiveDocument, "CoZip", _ rsInvoices("PostalCode").Value ' Retrieve and set Bill To information. 
SetBookmark ActiveDocument, "BillToName", _ rsInvoices("Salesperson").Value 
SetBookmark ActiveDocument, "BillToCompany", _ rsInvoices("ShipName").Value 
SetBookmark ActiveDocument, "BillToAddress", _ rsInvoices("ShipAddress").Value 
SetBookmark ActiveDocument, "BillToCity", _ rsInvoices("ShipCity").Value 'To handle Nulls in this field 
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
Posted
Updated 8-Mar-12 2:56am
v6
Comments
Aniket Yadav 7-Mar-12 4:19am    
Can You Post your VB Sample Code Here. If so then please.
I didn't get what you want to do
Aniket Yadav 7-Mar-12 6:41am    
Please post in a proper tag. Very difficult to understand
Prasad_Kulkarni 8-Mar-12 3:08am    
updated as much i can,do it proper next time sadhana4

1 solution

Conversion from VB code to C# is very usual practice. Please see this [^]could help you. Also you can search you can find lots of online converters which can help on this.
 
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