OpenXml ChangeDocumentType

使徒行传

我需要将PowerPoint模板从potx转换为pptx。如此处所示:http : //www.codeproject.com/Tips/366463/Create-PowerPoint-presentation-using-PowerPoint-te我尝试使用以下代码。但是,生成的pptx文档无效,不能由Office Powerpoint打开。如果跳过newDoc.ChangeDocumentType行,则生成的文档有效,但未转换为pptx。templateContentBytes是一个字节数组,其中包含potx文档的内容。temppath指向其本地版本。

using (var stream = new MemoryStream())
                {
                    stream.Write(templateContentBytes, 0, templateContentBytes.Length);

                    using (var newdoc = PresentationDocument.Open(stream, true))
                    {
                        newdoc.ChangeDocumentType(PresentationDocumentType.Presentation);
                        PresentationPart presentationPart = newdoc.PresentationPart;

                        presentationPart.PresentationPropertiesPart.AddExternalRelationship(
                            "http://schemas.openxmlformats.org/officeDocument/2006/" + "relationships/attachedTemplate",
                            new Uri(tempPath, UriKind.Absolute));
                        presentationPart.Presentation.Save();


                        File.WriteAllBytes(tempPathResult, stream.ToArray());
玛格洛斯

我遇到了同样的问题,只是移动

File.WriteAllBytes(tempPathResult, stream.ToArray());

使用之外

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章