【问题标题】:OpenXML PowerPoint files won't open on IOS 7 devicesOpenXML PowerPoint 文件无法在 IOS 7 设备上打开
【发布时间】:2014-02-08 23:06:35
【问题描述】:

类似于this question,我在我的 iPad 上打开 OpenXML 2.5 文档时遇到了问题。经过反复试验,我找到了这个 xml 标签:

需要存在于 .pptx 文件(实际上只是一个 zip 存档)根目录中的 "[Content_Types].xml" 文件中。然后该文件可以在 PC 上的 PowerPoint(在 2010 版测试)和 IOS 7 中打开。

【问题讨论】:

  • 对于其他人,我注意到关系路径是绝对的还是相对的,例如 /ppt/presentation.xml vs ../ppt/presentation.xml 如果文件在许多移动设备上打开,可能会有所不同.

标签: c# ios powerpoint openxml openxml-sdk


【解决方案1】:

这是我用来实际添加必要的 xml 元素的代码。欢迎建设性的反馈!此方法在演示文稿创建后调用。

    public MemoryStream ApplyOpenXmlFix(MemoryStream input)
    {
        XNamespace contentTypesNamespace = "http://schemas.openxmlformats.org/package/2006/content-types";
        string filename = "[Content_Types].xml";

        input.Seek(0, SeekOrigin.Begin);

        ZipFile zipArchive = ZipFile.Read(input);
        ZipEntry file = zipArchive.Entries.Where(e => e.FileName == filename).Single();

        var xmlDocument = XDocument.Load(file.OpenReader());
        var newElement = new XElement(
             contentTypesNamespace + "Override",
            new XAttribute("PartName", "/ppt/presentation.xml"),
            new XAttribute("ContentType", "application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml"));

        xmlDocument.Root.Add(newElement);

        MemoryStream updatedDocument = new MemoryStream();
        xmlDocument.Save(updatedDocument, SaveOptions.DisableFormatting);
        updatedDocument.Seek(0, SeekOrigin.Begin);
        zipArchive.UpdateEntry(filename, updatedDocument);

        MemoryStream output = new MemoryStream();
        zipArchive.Save(output);
        return output;
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-05-10
    • 2015-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多