问题描述
我想使用windows窗体填充word文档(即让用户在windows窗体中输入文本到文本框中(即textbox1)然后单击提交并让应用程序打开我创建的word文档,并使用书签(即bookmark1)将用户文本放入表单域中。
得到下面代码
-------------------------------- ---------
Hi,
I would like to populate a word document using a windows form (i.e. have a user enter text into a textbox in windows form (i.e. textbox1) and then click submit and have the application open a word document that I have created and place the users text into a form field using a bookmark (i.e. bookmark1).
got below code
-----------------------------------------
Imports Microsoft.Office.Interop
Public Class Form1
Dim wordapp As Word.ApplicationClass
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'open word document
wordapp = New Word.Application
Dim objdoc As Word.Document = wordapp.Documents.Open("c:\test")
'go to bookmark
wordapp.Selection.GoTo(What:=Word.WdGoToItem.wdGoToBookmark, Name:="Bookmark_Name")
' enter text from textbox
wordapp.Selection.TypeText(TextBox1.Text)
'make document visible
wordapp.Visible = True
End Sub
End Class
----------------------------------------------- -------
我正在使用c#。我想用c#编写代码。
请帮助。
------------------------------------------------------
I am using c#. I want to write code in c#.
Please help.
推荐答案
这篇关于Windows窗体和Word自动化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!