1. VB,NET 如何把WORD另存为HTML
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'定义Word对象
Dim wordApp As New Word.ApplicationClass
'要转换的文件名
Dim fileName As Object = "E:\Test.doc"
'默认值
Dim miss As Object = System.Reflection.Missing.Value
'打开要转换的 DOC 文件
Dim doc As Word.Document = DirectCast(wordApp.Documents.Open(fileName, miss, miss, miss, miss, miss, _
miss, miss, miss, miss, miss, miss, _
miss, miss, miss, miss), Word.Document)
'转换后的文件名
fileName = "E:\testDoc.HTML"
'保存的文件格式
Dim saveFormat As Object = Word.WdSaveFormat.wdFormatHTML
'按文本文件保存
doc.SaveAs(fileName, saveFormat, miss, miss, miss, miss, _
miss, miss, miss, miss, miss, miss, _
miss, miss, miss, miss)
'关闭是否保存文件,这里为不保存
Dim changes As Object = False
'关闭文件
doc.Close(changes, miss, miss)
'退出 Word 应用程序
wordApp.Quit(changes, miss, miss)
End Sub
2. 怎样在VB中输出word文档
Dim WordApp As Word.Application'定义word应用变量
Dim newDoc As Word.Document'定义word文档变量
Set WordApp = CreateObject("Word.Application")'创建新的word应用
WordApp.Visible = True
With WordApp
Set newDoc = .Documents.Add(App.Path &; "\报告单\食品水质报告.Doc")'在创建的word应用中新建一个新的word文档
With .Selection
.GoTo wdGoToBookmark, , , "bh" bh为word文档中的对应位置的标签名
.TypeText PrnBID'写内容
.GoTo wdGoToBookmark, , , "GoodsName" 'GoodsName为word文档中的对应位置的标签名
.TypeText PrnGName'写内容
Set MyRS = Nothing
End With
' newDoc.SaveAs FileName:=FilePath
End With
' If theError = 429 Then WordApp.Quit
Set WordApp = Nothing
在事先做好的word文档中要写内容的位置设定好标签,然后在程序中找到标签,再写入数据
3. vb的内容如何导出到word中
先用word建立一个“模板”,把该画的表格和格式设置好,然后调出“窗体”工具栏,在你想要接收vb传来数值的位置加入“文本型窗体域”(就是文本框),在“窗体”工具栏上把“域底纹”点一下把域的底纹去掉,要不然不好看。
加入域的时候记得要为每个“域”的属性里“书签”命名(其实就是相当于vb中的“名称”),保存退出(假设为c:doc1.doc)。在vb中新建工程并引用Microsoft Word x Object Library,在窗体中加入与word中域相对应的文本框,加一个command,加入类似以下的代码(我只用了一个文本框做例子,你自己再扩展一下吧):Private Sub Command1_Click()Dim doc1 As Word.ApplicationSet doc1 = New Word.Applicationdoc1.Documents.Open ("c:doc1.doc")doc1.ActiveDocument.FormFields("text1").Result = Text1.Textdoc1.ActiveDocument.Savedoc1.Documents.CloseSet doc1 = NothingEnd Sub这样一来,我就把窗体中text1中的text值传入到了名为doc1.doc的word文件中。
4. VB.NET RichTextBox 保存为 Word文档
将Word文档嵌入到WinForm窗体显示Word文档内容private void 打开ToolStripMenuItem_Click(object sender, EventArgs e){OpenFileDialog P_GetFile = new OpenFileDialog();//创建打开文件对话框对象DialogResult P_dr = P_GetFile.ShowDialog();//显示打开文件对话框if (P_dr == DialogResult.OK)//是否点击确定{WebBrowser.Navigate(P_GetFile.FileName);//打开Word文档并显示}}//在Word文档中插入图片private void btn_New_Click(object sender, EventArgs e){btn_New.Enabled = false;//停用新建按钮ThreadPool.QueueUserWorkItem(//使用线程池(P_temp) =>//使用lambda表达式{G_wa = new Word.Application();//创建Word应用程序对象Word.Document P_wd = G_wa.Documents.Add(//建立新文档ref G_missing, ref G_missing, ref G_missing, ref G_missing);Word.Range P_Range = P_wd.Paragraphs[1].Range;//得到段落范围object P_Ranges = P_Range;//创建ojbect对象P_wd.InlineShapes.AddPicture(//向文档中插入图片G_OpenFileDialog.FileName, ref G_missing, ref G_missing, ref P_Ranges);G_str_path = string.Format(//计算文件保存路径@"{0}\{1}", G_FolderBrowserDialog.SelectedPath,DateTime.Now.ToString("yyyy年M月d日h时s分m秒fff毫秒") + ".doc");P_wd.SaveAs(//保存Word文件ref G_str_path,ref G_missing, ref G_missing, ref G_missing, ref G_missing,ref G_missing, ref G_missing, ref G_missing, ref G_missing,ref G_missing, ref G_missing, ref G_missing, ref G_missing,ref G_missing, ref G_missing, ref G_missing);((Word._Application)G_wa.Application).Quit(//退出应用程序ref G_missing, ref G_missing, ref G_missing);this.Invoke(//开始执行窗体线程(MethodInvoker)(() =>//使用lambda表达式{btn_Display.Enabled = true;//启用显示按钮MessageBox.Show("成功创建Word文档!", "提示!");}));});}。
5. vb.net怎么对word进行操作
不清楚报错信息,只能给以下提示:
1、工程--引用,选Microsoft Word 11.0 Object Library
2、声明并赋值word程序相关变量,注意步骤不能乱。
Dim appObj As New Word.Application '新建一个word程序对象
Dim docObj As Word.Document '声明文档对象,也可以用new新建
Dim strFile As String = "D:\MyDocu.doc"
docObj = appObj.Documents.Open(strFile, False, False, False, "", "", False, "", "", , False, False, False) '打开文档
docObj.Activate()'激活文档
。.
With docObj
.Save()
.Close()
End With
docObj = Nothing
appObj = Nothing
注意:声明word对象和文档对象,应该提示错误,你只需要点击“示警”图标,在展打的选项里选第1项导入就可以了。
转载请注明出处51数据库 » vb.net导出word