Esempio n. 1
0
        public async Task ExcelSortTableOnFirstColumnValue()
        {
            try
            {
                var excelFileId = await OneDriveCreateTestFile("_excelSortTableOnFirstColumnValue.xlsx");
                await OneDriveUploadTestFileContent(excelFileId);

                // Create the sorting options.
                var sortField = new WorkbookSortField()
                {
                    Ascending = true,
                    SortOn    = "Value",
                    Key       = 0
                };

                var workbookSortFields = new List <WorkbookSortField>()
                {
                    sortField
                };

                // Sort the table. This results in a call to the service.
                await graphClient.Me.Drive.Items[excelFileId].Workbook.Tables["Table2"]
                .Sort
                .Apply(true, "", workbookSortFields)
                .Request()
                .PostAsync();

                await OneDriveDeleteTestFile(excelFileId, 3000);
            }
            catch (Microsoft.Graph.ServiceException e)
            {
                Assert.Fail("Something happened. Error code: {0}", e.Error.Code);
            }
        }
Esempio n. 2
0
        public static async Task <bool> SortExcelTableOnFirstColumnValueAsync(string fileId)
        {
            bool tableSorted = false;

            try
            {
                GraphServiceClient graphClient = AuthenticationHelper.GetAuthenticatedClient();

                // Create the sorting options.
                WorkbookSortField sortField = new WorkbookSortField()
                {
                    Ascending = true,
                    SortOn    = "Value",
                    Key       = 0
                };

                List <WorkbookSortField> workbookSortFields = new List <WorkbookSortField>()
                {
                    sortField
                };

                // Sort the table. This results in a call to the service.
                await graphClient.Me.Drive.Items[fileId].Workbook.Tables["Table2"]
                .Sort
                .Apply(true, "", workbookSortFields)
                .Request()
                .PostAsync();

                tableSorted = true;
                Debug.WriteLine("Sorted the table on this value: " + sortField.SortOn);
            }
            catch (Microsoft.Graph.ServiceException e)
            {
                Debug.WriteLine("We failed to sort the table: " + e.Error.Message);
            }

            return(tableSorted);
        }