首页 新闻 会员 周边

在程序中,增加了一个统计上传的word文档字数的功能,程序更新后,在外网上隔断时间就报错,内网中完全没错

0
[待解决问题]
//文件字数的统计

            wordApp = new Word.Application();
            object missing = System.Reflection.Missing.Value;


            string path = Server.MapPath("~") + "\\upfile\\";

            IFileManageService fms = SpringContext.GetObject<IFileManageService>("FileManageService");
            IList<Attachment> aa = fms.GetAttachmentsByRecId(Id.Text + "-1");
            string p = "";
            foreach (Attachment a in aa)
            {
                p = path + a.RelativePath + a.FileName;
            }


            object openFileName = p;

            object readOnly = true;
            object isVisible = false;
            object saveChangeFalse = false;

            // 创建 Word Application
            //Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();

            Word.Document wordDocument = null;

            wordDocument = wordApp.Documents.Open(ref openFileName,

            // 打开 Word 文档
                //Microsoft.Office.Interop.Word.Document wordDocument = wordApp.Documents.Open(ref openFileName,
              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);

            wordDocument.Activate();

            // 调用“字数统计”对话框对象
            //Microsoft.Office.Interop.Word.Dialog wdlg = wordApp.Dialogs[Microsoft.Office.Interop.Word.WdWordDialog.wdDialogToolsWordCount];
            Word.Dialog wdlg = wordApp.Dialogs[Word.WdWordDialog.wdDialogToolsWordCount];
            wdlg.Execute();

            System.Type dlgType = typeof(Word.Dialog);

            // 字数
            object oo = dlgType.InvokeMember("Words",
              System.Reflection.BindingFlags.GetProperty |
                System.Reflection.BindingFlags.Public |
                System.Reflection.BindingFlags.Instance,
              null,
              wdlg,
              null);

            int x = Convert.ToInt32(oo.ToString().Replace(",", ""));

            FontNum.Text = x.ToString();

            // 字符数(不计空格)
            oo = dlgType.InvokeMember("Characters",
              System.Reflection.BindingFlags.GetProperty |
                System.Reflection.BindingFlags.Public |
                System.Reflection.BindingFlags.Instance,
              null,
              wdlg,
              null);
            int y = Convert.ToInt32(oo.ToString().Replace(",", ""));

            // 字符数(计空格)
            oo = dlgType.InvokeMember("CharactersIncludingSpaces",
              System.Reflection.BindingFlags.GetProperty |
                System.Reflection.BindingFlags.Public |
                System.Reflection.BindingFlags.Instance,
              null,
              wdlg,
              null);
            int z = Convert.ToInt32(oo.ToString().Replace(",", ""));

            // 关闭 Word文档, 终止 Word Application
            wordDocument.Close(ref saveChangeFalse, ref missing, ref missing);
            wordApp.Quit(ref saveChangeFalse, ref missing, ref missing);
c#
lucy菜鸟的主页 lucy菜鸟 | 初学一级 | 园豆:194
提问于:2013-06-23 21:27
< >
分享
所有回答(2)
0

问题解决了吗?我也遇到这样的问题了,真不知道怎么弄啊,大神能帮帮吗?我的QQ  516383992

流编程风 | 园豆:151 (初学一级) | 2014-05-13 16:25

--配置问题(计算机)

当程序运行出现下面的错误:
  检索COM类工厂中CLSID为{000209FF-0000-0000-C000-000000000046}的组件时失败,原因是出现以下错误:80070005.

解决方法:

1.控制面板--〉管理工具--〉组件服务--〉计算机--〉我的电脑--〉DCom配置--〉找到Microsoft Word文档
之后
单击属性打开此应用程序的属性对话框 

2.单击标识选项卡,然后选择交互式用户。

3.单击“安全”选项卡,分别在“启动和激活权限”和“访问权限”组中选中“自定义”,然后
自定义--〉编辑--〉添加ASP.NET账号和IUSER_计算机名
**这些账号仅在计算机上安装有iis的情况下才存在。

4.确保允许每个用户访问,然后单击确定。

5.单击确定关闭DCOMCNFG。

如果上述方法不能解决问题,就应该是权限问题,请尝试用下面的方法:
在web.config中使用省份证模拟,在<system.web〉节中加入<identity impersonate="true" userName="你的用户名" password="密码" /> </system.web>

支持(0) 反对(0) lucy菜鸟 | 园豆:194 (初学一级) | 2014-07-26 20:14

@lucy菜鸟: 自定义的时候找不到   ASP.NET账号  ,电脑装有 IIS ,我的系统就是在IIS 上架着的

支持(0) 反对(0) 流编程风 | 园豆:151 (初学一级) | 2014-07-30 11:15
0

您好,请问这个问题解决了没,我也遇到了问题,能否想互交流下。

路遥方知阔 | 园豆:156 (初学一级) | 2017-09-24 19:27
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册