我需要将powerpoint模板从potx转换为pptx。如图所示:http://www.codeproject.com/Tips/366463/Create-PowerPoint-presentation-using-PowerPoint-te,我尝试了以下代码。但是,生成的pptx文档无效,无法打开。如果跳过行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());发布于 2015-05-14 11:02:43
我也有同样的问题,快走
File.WriteAllBytes(tempPathResult, stream.ToArray());在使用之外
https://stackoverflow.com/questions/26124088
复制相似问题