非哥
问个问题
我要把word文档中的内容读取出来
在页面上显示
怎么实现啊

解决方案 »

  1.   


    using System;
    using System.IO;
    using System.Collections;
    namespace TextFileReader_csharp
    {
        /// <summary>
        /// Summary description for Class1.
        /// </summary>
        class Class1
        {
            static void Main(string[] args)
            {
                StreamReader objReader = new StreamReader("c:\\test.doc");
                string sLine = "";
                ArrayList arrText = new ArrayList();
                while (sLine != null)
                {
                    sLine = objReader.ReadLine();
                    if (sLine != null)
                        arrText.Add(sLine);
                }
                objReader.Close();
                foreach (string sOutput in arrText)
                    Console.WriteLine(sOutput);
                Console.ReadLine();
            }
        }
    }
      

  2.   

    可以利用office组件
    http://topic.csdn.net/t/20040102/11/2625860.html
      

  3.   

    我们之前项目用一个类似于word的控件,但是是收费的,可以很方便的读取word的内容,然后在网页中打开后,可以随意编辑,保存。
      

  4.   


    我读取出来时乱码  public void ReadWord()
        {
          
           DataTable DT=DownMethod.GetDataByID(1,"ZJDownload");
           //文件路径
           path = DT.Rows[0][1].ToString();
           StreamReader objReader = new StreamReader(path);
           string sLine = "";
           ArrayList arrText = new ArrayList();
           while (sLine != null)
           {
               sLine = objReader.ReadLine();
               if (sLine != null)
                   arrText.Add(sLine);
           }
           objReader.Close();
           foreach (string sOutput in arrText)
               TextBox1.Text += sOutput;
           //    Console.WriteLine(sOutput);
           //Console.ReadLine();    }
      

  5.   

    恩,这种方式只能读取文字,有图片或是表格就乱码。你参考一个这个吧 http://liuway.javaeye.com/blog/431535
      

  6.   

    public bool Open(string strFileName)   
            {   
                return this.Open(strFileName, true);   
            }   你主要是调用这个函数就可以了
      

  7.   

    用控件吧
      千航的不错,可惜收费google那个在线文档好像也是可以读取/保存word的  不知道咋弄的
      

  8.   

    叶子
    能不能把
    word转换为pdf
    然后在页面中读取出来了
      

  9.   

    我回来了,这个可以你看看这个
    http://blog.hoyai.com/?p=16
      

  10.   

    打开word获取内容
    string path=Server.MapPath("a.doc"); 
       FileInfo file=new FileInfo(path);
       FileStream myfileStream=new FileStream(path,FileMode.Open,FileAccess.Read);
       byte[] filedata=new Byte[file.Length]; 
       myfileStream.Read(filedata,0,(int)(file.Length));
       myfileStream.Close(); 

    Word.Application app = new Microsoft.Office.Interop.Word.Application(); 
    Word.Document doc = null; 
    WORD生成PDF
    参考
    word在线编辑可使用
    office 编辑器 
    如DSOFramer,officecontrol.cab 
      

  11.   

    就想excel表格那样
    万一不行
    纯文本怎么弄
      

  12.   

    纯文本用js 读取 然后输出就可以了。excel表格那样  指的是什么样 
      

  13.   

    就是表格啊
    例如
      姓名  性别 年龄 备注...
      aa    男   34   dfada
      bb    女   25   dfsfs这样的非哥你说的
    纯文本JS读取怎么实现啊
      

  14.   


    <html>
    <div id='div'>
    </div>
    <input type="button" value="读取Word" onclick='readWord();' />
    </html>
    <script language="javascript">
    function readWord()
    {
      var WordApp,WordDoc,str;
      WordApp = new ActiveXObject("Word.application");
      WordDoc = WordApp.Documents.Open("C:\\a.doc");
      str=WordDoc.content.text;
      WordDoc.close();
      WordApp.quit();
      document.getElementById('div').innerHTML=str;
    }
    </script> 
      

  15.   

    网页错误详细信息用户代理: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)
    时间戳: Mon, 9 Nov 2009 08:31:00 UTC
    消息: Automation 服务器不能创建对象
    行: 10
    字符: 3
    代码: 0
    URI: http://localhost:1607/WebSite4/jquery/HTMLPage13.htm
    消息: Automation 服务器不能创建对象
    行: 10
    字符: 3
    代码: 0
    URI: http://localhost:1607/WebSite4/jquery/HTMLPage13.htm
      

  16.   

      WordApp = new ActiveXObject("Word.application");
    我看了下
    是这个地方有问题
      

  17.   

    来个C# 版本的
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <asp:Literal ID="lit" runat="server"></asp:Literal>
        </form>
    </body>
    </html>
    protected void Page_Load(object sender, EventArgs e)
        {
            
            lit.Text = GetText(Server.MapPath("a.doc"));
                }    public string GetText(string fileName)
        {
            //实例化COM
            Microsoft.Office.Interop.Word.ApplicationClass wordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
            object fileobj = fileName;
            object nullobj = System.Reflection.Missing.Value;
            //打开指定文件(不同版本的COM参数个数有差异,一般而言除第一个外都用nullobj就行了)
            Microsoft.Office.Interop.Word.Document doc = wordApp.Documents.Open(ref fileobj, ref nullobj, ref nullobj,
                ref nullobj, ref nullobj, ref nullobj,
                ref nullobj, ref nullobj, ref nullobj,
                ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj
                );
            //取得doc文件中的文本
            string outText = doc.Content.Text;
            //关闭文件
            doc.Close(ref nullobj, ref nullobj, ref nullobj);
            //关闭COM
            wordApp.Quit(ref nullobj, ref nullobj, ref nullobj);
            //返回
            return outText;
        }记得引用DLL, 我用的是 12.0 的,11.0 应该也没问题的
      

  18.   

    谢谢
    非哥
    C#版本的可以
    但是js的不可以
      

  19.   

     Sandy 945 的方法确实可以,我验证成功了。连html代码都能读出来。