Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#:演示文稿保存不起作用_C#_Asp.net_.net_Powerpoint_Add In - Fatal编程技术网

C#:演示文稿保存不起作用

C#:演示文稿保存不起作用,c#,asp.net,.net,powerpoint,add-in,C#,Asp.net,.net,Powerpoint,Add In,我正在尝试保存从磁盘加载的现有powerpoint文件中修改的更改。我成功地打开了文件。 尝试使用saveas方法保存已编辑(已存在)的powerpoint文件时,发现异常 private void adxPowerPointAppEvents1_PresentationBeforeSave(object sender, ADXHostBeforeActionEventArgs e) { try { PowerPoint.Prese

我正在尝试保存从磁盘加载的现有powerpoint文件中修改的更改。我成功地打开了文件。 尝试使用saveas方法保存已编辑(已存在)的powerpoint文件时,发现异常

private void adxPowerPointAppEvents1_PresentationBeforeSave(object sender, ADXHostBeforeActionEventArgs e)
    {
        try
        {
            PowerPoint.Presentation pre = e.HostObject as 
            PowerPoint.Presentation;

            // cancel this operation
            e.Cancel = true;

            //save
            pre.SaveAs(pre.Name, 
    PowerPoint.PpSaveAsFileType.ppSaveAsDefault,Office.MsoTriState.msoTrue);
            MessageBox.Show("you will not see me due to exception");

     }    
     catch(Exception e){}
}

执行代码时

msword和msexcel中使用的方法不起作用


如果有任何一种方法可以保存编辑过的文件,请帮助我。

获得了此问题的解决方案。。。 就像在word、excel中一样,我们无法执行save()操作。。。如果我们从同一事件处理程序(函数)调用save或saveas,则Powerpoint会引发异常。因此,在Powerpoint调用该事件处理程序后,您必须在该事件处理程序之外调用saveas

private void adxPowerPointAppEvents_PresentationBeforeSave(object sender, ADXHostBeforeActionEventArgs e)
        {
            PowerPoint.Presentation pre = e.HostObject as PowerPoint.Presentation;
            try
            {

                if (pre.Saved == Microsoft.Office.Core.MsoTriState.msoFalse)
                {
                    e.Cancel = true;

                    GCHandle handle = GCHandle.Alloc(pre.FullName);
                    IntPtr parameter = (IntPtr)handle;


                    this.SendMessage(MESSAGE_SAVE_PPT, parameter, IntPtr.Zero);
                    pre.Saved = Microsoft.Office.Core.MsoTriState.msoTrue;
                }
            }
            catch(Exception ex)
            {
                Log.Info("Exception while saving powerpoint : " + ex.StackTrace);
                MessageBox.Show(ex.Message);
            }
                return;
        }

private void AddinModule_OnSavePowerPointMessage(object sender, AddinExpress.MSO.ADXSendMessageEventArgs e)
        {
            if (e.Message == MESSAGE_SAVE_PPT)
            {
                PowerPoint.Presentation ppPre = null;
                try
                {
                    GCHandle handle = (GCHandle)e.WParam;
                    String fullName = (handle.Target as String);

                    ppPre = PowerPointApp.Presentations[fullName];
                    if (ppPre != null)
                    {
                        ppPre.Saved = Microsoft.Office.Core.MsoTriState.msoTrue;
                        //ppPre.SaveAs(ppPre.FullName, PowerPoint.PpSaveAsFileType.ppSaveAsDefault, Microsoft.Office.Core.MsoTriState.msoTrue);
                        ppPre.Save();


                        Log.Info("Value of pre.name " + ppPre.Name);
                    }
                }
                catch (Exception exSavePpt)
                {
                    Log.Info("Exception while saving powerpoint : " + exSavePpt.StackTrace);
                }
            }
        }

实际上,在AddinModule_OnSavePowerPointMessage()中,我们不应该传递会创建COM异常的COM对象。因此,我们应该传递表示名(ppt.fullname)并在第二个方法中创建指向同一对象的com引用。所以,现在我可以毫不费力地保存ppt文件了…

您还没有检查theas运算符是否返回null。我不确定这是否会导致您的异常,但我想这是一个很好的ide来更改它。SaveAs()调用引发异常..(详细信息见附件)您能告诉我们为什么您的外接程序取消保存(
e.Cancel=true
),然后在下一行调用
SaveAs
本身吗?实际上,当我键入长段落时,我们经常将文件保存在中间,对吗?对于每个保存事件,都会显示对话框。。我们必须手动按“取消”按钮。。而不是将obj.cancel设置为true,将saveas()设置为truecalled@mjwills对我已经查过那个链接了。。但该解决方案发现更不清楚,也无法提取与此问题相关的任何有用信息。。。我觉得这个解决方案需要改进。