Esempio n. 1
0
        public async Task ExcelAddRowToTable()
        {
            string excelFileId = string.Empty;

            try
            {
                excelFileId = await OneDriveCreateTestFile("_excelAddRowToTable.xlsx");
                await OneDriveUploadTestFileContent(excelFileId);

                // Create the table row to insert. This assumes that the table has 2 columns.
                // You'll want to make sure you give a JSON array that matches the size of the table.
                var newWorkbookTableRow = new WorkbookTableRow();
                newWorkbookTableRow.Index = 0;
                var myArr = JArray.Parse("[[\"ValueA2\",\"ValueA3\"]]");
                newWorkbookTableRow.Values = myArr;

                //// Insert a new row. This results in a call to the service.
                var workbookTableRow = await graphClient.Me.Drive.Items[excelFileId]
                                       .Workbook
                                       .Tables["Table1"]
                                       .Rows
                                       .Request()
                                       .AddAsync(newWorkbookTableRow);

                Assert.NotNull(workbookTableRow);

                await OneDriveDeleteTestFile(excelFileId, 3000);
            }
            catch (Microsoft.Graph.ServiceException e)
            {
                await OneDriveDeleteTestFile(excelFileId, 3000);

                Assert.True(false, "Something happened. Error code: " + e.Error.Code);
            }
        }
Esempio n. 2
0
        public static async Task <WorkbookTableRow> AddExcelRowToTableAsync(string fileId)
        {
            WorkbookTableRow workbookTableRow = null;

            try
            {
                GraphServiceClient graphClient = AuthenticationHelper.GetAuthenticatedClient();

                // Create the table row to insert. This assumes that the table has 2 columns.
                // You'll want to make sure you give a JSON array that matches the size of the table.
                WorkbookTableRow newWorkbookTableRow = new WorkbookTableRow();
                newWorkbookTableRow.Index = 0;
                JArray myArr = JArray.Parse("[[\"ValueA2\",\"ValueA3\"]]");
                newWorkbookTableRow.Values = myArr;

                //// Insert a new row. This results in a call to the service.
                workbookTableRow = await graphClient.Me.Drive.Items[fileId]
                                   .Workbook
                                   .Tables["Table1"]
                                   .Rows
                                   .Request()
                                   .AddAsync(newWorkbookTableRow);

                Debug.WriteLine("Added a row to Table 1.");
            }
            catch (Microsoft.Graph.ServiceException e)
            {
                Debug.WriteLine("We failed to add the table row: " + e.Error.Message);
            }

            return(workbookTableRow);
        }
        public static async Task <bool> TryAddExcelRowToTableAsync()
        {
            string createdFileId = await UserSnippets.UploadExcelFileAsync("excelTestResource.xlsx");

            WorkbookTableRow excelWorkbookTableRow = await UserSnippets.AddExcelRowToTableAsync(createdFileId);

            return(excelWorkbookTableRow != null);
        }
 public static void MockPostTableRowAsyc(this Mock <IGraphServiceClient> mock, WorkbookTableRow returnValue)
 {
     mock.Setup(client => client
                .Me
                .Drive
                .Root
                .ItemWithPath(It.IsAny <string>())
                .Workbook
                .Tables[It.IsAny <string>()]
                .Rows
                .Add(null, It.IsAny <JToken>())
                .Request(null)
                .PostAsync()).Returns(Task.FromResult(returnValue));
 }