使用Open XML SDK合并powerpoint幻灯片后,无法编辑表格或图表数据 [英] Can't edit the table or chart data after merging the powerpoint slides using Open XML SDK

查看:77
本文介绍了使用Open XML SDK合并powerpoint幻灯片后,无法编辑表格或图表数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我使用Open XML SDK将多个powerpoint文档合并为一个。我们在这些powerpoint文档上有一些可以编辑的表格和图表。


我使用了文章中描述的合并powerpoint文档的类似过程。


http://openxmldeveloper.org/blog/b/openxmldeveloper/ archive / 2011/01/28 / 110420.aspx


但是一旦合并这些,我就无法编辑表/图表数据并显示错误


"无法找到服务器应用程序,源文件或项目,或者返回了一个未知错误。您可能需要重新安装服务器应用程序"


我在某些地方读过,如果文档是压缩的,则可能会发生这种情况格式。我不确定如何在open xml中对其进行编辑。


感谢您的帮助。



以下是示例代码



 


  PresentationDocument myMonthlyDeck = null;

   myMonthlyDeck = PresentationDocument.Open(" output.pptx",true);


   VAR inputFilePaths = Directory.GetFiles(QUOT; \\input"," * PPTX"。);


的foreach(字符串中inputFilePaths pptname)

                {

$


               ;        MergeSlides(pptname,myMonthlyDeck);

      



                }




       static void MergeSlides(string sourcePresentation,PresentationDocument myDestDoc)

        {

            int id = 0;



            {

                PresentationPart destPresPart = myDestDoc.PresentationPart;



             &NBSP ;  如果(destPresPart.Presentation.SlideIdList == NULL)

               &NBSP ;    destPresPart.Presentation.SlideIdList =新SlideIdList();



           &NBSP ;    PresentationDocument mySourceDeck = PresentationDocument.Open(sourcePresentation,FALSE);

                //使用()

                {

                    PresentationPart sourcePresPart = mySourceDeck.P​​resentationPart;



             &NBSP ;      //获取幻灯片母版和幻灯片列表的唯一ID以供日后使用。

                     UNIQUEID = GetMaxSlideMasterId(destPresPart.Presentation.SlideMasterIdList);

               &NBSP ;    UINT maxSlideId = GetMaxSlideId(destPresPart.Presentation.SlideIdList);



                     //将源演示文稿中的每张幻灯片复制到目的地演示文稿。

                    的foreach(SlideId slideId在sourcePresPart.Presentation.SlideIdList)

               &NBSP ;    {

                    &NBSP ;   SlidePart SP;

                   &NBSP ;    SlidePart destSp;

                   &NBSP ;    SlideMasterPart destMasterPart;

                   &NBSP ;   串RELID;

                   &NBSP ;    SlideMasterId newSlideMasterId;

                   &NBSP ;    SlideId newSlideId;



               &NBSP ;        //创建一个唯一的关系ID。

                         ID ++;

                         SP =(SlidePart)sourcePresPart.GetPartById(slideId.RelationshipId);

                        字符串文件名= Path.GetFileName(sourcePresentation).Replace(QUOT;"," C");

         &NBSP ;              relId =" c" + filename.Trim()+ id;



               ;           //滑动部分添加到目标演示

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; destSp = destPresPart.AddPart< SlidePart>(SP,RELID);



&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; //主要部分已添加。确保关系到位。

                  &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; destMasterPart = destSp.SlideLayoutPart.SlideMasterPart;

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; destPresPart.AddPart(destMasterPart);



&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; //添加幻灯片母版到幻灯片母版列表

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; UNIQUEID ++;

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; newSlideMasterId =新SlideMasterId();

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; newSlideMasterId.RelationshipId = destPresPart.GetIdOfPart(destMasterPart);

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; newSlideMasterId.Id = uniqueId;
$


               &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; //将幻灯片添加到幻灯片列表。

                  &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; maxSlideId ++;

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; newSlideId =新SlideId();

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; newSlideId.RelationshipId = RELID;

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP; newSlideId.Id = maxSlideId;



&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; destPresPart.Presentation.SlideMasterIdList.Append(newSlideMasterId);

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; destPresPart.Presentation.SlideIdList.Append(newSlideId);

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP; }



&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP; //确保所有幻灯片ID都是唯一的。

                 &NBSP;&NBSP;&NBSP; FixSlideLayoutIds(destPresPart);

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; }


                //将更改保存到目的卡组。

                destPresPart.Presentation.Save();

                mySourceDeck.Close();

            }


        }



< /跨度>


<小时类= "SIG">

VM7258

解决方案

VM7258


感谢您对MSDN论坛发帖。


您在你的程序失去TableStylePart / ChartPart。


我希望它可以帮到你。


祝你有个美好的一天,


Tom


Hi,

I used Open XML SDK to merge multiple powerpoint documents into one.We have some of the tables and charts on these power point documents which can be editable.

I used similar process which is described in the articleto merge powerpoint documents.

http://openxmldeveloper.org/blog/b/openxmldeveloper/archive/2011/01/28/110420.aspx

But once these are merged, I can't edit the tables / charts data and displays the error

"The server application, source file, or item can’t be found, or returned an unknown error. You may need to reinstall the server application"

I read in some places that it may happen if the document is in compressed format. I am not sure how to make it editable in open xml.

I appreciate your help.

Here is the sample code

 

  PresentationDocument myMonthlyDeck = null;
   myMonthlyDeck = PresentationDocument.Open("output.pptx", true);

   var inputFilePaths = Directory.GetFiles("\\input","*.pptx");

foreach (string pptname in inputFilePaths)
                {


                     MergeSlides(pptname, myMonthlyDeck);
      

                }

       static void MergeSlides(string sourcePresentation, PresentationDocument myDestDoc)
        {
            int id = 0;

            {
                PresentationPart destPresPart = myDestDoc.PresentationPart;

                 if (destPresPart.Presentation.SlideIdList == null)
                    destPresPart.Presentation.SlideIdList = new SlideIdList();

                PresentationDocument mySourceDeck = PresentationDocument.Open(sourcePresentation, false);
                // using ()
                {
                    PresentationPart sourcePresPart = mySourceDeck.PresentationPart;

                    // Get unique ids for the slide master and slide lists for use later.
                    uniqueId = GetMaxSlideMasterId(destPresPart.Presentation.SlideMasterIdList);
                    uint maxSlideId = GetMaxSlideId(destPresPart.Presentation.SlideIdList);

                    // Copy each slide in the source presentation in order to the destination presentation.
                    foreach (SlideId slideId in sourcePresPart.Presentation.SlideIdList)
                    {
                        SlidePart sp;
                        SlidePart destSp;
                        SlideMasterPart destMasterPart;
                        string relId;
                        SlideMasterId newSlideMasterId;
                        SlideId newSlideId;

                        // Create a unique relationship id.
                        id++;
                        sp = (SlidePart)sourcePresPart.GetPartById(slideId.RelationshipId);
                        string filename = Path.GetFileName(sourcePresentation).Replace(" ", "c");
                        relId = "c" + filename.Trim() + id;

                        // Add the slide part to the destination presentation.
                        destSp = destPresPart.AddPart<SlidePart>(sp, relId);

                        // The master part was added. Make sure the relationship is in place.
                        destMasterPart = destSp.SlideLayoutPart.SlideMasterPart;
                        destPresPart.AddPart(destMasterPart);

                        // Add slide master to slide master list.
                        uniqueId++;
                        newSlideMasterId = new SlideMasterId();
                        newSlideMasterId.RelationshipId = destPresPart.GetIdOfPart(destMasterPart);
                        newSlideMasterId.Id = uniqueId;

                        // Add slide to slide list.
                        maxSlideId++;
                        newSlideId = new SlideId();
                        newSlideId.RelationshipId = relId;
                        newSlideId.Id = maxSlideId;

                        destPresPart.Presentation.SlideMasterIdList.Append(newSlideMasterId);
                        destPresPart.Presentation.SlideIdList.Append(newSlideId);
                    }

                    // Make sure all slide ids are unique.
                    FixSlideLayoutIds(destPresPart);
                }

                // Save the changes to the destination deck.
                destPresPart.Presentation.Save();
                mySourceDeck.Close();
            }

        }


VM7258

解决方案

Hi VM7258,

Thanks for posting in the MSDN Forum.

You lost TableStylePart/ChartPart in your program.

I hope it can help you.

Have a good day,

Tom


这篇关于使用Open XML SDK合并powerpoint幻灯片后,无法编辑表格或图表数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆