不是读取, 是将html写入到word文档

解决方案 »

  1.   

    http://blog.csdn.net/educast/article/details/4420111希望对你有帮助。
      

  2.   

    没有html转word, 再来个高手吧!
      

  3.   

    msdn search office automation
      

  4.   

    这个还不简单啊 你直接用C#读取html文件里面的内容然后在生成word文件不就好了,把读取的内容添加到要生成的文件里面去你生成文件的时候生成doc后缀的文件不就是word文档了吗
      

  5.   


    html格式无法直接用代码添加到word文件里的。如果你真正试过, 真正自己写过相关的代码就知道。
      

  6.   

    把代码贴给你吧/// <summary>
        /// 写入文件
        /// </summary>
        /// <param name="Path">文件路径</param>
        /// <param name="Text">写入内容</param>
        /// <param name="Coding">文件编码</param>
        public static void Writer(string Path, string Text, string Coding)
        {
            if (File.Exists(Path))
            {
                Delete(Path);
            }
            try
            {
                sw = new StreamWriter(Path, false, Encoding.GetEncoding(Coding));
                sw.WriteLine(Text);
                sw.Flush();
                sw.Close();
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
        }
    三个参数中路径是物理路径
    比如你要生成word文档
    就写d:/aaa.doc
    要写入的内容
    就是你要保存的html标签
    编码格式就是字符编码,可以是GB2312或者是utf-8
      

  7.   

    你要把<和>替换掉就可以了
      

  8.   

    找到解决办法了还是我刚才的代码/// <summary>
        private static StreamReader sr;
        private static StreamWriter sw;
        /// 读取文件
        /// </summary>
        /// <param name="Path">文件路径</param>
        /// <param name="Coding">文件编码</param>
        /// <returns></returns>
        public static string Reader(string Path, string Coding)
        {
            string str = "";
            if (File.Exists(Path))
            {
                try
                {
                    sr = new StreamReader(Path, Encoding.GetEncoding(Coding));
                    str = sr.ReadToEnd();
                    sr.Close();
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message, e);
                }
            }        return str;
        }    /// <summary>
        /// 写入文件
        /// </summary>
        /// <param name="Path">文件路径</param>
        /// <param name="Text">写入内容</param>
        /// <param name="Coding">文件编码</param>
        public static void Writer(string Path, string Text, string Coding)
        {
            if (File.Exists(Path))
            {
                Delete(Path);
            }
            try
            {
                sw = new StreamWriter(Path, false, Encoding.GetEncoding(Coding));
                sw.WriteLine(Text);
                sw.Flush();
                sw.Close();
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
        }    /// <summary>
        /// 删除文件
        /// </summary>
        /// <param name="Path">文件路径</param>
        public static void Delete(string Path)
        {
            if (File.Exists(Path))
            {
                try
                {
                    File.Delete(Path);
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message, e);
                }
            }
        }
    调用Writer方法传入写入内容参数的时候你在外面进行编码比如
    Writer("d:/aa.doc", Server.HtmlEncode(Reader("d:/webwz/im/HTMLPage.htm","gb2312")),"gb2312");
      

  9.   


    辛苦了, 不过你可以试试——把一个html文件直接改名为 xxx.doc, 是否可以正常打开?
      

  10.   

    拜托  两者不能混为一谈好不  你没认真看我的代码我把html标签用代码读出来之后用Server.HtmlEncode进行编码把编码之后的内容写入文件路面就可以打开了  内容也都正常只不过尖括号变成了代码等你要用的时候在读取进行解密就完全OK了啊
      

  11.   


    确实不行的, 哥们。 html与word格式区别很大, 直接写入到docx不现实……
      

  12.   

    //Aspose.Words.Document d = new Aspose.Words.Document("C:\\Users\\Administrator\\Desktop\\土地资源数据说明示例.doc");
    //Aspose.Words.Document d = new Aspose.Words.Document("c:\\1.doc");
    //d.Save("c:\\1.html", Aspose.Words.SaveFormat.Html);试试
      

  13.   


    确实支持, 但并没有将html转存word的功能
      

  14.   

    一般你问人家, 最好点一下右下角的引用……
    如果你给我留言, 最好是复制一下贴子的地址……这个没有什么很好太好的办法…… 你可以参考下我的文章:
    http://blog.csdn.net/yenange/article/details/8858817