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());