想问下怎么用C#按照需求自动生成PPT
最近需要做一个自动生成PPT的程序。。。一天头绪都没有。。网上搜到那些也看不太懂。。。 --------------------编程问答-------------------- 很多问题不是无法解决,而是无法在你的认知范围内解决。
就像让你算个微分方程没什么难度,但是让你教一个小学生算,你一定觉得很难办。
实在不行你就花钱找人帮你开发算了。 --------------------编程问答-------------------- 用微软提供的dll,一般在vs的安装目录下,比如
D:\Program Files\Microsoft Visual Studio 10.0\Visual Studio Tools for Office\PIA\Office12里面有关于office操作的dll,ppt的是
Microsoft.Office.Interop.PowerPoint.dll --------------------编程问答-------------------- http://support.microsoft.com/kb/303718/zh-cn --------------------编程问答--------------------
2008-09-09 15:33 c# 生成ppt using System;
using Microsoft.Office.Core;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using Graph = Microsoft.Office.Interop.Graph;
using System.Runtime.InteropServices;
namespace ExportPPT
{
/// <summary>
/// Summary description for OperatePPT.
/// </summary>
public class OperatePPT
{
public OperatePPT()
{
//
// TODO: Add constructor logic here
//
}
public static void InsertText(PowerPoint._Slide slide,string text,float left,float top,float width,float height)
{
PowerPoint.Shape shape = slide.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal,left,top,width,height);
PowerPoint.TextRange textRng = shape.TextFrame.TextRange;
textRng.Text = text;
}
public static void InsertPicture(PowerPoint._Slide slide,string fileName,float left,float top,float width,float height)
{
slide.Shapes.AddPicture(fileName,Microsoft.Office.Core.MsoTriState.msoFalse,Microsoft.Office.Core.MsoTriState.msoTrue,left,top,width,height);
}
public static void SetCanvas(PowerPoint._Slide slide,float left,float top,float width,float height)
{
slide.Shapes.AddCanvas(left,top,width,height);
}
public static void InsertMedia(PowerPoint._Slide slide,string fileName,float left,float top,float width,float height)
{
PowerPoint.Shape shape = slide.Shapes.AddMediaObject(fileName,left,top,width,height);
PowerPoint.AnimationSettings mediaSettings = shape.AnimationSettings;
PowerPoint.PlaySettings oPlaySettings = mediaSettings.PlaySettings;
oPlaySettings.PlayOnEntry = Microsoft.Office.Core.MsoTriState.msoTrue;
}
public static void InsertFlash(PowerPoint._Slide slide,string fileName,float left,float top,float width,float height)
{
ShockwaveFlashObjects.ShockwaveFlashClass flash =
(ShockwaveFlashObjects.ShockwaveFlashClass) slide.Shapes.AddOLEObject(left,top,width, height,"ShockwaveFlash.ShockwaveFlash.9", "", MsoTriState.msoFalse, "", 0,"", MsoTriState.msoFalse).OLEFormat.Object;
flash.Movie = fileName;
}
public static void Test()
{
PowerPoint.Application application;
PowerPoint.Presentations presentations;
PowerPoint._Presentation presentation;
PowerPoint.Slides slides;
PowerPoint._Slide slide;
PowerPoint.SlideRange objSldRng;
PowerPoint.SlideShowSettings objSSS;
PowerPoint.SlideShowTransition objSST;
PowerPoint.SlideShowWindows objSSWs;
//create application
application = new PowerPoint.ApplicationClass();
application.Visible = MsoTriState.msoTrue;
presentations = application.Presentations;
presentation = presentations.Add(Microsoft.Office.Core.MsoTriState.msoTrue);
//add first silde
slides = presentation.Slides;
slide = slides.Add(1,Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutTitleOnly);
//InsertText(slide,"Hello World",0,0,200,200);
//InsertPicture(slide,@"C:\pic.jpg",0,200,300,200);
InsertFlash(slide,@"C:\xiyou.swf",0,0,200,200);
//InsertMedia(slide,@"c:\bjhyn.wmv",200,200,200,200);
int[] SlideIdx = new int[1];
for(int i=0;i<1;i++) SlideIdx[i]=i+1;
objSldRng = slides.Range(SlideIdx);
objSST = objSldRng.SlideShowTransition;
objSST.AdvanceOnTime = MsoTriState.msoTrue;
objSST.AdvanceTime = 3;
objSST.EntryEffect = PowerPoint.PpEntryEffect.ppEffectBoxOut;
//Prevent Office Assistant from displaying alert messages:
bool bAssistantOn = application.Assistant.On;
application.Assistant.On = false;
//Run the Slide show.
objSSS = presentation.SlideShowSettings;
objSSS.StartingSlide = 1;
objSSS.EndingSlide = 1;
objSSS.Run();
//Wait for the slide show to end.
objSSWs = application.SlideShowWindows;
while(objSSWs.Count>=1) System.Threading.Thread.Sleep(1000);
//Reenable Office Assisant, if it was on:
if(bAssistantOn)
{
application.Assistant.On = true;
application.Assistant.Visible = false;
}
//Close the presentation without saving changes and quit PowerPoint.
presentation.SaveAs(@"c:\fang.ppt",PowerPoint.PpSaveAsFileType.ppSaveAsDefault,Microsoft.Office.Core.MsoTriState.msoTrue);
presentation.Close();
application.Quit();
}
}
}
补充:.NET技术 , C#