Windows窗体书签 [英] windows form bookmark
问题描述
我正在寻求有关如何从DataSet中填充Word 2003模板,以正确格式插入书签以及如何访问书签集合的帮助.书签插入指向收件人的位置以及名称和地址. .i有2或3个表,并且我填充了具有不同字段的数据集.比该字段必须填充
到模板文件.在此字段中,我必须设置书签名称和位置.如何在C#Windows窗体中做到这一点?
如何使用不同的字段进行数据设置并使用书签填充模板文件??
请帮助我,我有VB 6代码,但是在C#Windows窗体中我不怎么做?
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" '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
推荐答案
此 [
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.
这篇关于Windows窗体书签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!