Excel和“不可读内容”当使用MemoryStream创建Open XML电子表格时 [英] Excel and "unreadable content" when creating an Open XML spreadsheet with MemoryStream

查看:165
本文介绍了Excel和“不可读内容”当使用MemoryStream创建Open XML电子表格时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Open XML SDK v2.0创建Excel电子表格时,我们的Excel输出最初成功工作了好几个月。最近Excel(所有版本)开始抱怨Excel在zot.xlsx中发现无法读取的内容,您要恢复此工作簿的内容吗?我们正在使用MemoryStream作为存储在Web应用程序中创建该文件,然后以MIME类型application / vnd.openxmlformats-officedocument.spreadsheetml.sheet作为HTTP响应中的byte []发送。坏文件的解压缩内容与文件的解压缩内容没有错误相同。

When creating an Excel spreadsheet using the Open XML SDK v2.0, our Excel output initially worked successfully for a number of months. Recently Excel (all versions) began to complain about "Excel found unreadable content in 'zot.xlsx'. Do you want to recover the contents of this workbook?". We are creating the file in a web application, using a MemoryStream as the store, which is then sent as a byte[] in an HTTP response with a MIME type of "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet". The unzipped contents of a bad file were identical to the unzipped contents of a file without errors.

推荐答案

我们追逐了这么多小时,一路上拾起了一对红色的鲱鱼,解决了坏文件在一方面是不同的。文件长度不同在返回MemoryStream并将byte []写入HTTP响应之前,请确保使用简单的'stream.Capacity = stream.Length;'来截断MemoryStream以使其容量和长度相同。

We chased this down for too many hours, picking up a couple of red herrings along the way, but in the end, resolved that the bad file was different in one respect. The file length was different. Before returning the MemoryStream and writing the byte[] to the HTTP response, ensure that you truncate the MemoryStream so that its capacity and length are the same, using a simple 'stream.Capacity = stream.Length;'.

似乎Excel现在将文件中的额外内容检测为不可读内容的安全风险,并引发烦人的错误,过去在以前会接受风险。

It appears that Excel now detects the extra content in the file as a security risk as 'unreadable content' and throws the annoying error, when in the past it would accept the risk.

注意:从原来的海报回答,他以前在问题中有答案

这篇关于Excel和“不可读内容”当使用MemoryStream创建Open XML电子表格时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆