如何使用OOXML和c#将Power Point幻灯片复制到演示文稿中

编程入门 行业动态 更新时间:2024-10-12 03:16:23
本文介绍了如何使用OOXML和c#将Power Point幻灯片复制到演示文稿中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在一个循环中我使用OOXML和C#创建Power Point幻灯片。后我保存它们(一次一个),我复制滑入使用以下代码Final_presentation.pptx文件:

公共无效CopySlideIntoPresentation(串slide_to_copy,串presentation_to_save) { //生成随机数 Random random = new Random(); int i = random.Next(10,100000); $ //将幻灯片复制到final_presentation using(PresentationDocument newDocument = PresentationDocument.Open(presentation_to_save,true)) { PresentationDocument templateDocument = PresentationDocument.Open(slide_to_copy,FALSE); UINT UNIQUEID = GetMaxIdFromChild(newDocument.PresentationPart.Presentation.SlideMasterIdList); UINT maxId = GetMaxIdFromChild(newDocument.PresentationPart.Presentation.SlideIdList); // SlidePart oldPart = GetSlidePartByTagName(templateDocument," RID1"); SlidePart oldPart = templateDocument.PresentationPart.SlideParts.First(); &NBSP ; SlidePart NEWPART = newDocument.PresentationPart.AddPart< SlidePart>(oldPart,"的SourceID" + I); SlideMasterPart newMasterPart = newDocument.PresentationPart.AddPart(newPart.SlideLayoutPart.SlideMasterPart); SlideIdList idList = newDocument.PresentationPart.Presentation.SlideIdList; $   ; //创建新的幻灯片ID maxId ++; $ SlideId newId = new SlideId(); $ newId.Id = maxId; newId.RelationshipId =" sourceId" + i; idList.Append(newId); $   ; //创建新的主幻灯片ID uniqueId ++; $ SlideMasterId newMasterId = new SlideMasterId(); $ newMasterId.Id = uniqueId; newMasterId.RelationshipId = newDocument.PresentationPart.GetIdOfPart(newMasterPart); &NBSP ; newDocument.PresentationPart.Presentation.SlideMasterIdList.Append(newMasterId); &NBSP ; //更改幻灯片布局ID FixSlideLayoutIds(newDocument.PresentationPart); $ //newPart.Slide.Save(); templateDocument.Close(); $ newDocument.PresentationPart.Presentation.Save(); newDocument.Close(); //返回true; } }

即使将所有幻灯片复制到final_presentation.pptx文件中,打开时也会出现以下错误:

" Powerpoint在final_presntation.pptx中找到了不可读的内容。您想恢复此演示文稿的内容吗?如果您信任此演示文稿的来源,请单击是"

我单击"是"和"是"。然后我得到:

"使用Microsoft Office Powerpoint无法打开该文件。是否要在Microsoft Office Online网站上搜索可以打开该文件的转换器? "

我点击"否"我可以看到新的幻灯片插入到这个final_presentation文件中。

有人可以帮我解决这个错误吗?

谢谢

解决方案

我将其发布到此类别进行讨论。

感谢您的理解和支持。

Within a loop I create Power Point slides using OOXML and C#. After I save them (one at a time) , I copy that slide into a Final_presentation.pptx file using the following code:

public void CopySlideIntoPresentation(string slide_to_copy, string presentation_to_save) { //generate a random number Random random = new Random(); int i = random.Next(10, 100000); //Copy slide into final_presentation using (PresentationDocument newDocument = PresentationDocument.Open(presentation_to_save, true)) { PresentationDocument templateDocument = PresentationDocument.Open(slide_to_copy, false); uint uniqueId = GetMaxIdFromChild(newDocument.PresentationPart.Presentation.SlideMasterIdList); uint maxId = GetMaxIdFromChild(newDocument.PresentationPart.Presentation.SlideIdList); //SlidePart oldPart = GetSlidePartByTagName(templateDocument, "rId1"); SlidePart oldPart = templateDocument.PresentationPart.SlideParts.First(); SlidePart newPart = newDocument.PresentationPart.AddPart<SlidePart>(oldPart, "sourceId" + i); SlideMasterPart newMasterPart = newDocument.PresentationPart.AddPart(newPart.SlideLayoutPart.SlideMasterPart); SlideIdList idList = newDocument.PresentationPart.Presentation.SlideIdList; // create new slide ID maxId++; SlideId newId = new SlideId(); newId.Id = maxId; newId.RelationshipId = "sourceId" + i; idList.Append(newId); // Create new master slide ID uniqueId++; SlideMasterId newMasterId = new SlideMasterId(); newMasterId.Id = uniqueId; newMasterId.RelationshipId = newDocument.PresentationPart.GetIdOfPart(newMasterPart); newDocument.PresentationPart.Presentation.SlideMasterIdList.Append(newMasterId); // change slide layout ID FixSlideLayoutIds(newDocument.PresentationPart); //newPart.Slide.Save(); templateDocument.Close(); newDocument.PresentationPart.Presentation.Save(); newDocument.Close(); //return true; } }

Even though all the slides get copied into final_presentation.pptx file, I get the following error when open it:

"Powerpoint found unreadable content in final_presntation.pptx. Do you want to recover the contents of this presentation? If you trust the source of this presentation click Yes"

I click "yes" and then I get:

"The file cannot be open by using Microsoft Office Powerpoint. Do you want to search the Microsoft Office Online website for a converter that can open the file? "

I click "No" and I can see the new slide inserted into this final_presentation file.

Can someone help me to solve this error?

THANKS

解决方案

I post it to this category for good discussion.

Thanks for your understanding and support.

更多推荐

如何使用OOXML和c#将Power Point幻灯片复制到演示文稿中

本文发布于:2023-10-31 10:46:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545853.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:幻灯片   如何使用   演示文稿   Power   OOXML

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!