使用vb.net从多个doc文件中检索内容并保存到新的doc文件中 [英] retrieving contents from multiple doc file and saving to a new doc file using vb.net

查看:82
本文介绍了使用vb.net从多个doc文件中检索内容并保存到新的doc文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个新的.doc文件,在编码部分读取了一个doc文件并将其写入新的doc文件中...

我如何继续读取多个doc文件的操作并将其写入新的doc文件.....

hi , i had created a new .doc file, in the coding part a single doc file is readed and writed to the new doc file ...

how can i continue the operation for reading multiple doc file and write it to a new doc file .....

 Imports System.Windows.Forms
Imports word = Microsoft.Office.Interop.Word
Imports Microsoft.Office.Interop.Word
Imports System.Runtime.InteropServices

Public Class Form1
    Dim flb As New System.Windows.Forms.FolderBrowserDialog
    Dim fod As OpenFileDialog = New OpenFileDialog()
    Dim objapp As New word.Application
    Dim objdoc As New word.Document
    Dim object1 As Object
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        flb.RootFolder = Environment.SpecialFolder.MyComputer
        flb.ShowNewFolderButton = False
        Dim result As DialogResult = flb.ShowDialog
        If (result = DialogResult.OK) Then
            ListBox1.Items.Clear()
            TextBox1.Text = flb.SelectedPath
            For Each filename In Directory.GetFiles(flb.SelectedPath, "*.doc").Union(Directory.GetFiles(flb.SelectedPath, "*.rtf").ToArray())
                             
            Next
        End If
    End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
 Call readandwrite()

    End Sub
    Sub readandwrite()

        Dim missing As Object = System.Reflection.Missing.Value
        Dim oFals As Object = False
        Dim oTru As Object = True
        
        Dim obj1 As Object
        obj1 = TextBox1.Text & "\sam1"


         Try
        objapp = New word.Application
        objdoc = New word.Document

        If ListBox1.Items.Count > 0 Then

            For i As Integer = 0 To ListBox1.Items.Count - 1
                Dim obj As Object = ListBox1.Items(i)
                
                objdoc = objapp.Documents.Open(obj, missing, oTru, missing)
                objapp = New word.Application
                objdoc = New word.Document

                objdoc = objapp.Documents.Add(obj)
                
                objdoc.SaveAs(obj1)

              

                objdoc.Activate()
                objdoc.Close()
                objapp.Quit()


                objdoc = Nothing
                objapp = Nothing

            Next



        End If
        Catch ex As Exception
         MsgBox("read error")
         End Try

    End Sub

推荐答案

步骤1->在文件打开对话框(设置属性Multiselect = true)中创建一个循环(foreach),该循环将迭代所选文件的数量.

2->在此循环中编写文件读取代码,使用循环的迭代变量中的文件名.

3->在读取代码下方编写您的新文件创建和编写代码(仅在循环内)

4->循环结束.


按照链接查看示例

http://msdn.microsoft.com/en-us/library/system.windows.forms.openfiledialog.multiselect.aspx [ ^ ]

标记为答案(如果有帮助的话,它会激发您的兴趣):)
step 1 -> create a loop (foreach), which will iterate for number of files you have selected, in file open dialogue box (set property Multiselect = true).

2 -> write your file reading code inside this loop, use the filename from the iteration variable of your loop.

3-> write your new file creation and writing code below the reading code (inside the loop only)

4 -> end of loop.


follow the link to see the example

http://msdn.microsoft.com/en-us/library/system.windows.forms.openfiledialog.multiselect.aspx[^]

mark as answer if helps you, it motivates :)


这篇关于使用vb.net从多个doc文件中检索内容并保存到新的doc文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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