簡體   English   中英

OpenXml ChangeDocumentType

[英]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());

使用之外

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM