使用OpenXML打开Excel工作表时,文件包含损坏的数据错误
我正在为SharePoint 2013中的ItemAdded编写事件接收器。我正在使用OpenXML来读取电子表格。 当我尝试以编程方式打开驻留在SharePoint库中的日志文件时,出现以下错误:
文件包含损坏的数据
抛出这个错误的代码块是:
using (SpreadsheetDocument spreadsheet = SpreadsheetDocument.Open(mstream, false)) using (SpreadsheetDocument logsheet = SpreadsheetDocument.Open(logstream, false))
第一行传递正常,第二行(日志)中断。 他们都是从stream中读取。 电子表格是在事件触发时添加的项目,日志表是SharePoint中当前存在的项目。
使用以下path从数据stream打开电子表格:
string workbookpath = properties.ListItem.Web.Url + "/" + properties.ListItem.File.Url;
并使用SharePoint中的直接URL使用数据stream打开日志表
string logFilePath = "http://SPSiteName/sites/SP/Dropbox/RuntimeLog.xml";
任何帮助或见解,非常感谢。
您的日志是一个XML文件[.xml]。 这不是一个Excel文件[.xlsx](Open XML并不仅仅意味着XML)。 这就是为什么失败。
啊,我忘了为忘记设置Excel服务的读写权限。 我还在以下地方find了很多有用的信息:
以编程方式从SharePoint库中读取excel文件
http://www.sharepointwithattitude.com/archives/61
从Excel文件读取数据
http://alancejacob.blogspot.in/2012/06/read-data-from-excel-file-and-insert-in.html