首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OpenXml ChangeDocumentType

OpenXml ChangeDocumentType
EN

Stack Overflow用户
提问于 2014-09-30 15:03:02
回答 1查看 228关注 0票数 0

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

代码语言:javascript
复制
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());
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-05-14 11:02:43

我也有同样的问题,快走

代码语言:javascript
复制
File.WriteAllBytes(tempPathResult, stream.ToArray());

在使用之外

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26124088

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档