【发布时间】:2012-06-11 08:16:23
【问题描述】:
我正在尝试在 .NET 中生成一个电子表格,我的经理不在办公室时将在他的 iPad 上打开该电子表格。
电子表格在 Windows PC 上可以正常打开,但尝试在 iPad 上打开时显示“读取文档时出错”(非常有用!)
通过使用 OpenXML SDK Productivity 工具上的“比较”功能与在 iPad 上打开的文档确实,并通过在记事本中手动编辑错误文档的 XML 文件,我缩小了范围到文件xl/_rels/workbook.xml.rels,该文件存储了工作簿中各部分的关系。
这是我用来生成 WorkbookPart 和引用的代码
WorkbookPart workbookPart1 = document.AddWorkbookPart();
WorkbookStylesPart workbookStylesPart1 = workbookPart1.AddNewPart<WorkbookStylesPart>("rId3");
ThemePart themePart1 = workbookPart1.AddNewPart<ThemePart>("rId2");
WorksheetPart worksheetPart1 = workbookPart1.AddNewPart<WorksheetPart>("rId1");
我的代码生成以下输出,但在 iPad 上无法打开。
<?xml version="1.0" encoding="utf-8" ?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="/xl/styles.xml" Id="rId3" />
<Relationship Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Target="/xl/theme/theme.xml" Id="rId2" />
<Relationship Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="/xl/worksheets/sheet.xml" Id="rId1" />
</Relationships>
如果我将 Target 属性的值更改为使用相对引用路径,并给出以下输出,那么它确实会在 iPad 上打开。
<?xml version="1.0" encoding="utf-8" ?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml" Id="rId3" />
<Relationship Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Target="theme/theme.xml" Id="rId2" />
<Relationship Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet.xml" Id="rId1" />
</Relationships>
所以问题是:
如何更改我的 .NET 代码,使其输出带有相对路径的 XML 的第二个版本。
感谢所有帮助!
【问题讨论】:
-
这似乎更像是一个“如何使用”的问题,而不是一个编程问题,但无论如何,您尝试使用 iPad 上的哪个应用程序打开电子表格?
-
对不起,我不明白您所说的“如何使用”与编程是什么意思,但还是感谢您回答我。我只是通过电子邮件直接从 ipad 上的邮件应用程序打开它。
-
我也有同样的问题,但是文档中没有关系文件,也没有任何Target属性!
标签: .net ios ipad openxml relative-path