页数计数时出错 [英] Error while doing page count

查看:110
本文介绍了页数计数时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我将Web应用程序部署到服务器后,遇到这样的情况,我在执行word doc页面计数时出现这样的错误.

Hi all

I have come up with a situation which gives me an error like this while doing word doc page count once I deployed my web application to the server.

Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

当我尝试上载word文档并进行页面计数时,出现上述错误.这里是我用于计数文档页面的代码...

When I try to upload a word doc and do the page count the above error appears.Here the code that I am using for count doc pages...

else if (extension == ".DOC" || extension == ".doc" || extension == ".docx")
                                {

                                    Microsoft.Office.Interop.Word.ApplicationClass WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
                                    

                                    // give any file name of your choice. 
                                    string tempath = numberofpage;
                                    RegexOptions options = RegexOptions.None;
                                    Regex regex = new Regex(@"[ ]{2,}", options);
                                    tempath = regex.Replace(tempath, @"");
                                    tempath = tempath.Replace(" \\", "\\");
                                    object fileName = tempath;
                                    object readOnly = false;
                                    object isVisible = true;

                                    //  the way to handle parameters you don't care about in .NET 
                                    object missing = System.Reflection.Missing.Value;
                                    object objDNS = Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges;

                                    //   Make word visible, so you can see what's happening 
                                    //WordApp.Visible = true; 
                                    //   Open the document that was chosen by the dialog 
                                    Microsoft.Office.Interop.Word.Document aDoc = WordApp.Documents.Open(ref fileName,
                                                            ref missing, ref readOnly, ref missing,
                                                            ref missing, ref missing, ref missing,
                                                            ref missing, ref missing, ref missing,
                                                                ref missing, ref isVisible);

                                    Microsoft.Office.Interop.Word.WdStatistic stat = Microsoft.Office.Interop.Word.WdStatistic.wdStatisticPages;
                                    count = aDoc.ComputeStatistics(stat, ref missing);

                                    WordApp.Quit(ref objDNS, ref missing, ref missing);

                                    aDoc = null;

                                    WordApp = null;

                                    GC.Collect();

                                }

推荐答案

成员9291223写道:
Member 9291223 wrote:

但这很好用在本地机器上.部署后出现了问题.

But this works fine in local machine. Issues came after deployment.

好,那并不奇怪.仅当安装了匹配版本的Office Office Interop程序集时,Office Interop才起作用. (在您的情况下,可能只是与Word相关的部分.)事实是Interop程序集已安装在本地GAC中,因此您可以构建产品,而事实是,安装了匹配版本的Office也可以使您运行自己的产品.本地计算机上的应用程序.在部署它的主机上,情况并非如此……

符合逻辑,不是吗?

—SA

OK, then it is no so strange. Office Interop works only when matching versions of Office an Office Interop assemblies are installed. (In your case, it could be just the Word-related part.) The fact the Interop Assembly was installed in your local GAC allowed you to build your product, and the fact that the matching version of Office is installed allowed you to run your application on a local machine. On the host where you deployed it, it could not be the case…

Logical, isn''t it?

—SA


这篇关于页数计数时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆