word转html

小程序员 2013-11-27 05:01:15
做了一个word转html的页面,使用office组件做的,本地调试没问题,部署到iis上本地也没问题,别人的电脑上传word过来的时候我电脑就跳出这个东西了,这个要怎么解决???(这个我手动选择后程序可以继续下去,没问题)
...全文
149 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
小程序员 2013-11-27
  • 打赏
  • 举报
回复
感谢3楼大神,膜拜,搞掂了
小程序员 2013-11-27
  • 打赏
  • 举报
回复
引用 3 楼 liuchaolin 的回复:
改用线程
好,我试试,谢谢
md5e 2013-11-27
  • 打赏
  • 举报
回复
改用线程

<%@ 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;
        }
    }

}
小程序员 2013-11-27
  • 打赏
  • 举报
回复
word版本和权限这个已经弄好了
  • 打赏
  • 举报
回复
1.看下word版本之类的 2.看下权限

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧