与此问题类似,我在iPad上打开OpenXML 2.5文档时遇到了麻烦。经过一番尝试和错误,我发现了这个xml标记:
<覆盖PartName =“ / ppt / presentation.xml” ContentType =“ application / vnd.openxmlformats-officedocument.presentationml.presentation.main + xml” />
需要"[Content_Types].xml"
在.pptx文件(实际上只是一个zip归档文件)的根目录中的文件中存在。然后可以在PC上的PowerPoint(在版本2010中测试)和IOS 7中打开文件。
这是我用来实际添加必要的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;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句