.net中應有一個組件的,你可以通過引用組件找到該.DLL文件,具體的自已去找一下。
解决方案 »
- .NET4.5怎么没有System.Net.Sockets
- dataGridView单元格获得焦点问题,winform中
- C#有些句子看不懂
- c#应用程度调用SQL存储过程的返回值
- winform绘图的项目
- 怎么才能使得DATAGRIDVIEW实现如下图所示的分组功能?
- 一直想问的一个问题
- C#代码运行过程中,如何写代码,将某些数据建立在一个表中,并能对表中某几列进行排序处理
- 求助:如何使一个dom对象内的节点很容易的插入到另外一个dom对象中指定的节点内
- 在不知道json是否包含特定键的时候,如何最快速的判断这个键的值是否是特定值?
- OFFICE图表控件问题,各位大虾帮忙啊!!!!!!
- C#如何调用OFFICE
工具箱不需要添加任何东东,倒是要在引用里要添加上你的excel的引用
Project--> Add Reference--> COM --> Microsoft Excel 9.0 object Lib...
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Office; //Office 2000
using System.Runtime.InteropServices;namespace PPT
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.button1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("button1.BackgroundImage")));
this.button1.Cursor = System.Windows.Forms.Cursors.Hand;
this.button1.Font = new System.Drawing.Font("宋体", 42F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button1.ForeColor = System.Drawing.Color.MediumSlateBlue;
this.button1.Location = new System.Drawing.Point(96, 80);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(304, 200);
this.button1.TabIndex = 0;
this.button1.Text = "调用Microsoft PowerPoint ";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(496, 332);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void button1_Click(object sender, System.EventArgs e)
{
ShowPresentation();
GC.Collect();
} private void ShowPresentation()
{
String strTemplate, strPic;
strTemplate =
@"D:\Microsoft Office\Templates\Presentation Designs\Blends.pot";
strPic = @"C:\Documents and Settings\Edifier\My Documents\My Pictures\CoolPhoto\PCDV0028.JPG";
bool bAssistantOn; PowerPoint.Application objApp;
PowerPoint.Presentations objPresSet;
PowerPoint._Presentation objPres;
PowerPoint.Slides objSlides;
PowerPoint._Slide objSlide;
PowerPoint.TextRange objTextRng;
PowerPoint.Shapes objShapes;
PowerPoint.Shape objShape;
PowerPoint.SlideShowWindows objSSWs;
PowerPoint.SlideShowTransition objSST;
PowerPoint.SlideShowSettings objSSS;
PowerPoint.SlideRange objSldRng;
Graph.Chart objChart; //Create a new presentation based on a template.
objApp = new PowerPoint.Application();
objApp.Visible = MsoTriState.msoTrue;
objPresSet = objApp.Presentations;
objPres = objPresSet.Open(strTemplate,
MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoTrue);
objSlides = objPres.Slides; //Build Slide #1:
//Add text to the slide, change the font and insert/position a
//picture on the first slide.
objSlide = objSlides.Add(1,PowerPoint.PpSlideLayout.ppLayoutTitleOnly);
objTextRng = objSlide.Shapes.Item(1).TextFrame.TextRange;
objTextRng.Text = "看看我们七匹狼,帅呆了吧";
objTextRng.Font.Name = "Comic Sans MS";
objTextRng.Font.Size = 48;
objSlide.Shapes.AddPicture(strPic, MsoTriState.msoFalse, MsoTriState.msoTrue,
150, 150, 500, 350); //Build Slide #2:
//Add text to the slide title, format the text. Also add a chart to the
//slide and change the chart type to a 3D pie chart.
objSlide = objSlides.Add(2, PowerPoint.PpSlideLayout.ppLayoutTitleOnly);
objTextRng = objSlide.Shapes.Item(1).TextFrame.TextRange;
objTextRng.Text = "试一试,图表";
objTextRng.Font.Name = "Comic Sans MS";
objTextRng.Font.Size = 48;
objChart = (Graph.Chart) objSlide.Shapes.AddOLEObject(150,150,480,320,
"MSGraph.Chart", "", MsoTriState.msoFalse, "", 0, "",
MsoTriState.msoFalse).OLEFormat.Object;
objChart.ChartType = Graph.XlChartType.xl3DPie;
objChart.Legend.Position=Graph.XlLegendPosition.xlLegendPositionBottom;
objChart.HasTitle = true;
objChart.ChartTitle.Text = "Here it is..."; //Build Slide #3:
//Change the background color of this slide only. Add a text effect to the slide
//and apply various color schemes and shadows to the text effect.
objSlide = objSlides.Add(3, PowerPoint.PpSlideLayout.ppLayoutBlank);
objSlide.FollowMasterBackground = MsoTriState.msoFalse;
objShapes = objSlide.Shapes;
objShape = objShapes.AddTextEffect(MsoPresetTextEffect.msoTextEffect27,
"谢谢观赏!", "Impact", 96, MsoTriState.msoFalse, MsoTriState.msoFalse, 230, 200); //Modify the slide show transition settings for all 3 slides in
//the presentation.
int[] SlideIdx = new int[3];
for(int i=0;i<3;i++) SlideIdx[i]=i+1;
objSldRng = objSlides.Range(SlideIdx);
objSST = objSldRng.SlideShowTransition;
objSST.AdvanceOnTime = MsoTriState.msoTrue;
objSST.AdvanceTime = 3;
objSST.EntryEffect = PowerPoint.PpEntryEffect.ppEffectBoxOut; //Prevent Office Assistant from displaying alert messages:
bAssistantOn = objApp.Assistant.On;
objApp.Assistant.On = false; //Run the Slide show from slides 1 thru 3.
objSSS = objPres.SlideShowSettings;
objSSS.StartingSlide = 1;
objSSS.EndingSlide = 3;
objSSS.Run(); //Wait for the slide show to end.
objSSWs = objApp.SlideShowWindows;
while(objSSWs.Count>=1) System.Threading.Thread.Sleep(100); //Reenable Office Assisant, if it was on:
if(bAssistantOn)
{
objApp.Assistant.On = true;
objApp.Assistant.Visible = false;
} //Close the presentation without saving changes and quit PowerPoint.
objPres.Close();
objApp.Quit();
}
}
}
Try!!!!!!!!!!! :)希望对你有所帮助