Windows窗体和Word自动化 [英] Windows Forms and Word Automation

查看:112
本文介绍了Windows窗体和Word自动化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我想使用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.

推荐答案

在我的过去的答案,我建议一些非常好的方法从VB.BET转换为C#,反之亦然。有类似解决方案和非常全面的离线解决方案:

C#到VB.NET的COde行解释 [ ^ ],

需要VB代码转换为C# [ ^ ],

FixedPage to ContentPage将c#代码转换为vb.net [ ^ ]。



-SA
In my past answers, I suggested some really good ways to translate from VB.BET to C# and visa versa automatically. There are both on-like solution and a really comprehensive off-line solution:
COde Line Interpretatio of C# to VB.NET[^],
Need to convert vb code to c#[^],
FixedPage to ContentPage convert c# code into vb.net[^].

—SA


这篇关于Windows窗体和Word自动化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆