操作工作簿-工作表存储在Office 365中-OneDrive通过Excel Service

时间:2018-07-04 12:59:22

标签: c# excel api office365 onedrive

我正在尝试访问Office 365上存储在oneDrive上的Excel文件,但是当我尝试访问它时,抛出以下错误;

错误:无法自动进入服务器。连接到服务器计算机“ rmiedu-my.sharepoint.com”失败。 Visual Studio 2015远程调试器(MSVMON.EXE)似乎没有在远程计算机上运行。这可能是因为防火墙阻止了与远程计算机的通信。

我要访问的服务器托管在另一个网络上。

请分享任何反馈。谢谢!

我正在使用的代码如下

using System;

using System.Web.Services.Protocols;

namespace prospectusDispatch.ExcelService

{

     class Program

     {

         [STAThread]
        static void Main(string[] args)
        {


            ExcelService es = new ExcelService();
            Status[] outStatus;
            RangeCoordinates rangeCoordinates = new RangeCoordinates();

            string sheetName = "Sheet1";
            // Using workbookPath this way will allow 
            // you to call the workbook remotely.
            // TODO: change the workbook path to 
            // point to workbook in a trusted location
            // that you have access to 
            string targetWorkbookPath = "https://rmiedu-my.sharepoint.com/:x:/g/personal/register_rmi_edu_pk/Eft0skMLaNFLuS3ZatkLha4Bln2RHub3rWcgk5IcfnySfg?e=DdET9m";

            // Set credentials for requests
            es.Credentials = System.Net.CredentialCache.DefaultCredentials;
            try
            {
                // Call open workbook, and point to the trusted   
                // location of the workbook to open.
                string sessionId = es.OpenWorkbook(targetWorkbookPath, "en-US", "en-US", out outStatus);

                // Prepare object to define range coordinates
                // and the GetRange method.
                rangeCoordinates.Column = 3;
                rangeCoordinates.Row = 9;
                rangeCoordinates.Height = 18;
                rangeCoordinates.Width = 12;

                object[] rangeResult1 = es.GetRange(sessionId, sheetName, rangeCoordinates, false, out outStatus);
                Console.WriteLine("Total Rows in Range: " + rangeResult1.Length);
                Console.WriteLine("Value in range is: " + ((object[])rangeResult1[5])[3]);
                es.CloseWorkbook(sessionId);
            }
            catch (SoapException e)
            {
                Console.WriteLine("SOAP Exception Message: {0}", e.Message);
            }

        }
    }
}

0 个答案:

没有答案