0
我需要將powerpoint模板從potx轉換爲pptx。如在這裏看到的:http://www.codeproject.com/Tips/366463/Create-PowerPoint-presentation-using-PowerPoint-te我試着用下面的代碼。但是,生成的pptx文檔無效,無法通過Office Powerpoint打開。如果我跳過newDoc.ChangeDocumentType行,則生成的文檔有效,但不會轉換爲pptx。 templateContentBytes是包含potx文檔內容的字節數組。 和temppath指向其本地版本。OpenXml ChangeDocumentType
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());