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();
}
不仅可以添加图片也可以添加文字、添加多媒体对象、OLE对象,PPT中添加Word\Excel\PPT\Flsh文件。
http://www.cnblogs.com/SanMaoSpace/archive/2013/02/19/2917739.html
PPT中添加对象:
/// <summary> /// 添加图片 /// </summary> /// <param name="slide"></param> /// <param name="filePath"></param> private void AddADPicture(PowerPoint.Slide slide, string filePath) { PowerPoint.Shape pic; pic = slide.Shapes.AddPicture(filePath, Office.MsoTriState.msoFalse, Office.MsoTriState.msoTrue, 100, 200, 100, 100); pic.Name = "GlodonAD"; } /// <summary> /// 添加多媒体文件 /// </summary> /// <param name="slide"></param> /// <param name="filePath"></param> private void AddMedia(PowerPoint.Slide slide, string filePath) { PowerPoint.Shape media; media = slide.Shapes.AddMediaObject(filePath, 10, 10, 200, 200); media.Name = "Media"; } //对于OLED对象标识:http://msdn.microsoft.com/zh-cn/library/office/ff746158.aspx /// <summary> /// 通过ClassName创建对象 /// </summary> /// <param name="slide"></param> /// <param name="className"></param> private void AddOLEDClass(PowerPoint.Slide slide, string className) { PowerPoint.Shape oledClass; oledClass = slide.Shapes.AddOLEObject(50, 50, 800, 500, ClassName: className, DisplayAsIcon: Office.MsoTriState.msoTrue); oledClass.Name = "OLEDClassName"; } /// <summary> /// 通过文件路径,添加文件 /// </summary> /// <param name="slide"></param> /// <param name="filePath"></param> private void AddOLEDPath(PowerPoint.Slide slide, string filePath) { PowerPoint.Shape oledFile; oledFile = slide.Shapes.AddOLEObject(50, 50, 800, 500, FileName: filePath, DisplayAsIcon: Office.MsoTriState.msoTrue);//, DisplayAsIcon: Office.MsoTriState.msoTrue oledFile.Name = "OLEDFilePath"; }
PPT中添加对象调用:
string filePath = "E:\\FF.doc"; filePath = "E:\\FF.ppt"; filePath = "E:\\FF.xls"; filePath = @"C:\Users\Administrator\Videos\PB043926.AVI"; filePath = @"C:\Users\Administrator\Videos\轻轻的问候.swf"; //AddMedia(slide, filePath); AddOLEDPath(slide, filePath); string className = "Excel.Sheet"; className = "Word.Document"; className = "PowerPoint.Slide"; // AddOLEDClass(slide, className);