try
        {    }
        catch (Exception ex)
        {
            throw new Exception(ex.Message);
        }
        finally
        { }
等去掉试试,应该会报错的吧

解决方案 »

  1.   

    感谢您的回复,我刚试了下,去掉那个不进行实例化也是这样的问题,要全部去掉才行。我在网上看到有说office组件需要访问网络,但我这个必须在局域网下使用,大湿有好办法吗
      

  2.   

    是不需要访问网络的,看看你的权限设置没有,还有就是office是否已损坏
      

  3.   

    这个是之前写的,用线程操作<%@ WebHandler Language="C#" Class="ajaxWordToHtml" %>using System;
    using System.Web;
    using System.Threading;
    public class ajaxWordToHtml : IHttpHandler
    {    private static object _lock = new object();
        string docPath = string.Empty;
        string htmlPath = string.Empty;
        bool Flang = false;
        string Message = string.Empty;    [STAThread]
        private void _Import()
        {        object o = Type.Missing;        try
            {            Word.Application app = new Word.Application();
                app.Visible = false;
                object docFile = docPath;
                object readOnly = true;
                object fileName = htmlPath;
                /*office 2003 begin
                Word.Document doc = app.Documents.Open(ref docFile, ref o, ref readOnly, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o);
                object format = Word.WdSaveFormat.wdFormatFilteredHTML;
                doc.SaveAs(ref fileName, ref format, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o);
                //office 2003 end*/            //* offic 2000 begin
                Word.Document doc = app.Documents.Open(ref docFile, ref o, ref readOnly, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o);
                object format = Word.WdSaveFormat.wdFormatHTML;
                doc.SaveAs(ref fileName, ref format, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o);
                doc.Close(ref o, ref o, ref o);
                app.Quit(ref o, ref o, ref o);            //*/            //WordToHtml.ConvertToHtml(docPath, htmlPath);
                Flang = true;
                Message = "已成功生成!";
                return;
            }
            catch (Exception error)
            {
                Flang = false;
                Message = error.Message;
                return;
            }
            finally
            {
                GC.Collect();
            }
        }    public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/html";
            docPath = HttpContext.Current.Request["docPath"];
            htmlPath = HttpContext.Current.Request["htmlPath"];
            if (!string.IsNullOrEmpty(docPath) && !string.IsNullOrEmpty(htmlPath))
            {
                lock (_lock)
                {
                    docPath = HttpContext.Current.Server.MapPath("/docfile/" + docPath);
                    htmlPath = HttpContext.Current.Server.MapPath("/htmlfile/" + htmlPath);
                 Thread _thread = new Thread(new ThreadStart(_Import));
                  _thread.Name = "ajaxWordToHtml";
                  _thread.SetApartmentState(ApartmentState.STA);
                  _thread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
                  _thread.Start();
                  TimeSpan ts = new TimeSpan(0, 0, 0, 30);
                  _thread.Join();
                  context.Response.Write(Flang);
                  context.Response.Write(Message);
                }
            }
            else
            {
                Flang = false;
                Message = "提交的参数不正确";
            }
        }    public bool IsReusable
        {
            get
            {
                return false;
            }
        }}
      

  4.   

    一般生成xls doc这类东西  我都不用微软的东西..环境,进程,权限 太多太多的问题...所以 一般都用什么asponse.words,myxls之类的插件..
      

  5.   

    ,我今天换成这种组件后,还是不行,真无语了,我的是内网,但下面几种情况是没这个问题的,1、把网络禁止了2、用web应用,不用Winform或者控制台程序3、外网可以。各位有遇到过这种神奇状况吗
      

  6.   

    结贴了,总算解决了,太纠结了。net框架用4.0就行了