Excel中的简单步骤“损坏”文件,因此Open XML Productivity Tool无法打开它 [英] Simple step in Excel to 'corrupt' a file so Open XML Productivity Tool can't open it

查看:87
本文介绍了Excel中的简单步骤“损坏”文件,因此Open XML Productivity Tool无法打开它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  1. 使用Excel创建新文件 - 2007年,2010年和2013年都有此问题
  2. 仍在Excel中,添加表单按钮并编辑文本 - 添加回车符以将部分文本放在新行
  3. 保存文件并关闭它
  4. 尝试使用Open打开它XML Productivity Toolkit - 2.0或2.5

您将看到以下消息:无法打开文件:部分/xl/drawings/vmlDrawing1.vml:'br'start标签在线xx位置yy与'font'的结束标记不匹配

You will see the message: Cannot open the file: Part /xl/drawings/vmlDrawing1.vml: The 'br' start tag on line xx position yy does not match the end tag of 'font'

这对我们来说是个问题,因为我们在一个目录中有几百个文件,所有文件都基于相同的模板一个带换行符的按钮。 

This is an issue for us as we have several hundred files in a directory, all based on the same template that incorporated a button with a line break. 

我们一直在通过VBA打开它们并提取数据用于各种报告目的。 文件很大,这个过程需要很长时间,所以我们想尝试用Open XML阅读它们。 它在"固定"的情况下要快得多。模板的
副本 - 即从按钮文本中删除换行符的模板 - 但不会对目录中的文件起作用。 尝试打开SpreadsheetDocument失败,报告文件已损坏。

We had been opening them via VBA and extracting data for various reporting purposes.  The files are huge and this process takes quite a while, so we wanted to try reading them with Open XML.  It is so much faster on a "fixed" copy of the template - that is, one where the line break was removed from the button text - but will not work on the files in the directory.  Trying to open the SpreadsheetDocument fails, reporting that the file is corrupted.

我对这些文件具有只读权限,无法编辑按钮文本。 每个人都必须通过内联网网站访问每个人,并且这些人只能访问输入单元;他们无法更改任何用户
界面元素。 

I have read-only access to these files and cannot edit the button text.  Each must be accessed by a specific person or two, by going through an intranet web site, and those people have access only to the input cells; they cannot change any of the user interface elements. 

如果没有办法以编程方式解决这个问题,我们将不得不让每个人下载他们的文件,发送给我,这样我就可以修复界面并发送他们回来,让他们通过网络界面上传。

If there is no way to get past this problem programmatically, we will be stuck having to have each of these people download their files, send them to me so I can fix the interface and send them back, to have them then upload through the web interface.

有人有任何想法吗?

推荐答案

您好,

>>所以我们想尝试使用Open XML读取它们...但是不会对目录中的文件起作用。 试图打开SpreadsheetDocument失败,报告该文件已损坏。

Hi,

>> so we wanted to try reading them with Open XML…but will not work on the files in the directory.  Trying to open the SpreadsheetDocument fails, reporting that the file is corrupted.

您能否为我提供OpenXML代码?当我使用Open Xml SDK更改了按钮的Text属性时,我猜测文件可能已损坏。

Could you provide your OpenXML code for me? I guessed the file may be corrupted when you changed button’s Text property using Open Xml SDK.

您是否想要修改位于网站中的文档?

Did you wanted to modify the documents were located in Web site?

我写了一个示例代码,用< Br>修改文本。标签,它在我的机器上工作正常。

I wrote a sample code to modify the text with <Br> tag, it worked fine in my machine.

这是我的示例代码:

            string sPptPath = @"D:\1.xlsx";
            var pkg = Package.Open(sPptPath, FileMode.Open, FileAccess.ReadWrite);
            // Specify the URI of the part to be read
            var uri = new Uri("/xl/drawings/vmlDrawing1.vml", UriKind.Relative);
            PackagePart part = pkg.GetPart(uri);
            Stream stremPart = part.GetStream(FileMode.Open, FileAccess.ReadWrite);
            var xmlMainXmlDoc = new XmlDocument();
            xmlMainXmlDoc.Load(stremPart);
            XmlNode ButtonText = xmlMainXmlDoc.GetElementsByTagName("v:textbox").Item(0);
            XmlNode Font = ButtonText.ChildNodes[0].ChildNodes[0];
            Font.InnerText = "1000";
// Save the changes in this stream.
            xmlMainXmlDoc.Save(stremPart);
            pkg.Close();

问候,

Marvin


这篇关于Excel中的简单步骤“损坏”文件,因此Open XML Productivity Tool无法打开它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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