質問

Similar to this question, I was having trouble opening OpenXML 2.5 documents on my iPad. After some trial and error, I found this xml tag:

< Override PartName="/ppt/presentation.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml" />

needs to be present in the "[Content_Types].xml" file in the root of the .pptx file (which is really just a zip archive). Then the file can be opened in both PowerPoint on the PC (tested on version 2010) and IOS 7.

役に立ちましたか?

解決

Here's the code I used to actually add the necessary xml element. Constructive feedback is welcomed! This method is called after the presentation is created.

    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;
    }
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top