复制粘贴的Powerpoint offcie 2013幻灯片失败。有人可以指导我下面的代码有什么问题吗?或者必须从哪里复制剪贴板数据。 [英] Copy Paste of a Powerpoint offcie 2013 slide fails.Can someone guide me as to what is wrong in the below code? or where is it that clipboard data has to be copied from.

查看:254
本文介绍了复制粘贴的Powerpoint offcie 2013幻灯片失败。有人可以指导我下面的代码有什么问题吗?或者必须从哪里复制剪贴板数据。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


using System;



using System.Collections .Generic;



using System.Linq;



使用 System.Text;



使用 Powerpoint = Microsoft.Office.Interop.PowerPoint;



使用 Office = Microsoft.Office.Core;





namespace Powerpoint_Aspect_Ratio



{



   
class 计划



    {      





        static
void Main( string [] args)



        {



            Powerpoint。 Application oAppPowerpoint;



            Powerpoint。 Presentation objPres;



            Powerpoint。 Presentation objPres1;



           
试用



            {



                oAppPowerpoint =
new Powerpoint。申请();



                Powerpoint。演示文稿 ppPrens = oAppPowerpoint.Presentations;



               
string filename = @" C:\ppttest\16.pptx" ;



                objPres = ppPrens.Open(filename,Office。 MsoTriState .msoFalse,
Office。 MsoTriState .msoFalse,Office。 MsoTriState .msoFalse);



               
int slidecount = objPres.Slides.Count;



               
int i = 0;



               
foreach (Powerpoint。幻灯片幻灯片
objPres.Slides)



                {



                    slide.Copy();



                    Powerpoint。演示文稿 ppPrens1
= oAppPowerpoint.Presentations;



                   
string filename1 = @" C:\\\ gtttest \ test.pptx" ;



                    objPres1 = ppPrens1.Open(filename1 ,Office。 MsoTriState .msoFalse,
Office。 MsoTriState .msoFalse,Office。< span style ="color:#2B91AF"> MsoTriState
.msoFalse);



                   
int tempslidecount = objPres1.Slides.Count;



                    Powerpoint。幻灯片 pasteSlides = objPres1.Slides;



                    pasteSlides.Paste(-1) ;



                    objPres1.Save();





               }



                objPres.Close();



                oAppPowerpoint.Quit();



           }



           
catch 例外 ex)



            {





           }





       }



   }



}




注意:示例在Office 2010中工作正常,但在Office2013中没有。


2013年办公室发生异常:


< span style ="color:#C00000; background:yellow">消息="幻灯片(未知成员):无效请求。 剪贴板为空或包含可能未在此处粘贴的数据。"

解决方案

除了我上面发布的内容,如果我们按照我在此评论中发布的方式尝试,将powerpointslide复制到临时幻灯片,但当我从临时幻灯片复制到名为"测试"的新幻灯片时,它再次失败。剪贴板是
仍然是空的。有人请解释一下,如果你能找到这个代码的问题这就是为什么剪贴板为空以及如何从中复制数据(ppt)。


使用System;

使用Powerpoint = Microsoft.Office.Interop .PowerPoint;

使用Office = Microsoft.Office.Core;



命名空间ConsoleApplication1

{

///< summary>

/// Summar对于Class1的描述。

///< / summary>

类Class1

{

///< summary>

///主要切入点应用程序。

///< / summary>

[STAThread]

static void Main(string [] args)

{

Powerpoint.Application oAppPowerpoint;

Powerpoint.Presentation objPres;

Powerpoint.Presentation objPres1;

试试
{

oAppPowerpoint = new Powerpoint.Application();

Powerpoint.Presentations ppPrens = oAppPowerpoint.Presentations;

string filename = @" C:\ pttest\16.pptx" ;;

< span style ="white-space:pre"> objPres = ppPrens.Open(filename,Office.MsoTriState.msoFalse,Office.MsoTriState.msoFalse,Office.MsoTriState.msoFalse);

int slidecount = objPres.Slides.Count;


foreach(在objPres.Slides中的Powerpoint.Slide幻灯片)

{  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;  

// slide.Copy();

string tempfilename = @" C:\ppttest\temp" ;;

幻灯片。导出(tempfilename," ppt",800,600);

Powerpoint.Presentations ppPrens1 = oAppPowerpoint.Presentations;

string filename1 = @" C:\\\ gtttest \ test.pptx"; $
objPres1 = ppPrens1.Open(filename1,Office.MsoTriState.msoFalse,Office.MsoTriState.msoFalse,Office.MsoTriState.msoFalse);

int tempslidecount = objPres1.Slides.Count;

Powerpoint.Slides pasteSlides = objPres1.Slides;

// pasteSlides.Paste(-1);


pasteSlides.InsertFromFile(tempfilename +" .ppt",0,1,-1);

objPres1.Save();
$


}

objPres.Close();

oAppPowerpoint。退出();

}

catch(exception ex)

{

Console.WriteLine(ex.Message);

}

< span style ="white-space:pre"> }

}

}


  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;&NBSP;

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using Powerpoint = Microsoft.Office.Interop.PowerPoint;

using Office = Microsoft.Office.Core;

namespace Powerpoint_Aspect_Ratio

{

    class Program

    {      

        static void Main(string[] args)

        {

            Powerpoint.Application oAppPowerpoint;

            Powerpoint.Presentation objPres;

            Powerpoint.Presentation objPres1;

            try

            {

                oAppPowerpoint = new Powerpoint.Application();

                Powerpoint.Presentations ppPrens = oAppPowerpoint.Presentations;

                string filename = @"C:\ppttest\16.pptx";

                objPres = ppPrens.Open(filename, Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse);

                int slidecount = objPres.Slides.Count;

                int i = 0;

                foreach (Powerpoint.Slide slide in objPres.Slides)

                {

                    slide.Copy();

                    Powerpoint.Presentations ppPrens1 = oAppPowerpoint.Presentations;

                    string filename1 = @"C:\ppttest\test.pptx";

                    objPres1 = ppPrens1.Open(filename1, Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse);

                    int tempslidecount = objPres1.Slides.Count;

                    Powerpoint.Slides pasteSlides = objPres1.Slides;

                    pasteSlides.Paste(-1);

                    objPres1.Save();

                }

                objPres.Close();

                oAppPowerpoint.Quit();

            }

            catch (Exception ex)

            {

            }

        }

    }

}

Note: The sample works fine in Office 2010 but not in Office2013.

Exception occurs for office 2013:

Message = "Slides (unknown member): Invalid request.  Clipboard is empty or contains data which may not be pasted here."

解决方案

In addition to what I posted above if we try it the way i have posted in this comment the powerpointslide is copied to the temporary slide but when I copy it from the temporary slide to a new slide named "test" here it again fails.The clipboard is still empty.Can someone please also explain if you are able to find the issue with this code that why is clipboard empty and how to copy data(ppt) from that.

using System;
using Powerpoint = Microsoft.Office.Interop.PowerPoint;
using Office = Microsoft.Office.Core;

namespace ConsoleApplication1
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Powerpoint.Application oAppPowerpoint;
Powerpoint.Presentation objPres;
Powerpoint.Presentation objPres1;
try
{
oAppPowerpoint = new Powerpoint.Application();
Powerpoint.Presentations ppPrens = oAppPowerpoint.Presentations;
string filename = @"C:\ppttest\16.pptx";
objPres = ppPrens.Open(filename, Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse);
int slidecount = objPres.Slides.Count;
foreach (Powerpoint.Slide slide in objPres.Slides)
{                                        
//slide.Copy();
string tempfilename = @"C:\ppttest\temp";
slide.Export(tempfilename,"ppt",800,600);
Powerpoint.Presentations ppPrens1 = oAppPowerpoint.Presentations;
string filename1 = @"C:\ppttest\test.pptx";
objPres1 = ppPrens1.Open(filename1, Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse);
int tempslidecount = objPres1.Slides.Count;
Powerpoint.Slides pasteSlides = objPres1.Slides;
//pasteSlides.Paste(-1);
pasteSlides.InsertFromFile(tempfilename+".ppt",0,1,-1);
objPres1.Save();

}
objPres.Close();
oAppPowerpoint.Quit();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}

                    


这篇关于复制粘贴的Powerpoint offcie 2013幻灯片失败。有人可以指导我下面的代码有什么问题吗?或者必须从哪里复制剪贴板数据。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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