简体   繁体   English

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

[英]File contains corrupted data error when opening Excel sheet with OpenXML

I'm writing an Event Receiver for ItemAdded with SharePoint 2013. I'm using OpenXML to read the spreadsheets. 我正在使用SharePoint 2013编写ItemAdded的事件接收器。我正在使用OpenXML读取电子表格。 When I try to open the logfile that lives in the SharePoint Library programmatically, I get the following error: 当我尝试以编程方式打开位于SharePoint库中的日志文件时,出现以下错误:

File contains corrupted data 文件包含损坏的数据

The block of code throwing this error is: 引发此错误的代码块是:

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

The first line passes fine, the second line (logsheet) breaks. 第一行通过,第二行(日志)中断。 They are both being read from a stream. 它们都是从流中读取的。 spreadsheet is the item being added when the event fires and logsheet is an item that currently exists in SharePoint. 电子表格是事件触发时要添加的项目,而日志表是SharePoint中当前存在的项目。

spreadsheet is opened from a data stream using the path: 使用以下路径从数据流中打开电子表格:

string workbookpath = properties.ListItem.Web.Url + "/" + properties.ListItem.File.Url;

and logsheet is opened using a datastream using its direct URL in SharePoint 并使用数据流通过SharePoint中的直接URL打开日志表

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

Any help or insight is greatly appreciated. 任何帮助或见解将不胜感激。

Your logsheet is an XML file [.xml]. 您的日志表是一个XML文件[.xml]。 It's not an Excel file [.xlsx] (Open XML doesn't mean just XML). 这不是一个Excel文件[.XLSX](开放XML并不仅仅意味着XML)。 That's why it failed. 这就是为什么它失败了。

AH, stupid me forgot to set permissions for the Excel service to read and write. 嗯,愚蠢的我忘记了设置Excel服务的读写权限。 I also found plenty of good information in the following places: 我还在以下地方找到了很多有用的信息:

Programmatically Reading excel file from SharePoint library 以编程方式从SharePoint库读取Excel文件

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

Read Data From Excel File 从Excel文件读取数据

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM