//下面这句老是出问题 我不知道问题出在哪儿? 希望能帮我解决   我要实现的功能是 通过程序打开一个PPT 然后自动修改PPT的背景图 pp.Slides.Application.ActiveWindow.Selection.SlideRange.Background.Fill.UserPicture(@"C:\Documents and Settings\Administrator\桌面\博研360.jpg");
以下是详细代码: 需要整个项目的可以加我QQ:54540387
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Office.Interop.PowerPoint;namespace WindowsApplication7
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }        private void button1_Click(object sender, EventArgs e)
        {
            Microsoft.Office.Interop.PowerPoint.ApplicationClass pa;            Microsoft.Office.Interop.PowerPoint.Presentation pp;
            pa = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();            pp = pa.Presentations.Open(@"G:\项目\博研\测试.ppt", Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse);
            Microsoft.Office.Interop.PowerPoint.TextRange oText;
            int slideCount = pp.Slides.Count;//总的幻灯片数
            //下面这句老是出问题 我不知道问题出在哪儿? 希望能帮我解决   我要实现的功能是 通过程序打开一个PPT 然后自动修改PPT的背景图
            pp.Slides.Application.ActiveWindow.Selection.SlideRange.Background.Fill.UserPicture(@"C:\Documents and Settings\Administrator\桌面\博研360.jpg");
            
            label1.Text = slideCount.ToString();
            pp.SaveAs(@"G:\项目\博研\测试2.ppt", Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsPowerPoint7, Microsoft.Office.Core.MsoTriState.msoTrue);        }        private void Form1_Load(object sender, EventArgs e)
        {        }
    }
}

解决方案 »

  1.   

    先要测一下pp = pa.Presentations.Open(@"G:\项目\博研\测试.ppt", 是否打开了PPT呀,要测试就要工程,可以发到[email protected],测的试试。
      

  2.   

    没有打开ppt,后面才会出现问题,open openold都不行,没办法了,哎
      

  3.   

      private void button2_Click(object sender, EventArgs e)
            {
                Microsoft.Office.Interop.PowerPoint.ApplicationClass pa;
                Microsoft.Office.Interop.PowerPoint.Presentation pp;
                pa = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();
                try
                { pp = pa.Presentations.Open(@"C:\Downloads\遗传算法.ppt", Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse);
                    pa.Activate();
                    pp.NewWindow();
                    //pp = pa.Presentations.OpenOld(@"C:\Downloads\遗传算法.ppt", Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse);
                    int slideCount = pp.Slides.Count;//总的幻灯片数 
                    //pp.Slides.Application.ActiveWindow.Selection.SlideRange.Background.Fill.UserPicture(@"C:\Documents and Settings\Administrator\My Documents\My Pictures\large_2668o107.jpg");
                    //pp.SlideShowWindow.Application.ActiveWindow.Selection.SlideRange.Background.Fill.UserPicture(@"C:\Documents and Settings\Administrator\My Documents\My Pictures\large_2668o107.jpg");
                    pp.Application.ActiveWindow.Selection.SlideRange.Background.Fill.UserPicture(@"C:\Documents and Settings\Administrator\My Documents\My Pictures\large_2668o107.jpg");
                    //pp.Windows.Application.ActiveWindow.Selection.SlideRange.Background.Fill.UserPicture(@"C:\Documents and Settings\Administrator\My Documents\My Pictures\large_2668o107.jpg");
                    //pp.SlideShowWindow.Application.ActiveWindow.Selection.SlideRange.Background.Fill.UserPicture(@"C:\Documents and Settings\Administrator\My Documents\My Pictures\large_2668o107.jpg");
                    label1.Text = slideCount.ToString();
                    pp.SaveAs(@"C:\Downloads\遗传算法1.ppt", Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsPowerPoint7, Microsoft.Office.Core.MsoTriState.msoTrue);
                    pp.Close();
                    pa.Quit();            }
                catch
                {
                    //MessageBox.Show("NO");            }
                
            }打开了,也另存为了,就是没有改背景,哎
      

  4.   

    详细项目文件及其源代码可以到 http://www.down100.cn 下载
      

  5.   

    pp.Application.ActiveWindow.Selection.SlideRange.Background.Fill.UserPicture(@"C:\Documents and Settings\Administrator\My Documents\My Pictures\large_2668o107.jpg");这句话实际已经执行错误了。
      

  6.   

    各位 怎么获取ppt的分辨率呢