【问题标题】:OpenXml ChangeDocumentTypeOpenXml 更改文档类型
【发布时间】:2014-09-30 15:03:02
【问题描述】:

我需要将 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());

【问题讨论】:

    标签: openxml openxml-sdk


    【解决方案1】:

    我有同样的问题,只是移动

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

    在使用之外

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-06
      相关资源
      最近更新 更多