using System;
using System.Windows.Forms;
using System.IO;using Word = Microsoft.Office.Interop.Word;
using System.Reflection;namespace WordTrue
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
         private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "*.doc|*.doc";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                object miss = System.Reflection.Missing.Value;
                Word.Application word = new Word.ApplicationClass();
                object fileName = ofd.FileName;
                Word.Document doc = word.Documents.Open(ref fileName, ref  miss, ref  miss, ref  miss, ref  miss, ref  miss, ref  miss, ref  miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss);
                string s = doc.Content.Text.ToString();
                s = s.Substring(0, s.IndexOf("\r"));
                s = s.Trim();
                textBox1.Text = s;
                doc.Close(ref miss, ref miss, ref miss);
                word.Quit(ref miss, ref miss, ref miss);
                releaseObj(word);
                //下面添加 word处理代码
            }
         }
        
        private void releaseObj(object obj)
        {
            System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
            obj = null;
            GC.Collect();
        }        private void textBox1_TextChanged(object sender, EventArgs e)
        {
       
        
        
        }
                }
}
代码如上。针对这段代码,每次只能选取一个Word文件,我现在想一下子选取多个文件,也就是在弹出的资源管理器中可以按住Ctrl键选取多个Word文件,在多个textBox标签中一一显示在Word文档中提取所谓字符。请各位修改我的代码后再完整的发上来。还请各位能详细说明一下,在哪里、怎样修改,才能够实现自己想选几个文件就选几个文件。当然那个还要配合textBox标签的多少,希望能多做一下说明。谢谢了啊!

解决方案 »

  1.   

    设置openfiledialog1.Multiselect=true;//多选
    就可以让OpenFileDialog多选文件。。
    取文件名的时候:openfiledialog1.FileNames;即可
      

  2.   

    openFileDialog1.Multiselect = true;
    openFileDialog1.Title = "打开文件";
    if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
                {}
      

  3.   

    openfiledialog1.FileNames
    openfiledialog1.Multiselect=true
    openFileDialog1.Multiselect = true;
    openFileDialog1.Title = "打开文件";
    if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
      {你要的操作写这里}
    以上内容单纯的复制黏贴,不必给分
      

  4.   

    OpenFileDialog ofd = new OpenFileDialog();
                ofd.Multiselect = true;//多选
                ofd.Title = "打开文件";
    我这么写了,确实能在资源管理器中多选了,但是怎么显示所提取的字符还是个问题啊。我只有一个textBox标签,按一下Button标签,在textBox标签中显示的还是一个文档的提取结果,当然只有一个textBox标签话这是必然的,就算多个文档的标题被提取出来了,集中在一个textBox标签中队我来说也没用啊。所以要多拖几个textBox标签,但拖好之后,怎样对应着把标题显示在textBox标签中呢?比如我选中了两个Word文档,那就要有至少两个textBox标签来显示,选中三个文档的话,那就要有至少三个textBox标签来显示。我可以一开始多拖几个textBox标签,选着的文档数只要少于textBox标签数就行了。关键是代码要怎么写呢,因为我是菜鸟,还是希望你们能稍微多花一些时间写具体一点,能让我不要改这改那的之后才能和我的代码对应起来,有时候我知道你们发的这代码是对,但我改来改去就是没法和我的代码对应起来。还请你们能多多帮忙,谢谢了啊!跪谢了!
      

  5.   

    窗口上整一个stackpanel,对读出来的每一个文件,读内容,动态创建一个textbox,赋值,然后添加到stackpanel里面去