Read excel file stored in SharePoint Document Library

前端 未结 2 965
感动是毒
感动是毒 2021-01-26 19:59

I have an excel file stored in SharePoint document library. I need to read this excel file and get the data programmatically from the file path

For Example: SharePoint

2条回答
  •  情深已故
    2021-01-26 20:23

    You can obtain the binary data from SPFile object and then open it in third party library ClosedXML

    SPFile file = web.GetFile("http://servername:1000/ExcelDocs//ExcelFile.xlsx");
    Stream dataStream = file.OpenBinaryStream();
    XLWorkbook workbook = new XLWorkbook(dataStream);
    

    or you can use OpenXML, which is Microsoft SDK.

    SPFile file = web.GetFile("http://servername:1000/ExcelDocs//ExcelFile.xlsx");
    Stream dataStream = file.OpenBinaryStream();
    SpreadsheetDocument document = SpreadsheetDocument.Open(dataStream, false);
    Workbook workbook = document.WorkbookPart.Workbook;
    

    Here is the example of using OpenXML

提交回复
热议问题