• 大小: 127KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-09
  • 语言: 其他
  • 标签:

资源简介

如何在Web页面上做到像SharePoint中的效果一样,能直接激活客户端的Word来打开.doc文件,而不是类似直接点击.doc文档链接时Word在IE中被打开那样。想想这个问题应该很多人都会感兴趣.Web 页面上直接打开、编辑、创建Office文档

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
//using Word;
//using System.Diagnostics;
//using System.Reflection;
using Word = Microsoft.Office.Interop.Word;  


namespace WORD
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender EventArgs e)
        {
            //调用打开文件对话框获取要打开的文件WORD文件,RTF文件,文本文件路径名称
            OpenFileDialog opd = new OpenFileDialog();
            opd.InitialDirectory = “c:\\“;
            opd.Filter = “Word文档(*.doc)|*.doc|文本文档(*.txt)|*.txt|RTF文档(*.rtf)|*.rtf|所有文档(*.*)|*.*“;
            opd.FilterIndex = 1;

            if (opd.ShowDialog() == DialogResult.OK && opd.FileName.Length > 0)
            {

              //建立Word类的实例缺点:不能正确读取表格图片等等的显示
             // Word.Application app = new Word.ApplicationClass();  
              Word.ApplicationClass app = new Word.ApplicationClass();
             
              Word.Document doc = null;

              object missing = System.Reflection.Missing.Value;






              object FileName = opd.FileName;
              object readOnly = false;
              object isVisible = true;
              object index = 0;
              try
              {
                 doc = app.Documents.Open(ref FileName ref missing ref readOnly
                 ref missing ref missing ref missing ref missing ref missing
                 ref missing ref missing ref missing ref isVisible ref missing
                 ref missing ref missing ref missing);

                 doc.ActiveWindow.Selection.WholeStory();
                 doc.ActiveWindow.Selection.Copy();
                 //从剪切板获取数据
                 IDataobject data=Clipboard.GetDataobject();
                 this.richTextBox1.Text=data.GetData(DataFormats.Text).ToString();

               }
               finally
              {
                  if (doc != null)
                  {
                     doc.Close(ref missing ref missing ref missing);
                     doc = null;
                   }

                  if (app != null)
                  {
                      app.Quit(ref missing ref missing ref missing);
                      app = null;
                   }
               }

           }
        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       9216  2009-12-28 22:57  WORD\WORD\bin\Debug\WORD.exe

     文件      22016  2009-12-28 22:57  WORD\WORD\bin\Debug\WORD.pdb

     文件      14328  2009-12-28 23:00  WORD\WORD\bin\Debug\WORD.vshost.exe

     文件        490  2007-07-21 01:33  WORD\WORD\bin\Debug\WORD.vshost.exe.manifest

     文件       2688  2009-12-28 23:01  WORD\WORD\Form1.cs

     文件       2569  2009-12-28 13:40  WORD\WORD\Form1.Designer.cs

     文件       6017  2009-12-28 22:38  WORD\WORD\Form1.resx

     文件     409600  2009-12-28 22:38  WORD\WORD\obj\Debug\Interop.Microsoft.Office.Core.dll

     文件       1115  2009-12-28 23:00  WORD\WORD\obj\Debug\WORD.csproj.FileListAbsolute.txt

     文件        847  2009-12-28 22:38  WORD\WORD\obj\Debug\WORD.csproj.GenerateResource.Cache

     文件        811  2009-12-28 22:38  WORD\WORD\obj\Debug\WORD.csproj.ResolveComReference.cache

     文件       9216  2009-12-28 22:57  WORD\WORD\obj\Debug\WORD.exe

     文件        180  2009-12-28 22:57  WORD\WORD\obj\Debug\WORD.Form1.resources

     文件      22016  2009-12-28 22:57  WORD\WORD\obj\Debug\WORD.pdb

     文件        180  2009-12-28 22:57  WORD\WORD\obj\Debug\WORD.Properties.Resources.resources

     文件        496  2009-12-28 13:32  WORD\WORD\Program.cs

     文件       1428  2009-12-28 13:32  WORD\WORD\Properties\AssemblyInfo.cs

     文件       2837  2009-12-28 13:32  WORD\WORD\Properties\Resources.Designer.cs

     文件       5612  2009-12-28 13:32  WORD\WORD\Properties\Resources.resx

     文件       1089  2009-12-28 13:32  WORD\WORD\Properties\Settings.Designer.cs

     文件        249  2009-12-28 13:32  WORD\WORD\Properties\Settings.settings

     文件       4635  2009-12-28 22:44  WORD\WORD\WORD.csproj

     文件        902  2009-12-28 13:32  WORD\WORD.sln

    ..A..H.     18944  2009-12-28 23:11  WORD\WORD.suo

     目录          0  2009-12-28 13:32  WORD\WORD\obj\Debug\TempPE

     目录          0  2009-12-28 22:57  WORD\WORD\bin\Debug

     目录          0  2009-12-28 22:57  WORD\WORD\obj\Debug

     目录          0  2009-12-28 13:32  WORD\WORD\bin

     目录          0  2009-12-28 13:32  WORD\WORD\obj

     目录          0  2009-12-28 13:32  WORD\WORD\Properties

............此处省略5个文件信息

评论

共有 条评论