Reading and Writing Office 365 Excel from a Console app using the Microsoft.Graph C# Client API #code#microsoft#excel#graph#office365 How to read and write data to an Office 365 Excel workbook using the Microsoft.Graph client library from a C# console application.
Updated on Sunday, September 18, 2022
I needed a console app that reads some inputs from an online Excel workbook, does some processing and then writes back the results to a different worksheet. Because I enjoy pain I decided to use the thinly documented new Microsoft.Graph client library. The sample code below assumes that you have a work or education Office 365 subscription.
Paste the code into a new console project and then follow the instructions at the top to add the necessary NuGet packages. You'll also need to register an application at https://portal.azure.com/. You want a Native application and you'll need the Application ID and the redirect URL (just make up some non-routable URL for this). Under Required Permissions for the app you should add read and write files delegated permissions for the Microsoft Graph API.
Hope this saves you a few hours. Comment below if you need a more detailed explanation for any of the above.
All comments are moderated. Your email address is used to display a Gravatar
and optionally for notification of new comments and to sign up for the newsletter.
Newsletter
Related
Using the Azure Monitor REST API from Google Apps Script — This post describes how to get metrics (in this case average response time) from an Azure App Service into a Google Sheet. I’m doing this so I can go from the sheet to a Data Studio dashboard. I already have a report in Data...
Sending email via GMail in C#/.NET using SmtpClient — Here’s a quick code snippet that configures SmtpClient to send email using Gmail’s SMTP server: using (SmtpClient smtp = new SmtpClient()) { smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.UseDefaultCredentials = false; smtp.EnableSsl...
Google Spreadsheets API and Column Names — I had a play with the Google Spreadsheets API recently to feed in some data from a C# application. The getting started guide is great and I was authenticated and adding dummy data in no time. But as soon as I started to work with real data...
Add Comment
All comments are moderated. Your email address is used to display a Gravatar and optionally for notification of new comments and to sign up for the newsletter.