我要从SharePoint 2013文档库下载一个excel文件。将其写入内存流并将其加载到Excel Package之后,我想对excel工作表进行修改并将文档保存到库中。
下面是我到目前为止的代码
using (var clientContext = new ClientContext("https://url/"))
{
Web web = clientContext.Web;
clientContext.Load(web);
clientContext.ExecuteQuery();
string url = web.ServerRelativeUrl;
Microsoft.SharePoint.Client.File file = web.GetFileByServerRelativeUrl(url + "/Shared/Test.xlsx");
ClientResult<System.IO.Stream> data = file.OpenBinaryStream();
clientContext.Load(file);
clientContext.ExecuteQuery();
MemoryStream mStream = new MemoryStream();
data.Value.CopyTo(mStream);
using (var ws = new OfficeOpenXml.ExcelPackage(mStream))
{
ExcelWorksheet sheet = ws.Workbook.Worksheets.First();
sheet.Cells[1, 1].Value = "Test";
ws.Save()
var stream = new MemoryStream(ws.GetAsByteArray()); **'Getting an error here'**
string fileUrl = url + "/Shared/Test.xlsx";
Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, fileUrl, stream, true);
}
}
}
有人可以帮忙吗!