也进行了一些测试性的代码:
PowerPoint.Slides slides = Globals.ThisAddIn.Application.ActivePresentation.Slides;
for (int i = 1; i <= slides.Count; i++)
{
MessageBox.Show("第" + i + "个Slid!");
PowerPoint.Slide slide = slides[i];
PowerPoint.Shapes shapes = slide.Shapes;
PowerPoint.Shapes tempShapes = null;//用来存放添加的图片的集合信息
int count = shapes.Count;//元素集合总数是变化的
for (int j = 1; j <= count; j++)
{
if (shapes[j].Type == MsoShapeType.msoMedia || shapes[j].Type == MsoShapeType.msoPicture)//如果为多媒体或图片
{
MessageBox.Show("MediaName:" + shapes[j].Name);//多媒体信息
if (Globals.ThisAddIn.IsEncrypt)//判断是否加密
{
shapes[j].Visible = MsoTriState.msoFalse;//将原来多媒体隐藏
string picPath = @"c:\广告图片.PNG";//替换的图片
AddPicture(slide, shapes[j], picPath);//隐藏多媒体,替换图片
}
else
{
shapes[j].Visible = MsoTriState.msoTrue;//将原来多媒体显示
if (shapes[j].Name == "广告图片")//如果这张图片已添加
{
//shapes[j].Delete();//删除该图片
//MessageBox.Show("删除成功!");
shapes[j].Visible = MsoTriState.msoFalse;//隐藏该图片
}
}
}
}
//向slide中添加文本框
string txtContent = e.Start.ToLongDateString();
AddTextBox(slide, txtContent);//向slide中添加TextBox文本框
}
private void AddTextBox(PowerPoint.Slide slide, string txtContent)
{
PowerPoint.Shape textbox;
textbox = slide.Shapes.AddTextbox(Office.MsoTextOrientation.msoTextOrientationHorizontal, 50, 100, 600, 50);//向当前PPT添加文本框
textbox.TextFrame.TextRange.Text = txtContent;//设置文本框的内容
textbox.TextFrame.TextRange.Font.Size = 48;//设置文本字体大小
textbox.TextFrame.TextRange.Font.Color.RGB = Color.DarkViolet.ToArgb();//设置文本颜色
}
private void AddPicture(PowerPoint.Slide slide, PowerPoint.Shape shape, string filePath)
{
PowerPoint.Shape pic;
pic = slide.Shapes.AddPicture(filePath, Office.MsoTriState.msoFalse, Office.MsoTriState.msoTrue, shape.Left, shape.Top, shape.Width, shape.Height);
pic.Name = "广告图片";
pic.Height = shape.Height;
pic.Width = shape.Width;
}
private void AddTextMessage(PowerPoint.Slide slide, PowerPoint.Shape shape, string txtContent)
{
PowerPoint.Shape textbox;
textbox = slide.Shapes.AddTextbox(Office.MsoTextOrientation.msoTextOrientationHorizontal, shape.Left, shape.Top, shape.Width, shape.Height);//向当前PPT添加文本框
textbox.Height = shape.Height;
textbox.Width = shape.Width;
textbox.TextFrame.TextRange.Text = txtContent;
textbox.TextFrame.TextRange.Font.Color.RGB = Color.Orange.ToArgb();
}
希望大牛给出一些建议。
路漫漫其修远兮,吾将上下而求索!