简体   繁体   English

Excel 500(内部服务器错误)

[英]Excel 500 (Internal Server Error)

I'm writing LigthSwitch application and one of the requirements is to export data to Excel. 我正在编写LigthSwitch应用程序,其中一个要求是将数据导出到Excel。 I have accomplished such task. 我完成了这样的任务。 It works perfectly when application is being run on localhost. 当应用程序在localhost上运行时,它可以正常工作。 However, when I upload application into the SharePoint site I get following error: 但是,当我将应用程序上传到SharePoint网站时,我收到以下错误:

Failed to load resource: the server responded with a status of 500 (Internal Server Error) https://437aa483-68ef-4ae1-9269-b206f5beb418.o365apps.net/setExcelDocument.ashx 无法加载资源:服务器响应状态为500(内部服务器错误) https://437aa483-68ef-4ae1-9269-b206f5beb418.o365apps.net/setExcelDocument.ashx

Here is the sample code(Just copy, reference excel.dll and add trigger) : 以下是示例代码(只需复制,引用excel.dll和添加触发器):

        private Microsoft.Office.Interop.Excel.Application app = null;
        private Microsoft.Office.Interop.Excel.Workbook workbook = null;
        private Microsoft.Office.Interop.Excel.Worksheet worksheet = null;
        private Microsoft.Office.Interop.Excel.Range workSheet_range = null;

        private void createOpportunity()
        {
            try
            {
                app = new Microsoft.Office.Interop.Excel.Application();
                app.Visible = true;
                workbook = app.Workbooks.Add(1);
                worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Sheets[1];
            }
            catch (Exception e)
            {
                throw new Exception(e.ToString());
            }

            worksheet.Cells[5,1] = "hello World";
            workSheet_range = worksheet.get_Range("B5", "Q5");
            workSheet_range.Merge(14);
            string b = "YELLOW";
            switch (b)
            {
                case "YELLOW":
                    workSheet_range.Interior.Color = System.Drawing.Color.Yellow.ToArgb();
                    break;
                case "GRAY":
                    workSheet_range.Interior.Color = System.Drawing.Color.Gray.ToArgb();
                    break;
                case "GAINSBORO":
                    workSheet_range.Interior.Color =
            System.Drawing.Color.Gainsboro.ToArgb();
                    break;
                case "Turquoise":
                    workSheet_range.Interior.Color =
            System.Drawing.Color.Turquoise.ToArgb();
                    break;
                case "PeachPuff":
                    workSheet_range.Interior.Color =
            System.Drawing.Color.PeachPuff.ToArgb();
                    break;
                default:
                    //  workSheet_range.Interior.Color = System.Drawing.Color..ToArgb();
                    break;
            }

            workSheet_range.Borders.Color = System.Drawing.Color.Black.ToArgb();
            workSheet_range.Font.Bold = true;
            workSheet_range.ColumnWidth = 14;
            string fcolor = "n";
            if (fcolor.Equals(""))
            {
                workSheet_range.Font.Color = System.Drawing.Color.White.ToArgb();
            }
            else
            {
                workSheet_range.Font.Color = System.Drawing.Color.Black.ToArgb();
            }

            worksheet.Cells[7,2] = "hi";
            workSheet_range = worksheet.get_Range("B7", "C7");
            workSheet_range.Borders.Color = System.Drawing.Color.Black.ToArgb();
            workSheet_range.NumberFormat = "#,##0";

        }

Your code executes on the host system and when deployed to a SharePoint site that host system would need to have Excel installed and security access enabled to run it. 您的代码在主机系统上执行,当部署到SharePoint站点时,主机系统需要安装Excel并启用安全访问才能运行它。 That solution would not scale or work well as you would be trying to attempt multithreaded access from a web server thread. 该解决方案无法扩展或运行良好,因为您尝试从Web服务器线程尝试多线程访问。

You need to follow a different design pattern like working with OpenXml (on client or server) or interact with the Office365 API's as this is in the cloud. 您需要遵循不同的设计模式,例如使用OpenXml(在客户端或服务器上)或与Office365 API进行交互,因为它位于云中。

API's for Excel Services on the Web 用于Web上Excel Services的API

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM