Excel合并在本地系统中工作,但在IIS中不工作 [英] Excel Merging Working in Local System but not Working in IIS

查看:86
本文介绍了Excel合并在本地系统中工作,但在IIS中不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在这里的代码,我正在将文件从源文件夹合并到目标文件夹...

它在本地计算机上正常工作,但是当我在IIS服务器中托管它时,合并没有发生

我已经完全控制了IIS中的相应文件夹

请给我一些有价值的建议以解决此问题?




This is my code here I am merging Files from a source Folder into a Destination Folder...

Its working Correctly in local machine but when i hosted it in IIS server Merging is not Happening

I have given full control for the corresponding folders in IIS

Please give me some valuable suggetions to fix this problem?




private void Merge(string strSourceFolder, string strDestinationFile)
        {
            try
            {
                object missing = System.Reflection.Missing.Value;
                Microsoft.Office.Interop.Excel.ApplicationClass ExcelApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
                ExcelApp.Visible = false;
               
                Microsoft.Office.Interop.Excel.Application appExcel = new Microsoft.Office.Interop.Excel.ApplicationClass();
               
                //Create destination object
                Microsoft.Office.Interop.Excel.Workbook objBookDest = ExcelApp.Workbooks.Add(missing);
                objBookDest.UserControl = true;
               
                foreach (string filename in Directory.GetFiles(strSourceFolder))
                {
                    //string filename1;
                    
                    if (File.Exists(filename))
                    {                    
                      
                        Microsoft.Office.Interop.Excel.Workbook objBookSource = ExcelApp.Workbooks._Open
                        (filename, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing
                        ,Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);


                        //Browse through all files.
                        foreach (Microsoft.Office.Interop.Excel.Worksheet sheet in objBookSource.Worksheets)
                        {

                            string Sheetname = sheet.Name.ToLower();
                            //sheet.Name = Sheetname.Substring(1);

                            sheet.Copy(Type.Missing, objBookDest.Worksheets[objBookSource.Worksheets.Count]);
                            objBookSource.Close(Type.Missing, Type.Missing, Type.Missing);
                            objBookSource = null;
                        }

                    }

                }

                foreach (string filename1 in Directory.GetFiles(Server.MapPath("~\\MergeReports\\")))
                {
                    if (File.Exists(filename1))
                    {
                        File.Delete(strDestinationFile);
                        break;
                    }
                }

             


                objBookDest.SaveAs(strDestinationFile, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, myExcel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
                 objBookDest.Close(Type.Missing, Type.Missing, Type.Missing);


                objBookDest = null;
                ExcelApp = null;

                string[] filePaths = Directory.GetFiles(Server.MapPath("~\\Merge\\"));
                foreach (string filePath in filePaths)
                    File.Delete(filePath);
            }
            catch (System.Exception e)
            {
                objException = new BaseException(BasePage.GetCurrentUser.UserID.ToString(), e);
            }
        }

推荐答案

Interop是excel.exe的接口.本地系统可以访问C:/程序文件,但是IIS具有自己的目录结构.我认为您可以将IIS配置为在其目录结构中包含C:/program文件.我只是不知道如何.
The Interop is an interface to the excel.exe. The local system can access C:/program files but the IIS has its own directory structure. I think you can configure the IIS to include C:/program files in its directory structure. I just don''t know how.


首先,您必须授予Excel应用程序的权限.....
在Dcom Config中.....


http://social.msdn.microsoft.com /Forums/zh-CN/Vsexpressvb/thread/b6388275-b295-4e55-8c25-6d8788eac1ca/ [
在高级"属性中,如果它的值为false,则必须启用32位应用程序为true....
First of all you have to give Permission for Your Excel Application.....
in Dcom Config.....


http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvb/thread/b6388275-b295-4e55-8c25-6d8788eac1ca/[^]


Here They have Explained Every thing about Permissions...



In IIS Default Application pool You Have to set Identity into network Service

and In Advanced properties we have to enable 32 bit application into true if its false....


这篇关于Excel合并在本地系统中工作,但在IIS中不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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