问题描述
我已经在 Stackoverflow 中进行了搜索,发现很少有使用 Interop.Excel 的示例。
我使用的是 Office 2016,Interop.Excel 面向 2013。我想从我的 C# 应用程序读取位于 Sharepoint 路径中的 excel 文件。用户将从应用程序中更改单元格值,它应该会在 Sharepoint 文件中更新。
我检查了几个 ClosedXML 样本,但这些样本是访问本地文件而不是 Sharepoint。
解决方法
// Starting with ClientContext,the constructor requires a URL to the
// server running SharePoint.
ClientContext context = new ClientContext("https://{site_url}");
GroupCollection siteGroups = context.Web.SiteGroups;
// Assume that there is a "Members" group,and the ID=5.
Group membersGroup = siteGroups.GetById(5);
// Let's set up the new user info.
UserCreationInformation userCreationInfo = new UserCreationInformation();
userCreationInfo.Email = "user@domain.com";
userCreationInfo.LoginName = "domain\\user";
userCreationInfo.Title = "Mr User";
// Let's add the user to the group.
User newUser = membersGroup.Users.Add(userCreationInfo);
context.ExecuteQuery();
我希望示例代码有所帮助。