一个关于office组件的问题。弓虽人请入。 .net中應有一個組件的,你可以通過引用組件找到該.DLL文件,具體的自已去找一下。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在解决方案管理器里:右击引用,选添加引用,在弹出的对话框里选COM标签页,选择Microsof Excel 9.0,确定。你就可以使用excel了。工具箱不需要添加任何东东,倒是要在引用里要添加上你的excel的引用Project--> Add Reference--> COM --> Microsoft Excel 9.0 object Lib... using System;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(); } }} 楼主可以仔细看看上面的代码..我以前练习过的一个东东,调用PowerPoint自动加入Session等等.把上面的图片路径换成你自己的吧..Try!!!!!!!!!!! :)希望对你有所帮助 C# TCP 发送与接收 遇到难题了!请高手解答 c#委托与事件 委托代替事件 为什么还要存在事件这个概念? 菜鸟提问,请教算法:求(1+X)的8次方=1.3 如何将图片的路径存入数据库,然后在PICTUREBOX上显示出来 很值得大家探讨的问题!也是开发常会遇到的问题! 图片下载及用正则替换的问题 如何在B\S结构中实现文件下载的功能..?? 如何将system.windows.forms.datagrid中的checkbox设置为灰色。 一个初级问题,多谢!! 在层级列表中如何查找并删除指定对象 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!!!!!!!!!!! :)希望对你有所帮助