inetrop.excel库在服务器上不起作用,但在loacalhost上运行良好 [英] inetrop.excel library not working on server but running fine on loacalhost

查看:114
本文介绍了inetrop.excel库在服务器上不起作用,但在loacalhost上运行良好的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

我在这里遇到一个关键问题.我有一个项目,我们为用户提供功能,可轻松下载或通过电子邮件发送.xls格式的数据. .xls表使用水印,像元宽度等进行了高度修改.问题是代码在本地主机上运行异常,但没有在实时运行.我尝试删除try-catch来设置错误,但我什至没有收到任何错误.当我去下载时,它开始下载,然后在两者之间停止.我首先将文件保存在服务器上的文件夹中,该文件夹具有完全的权限下载.我首先将工作表从数据表写入xls.而不是使用interop excel的com对象,我选择了这个文件进行过氧化处理,将它以diff名称保存在同一文件夹中,然后删除了较旧的文件.这就是全部的工作方式.但是一切都是徒劳的.我需要认真的帮助.今天这要吞噬我的工作.我真的很紧张.我已经尝试了一切.这是我正在使用的一些代码:

Hello all of you !

I am suffering from a crucial problem here. I have a project in which we give users functionality to eider download or email the data in .xls format. The .xls sheet is highly modified using watermarks, cell widths, etc etc. The problem is the code is running amazingly on local host but not on live. I tried removing try-catch to se wats the error still I am not even getting any error. When I go for download it starts downloading and then stops in between. I save the file first on server in the folder name downloads which has full permissions. I first write the sheet from datatable to xls. than using com objects of interop excel I pick this file maodify it save it with a diff name in the same folder and than delete the older one. This is how It all works. But all in vain on live. Plz I need serious help. This is about to gulp my job today. I am really tensed. I have tried everything. here is some code that I am using :

private static string Recreating_Ecxel_WorkSheet(string strWorkOrder, string strDwnload_file_name)
    {
        // Creating Objects.
        object oMissing = System.Reflection.Missing.Value;
        Excel.ApplicationClass xl = new Microsoft.Office.Interop.Excel.ApplicationClass();
        Excel.Workbook xlBook;
        Excel.Worksheet xlSheet;
        Excel.Range range;

        //Accessing Sheet and Image for insertion.
        string laPath = HttpContext.Current.Server.MapPath("~//download//" + strDwnload_file_name + ".xls");
        xlBook = (Workbook)xl.Workbooks.Open(laPath, oMissing,
        oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);
        xlSheet = (Worksheet)xlBook.Worksheets.get_Item(1);
        xlSheet.Cells.Borders.LineStyle = Excel.XlLineStyle.xlContinuous;
        xlSheet.SetBackgroundPicture(HttpContext.Current.Server.MapPath("~//images//cybex-punchline_half.jpg"));
        xlSheet.Cells.WrapText = false;

        //range = xlSheet.get_Range("A:A", System.Type.Missing);
        //range.EntireColumn.ColumnWidth = 15;
        xlBook.Worksheets.get_Item(1);
        ((Range)xlSheet.Columns["A", Type.Missing]).ColumnWidth = 13;
        ((Range)xlSheet.Columns["B", Type.Missing]).ColumnWidth = 09;
        ((Range)xlSheet.Columns["C", Type.Missing]).ColumnWidth = 65;
        ((Range)xlSheet.Columns["D", Type.Missing]).ColumnWidth = 13;
        ((Range)xlSheet.Columns["E", Type.Missing]).ColumnWidth = 10;
        ((Range)xlSheet.Columns["F", Type.Missing]).ColumnWidth = 22;
        ((Range)xlSheet.Columns["G", Type.Missing]).ColumnWidth = 10;
        ((Range)xlSheet.Columns["H", Type.Missing]).ColumnWidth = 30;
        ((Range)xlSheet.Columns["I", Type.Missing]).ColumnWidth = 12;
        ((Range)xlSheet.Columns["J", Type.Missing]).ColumnWidth = 25;


        string str_modified_file_download_name = dwnlod_file_name(strWorkOrder);
        // Saving File on disk.
        xlBook.SaveAs(HttpContext.Current.Server.MapPath("~//download//" + str_modified_file_download_name + ".xls"), XlFileFormat.xlWorkbookDefault, Type.Missing, Type.Missing,
        false, false, XlSaveAsAccessMode.xlNoChange,
        Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

        //xlBook.Sheets("str").Cells.WrapText = False;


        xl.Application.Workbooks.Close();
        FileInfo fi1 = new FileInfo(laPath);
        if (fi1.Exists)
            fi1.Delete();

        // Releasing Objects.
        releaseObject(xlBook);
        releaseObject(xlSheet);
        releaseObject(xl);
        return str_modified_file_download_name;
    }

Pls does anyone know something about it ? Please help me

推荐答案

Office互操作库要求您在服务器计算机上安装Office.

通常,这是一个坏主意,使用特定库(例如 http://epplus.codeplex.com/ []会更好,更高效)[ ^ ]用于XLS(X)文件处理,不需要安装任何内容,并且在服务器上工作.
Office interop libraries require you to install Office on your server machine.

This is generally a bad idea, it is better and more performant to use specific libraries like http://epplus.codeplex.com/[^] for XLS(X) file processing which do not require anything to be installed and work on servers.


这篇关于inetrop.excel库在服务器上不起作用,但在loacalhost上运行良好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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