我们需要创建一个 C# 应用程序,该应用程序可以修改我们的 Sharepoint 在线站点之一中的 Excel 文件。
对于本地文件,我喜欢这样:
Excel.Application excel_app = new Excel.Application();
excel_app.Visible = true;
Excel.Workbook workbook = excel_app.Workbooks.Open(
<path to excel file>,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);
但是如果我输入 Sharepoint Excel 文件的 url,它就不起作用。这是否可行,如何实现?
最佳答案
您可以下载文件、修改文件、上传文件并替换
以下是如何连接到共享点站点并上传文件
使用 Microsoft.SharePoint.Client 命名空间
using SP = Microsoft.SharePoint.Client;
...
using (var context = new SP.ClientContext(new Uri(<YOURSITEURL>))) {
var web = context.Web;
context.Credentials = new NetworkCredential(<NETWORK_USERNAME>, <NETWORK_PASS>, <DOMAIN_NAME>);
context.Load(web);
try
{
context.ExecuteQuery();
} catch (Exception ex) {
}
var file = web.GetFileByServerRelativeUrl(new Uri(<FILE_URL>).AbsolutePath);
context.Load(file);
try
{
context.ExecuteQuery();
file.SaveBinary(new SP.FileSaveBinaryInformation() { Content = Encoding.UTF8.GetBytes(<NEW_FILE>) });
try
{
context.ExecuteQuery();
}
catch (Exception ex)
{
}
}
}
关于c# - 以编程方式修改 Sharepoint Online Excel 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37837675/