使用OpenXML打开Excel工作表时,文件包含损坏的数据错误

时间:2013-10-30 18:27:53

标签: c# excel sharepoint openxml

我正在使用SharePoint 2013为ItemAdded编写事件接收器。我正在使用OpenXML来阅读电子表格。当我尝试以编程方式打开SharePoint库中的日志文件时,出现以下错误:

文件包含损坏的数据

抛出此错误的代码块是:

using (SpreadsheetDocument spreadsheet = SpreadsheetDocument.Open(mstream, false))
using (SpreadsheetDocument logsheet = SpreadsheetDocument.Open(logstream, false))

第一行传递正常,第二行(日志表)中断。它们都是从流中读取的。电子表格是事件触发时添加的项目,而日志表是SharePoint中当前存在的项目。

使用以下路径从数据流打开电子表格:

string workbookpath = properties.ListItem.Web.Url + "/" + properties.ListItem.File.Url;
使用SharePoint中的直接URL

使用数据流打开

和日志表

string logFilePath = "http://SPSiteName/sites/SP/Dropbox/RuntimeLog.xml";

非常感谢任何帮助或见解。

2 个答案:

答案 0 :(得分:0)

您的日志表是一个XML文件[.xml]。它不是Excel文件[.xlsx](Open XML并不意味着只是 XML)。这就是它失败的原因。

答案 1 :(得分:0)

AH,愚蠢的我忘了设置Excel服务的读写权限。我还在以下地方找到了很多好消息:

以编程方式从SharePoint库中读取Excel文件

http://www.sharepointwithattitude.com/archives/61

从Excel文件中读取数据

http://alancejacob.blogspot.in/2012/06/read-data-from-excel-file-and-insert-in.html

相关问题