Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

PowerPoint 문서를 제어해 보신 분... 조언좀. 부탁드립니다.

154 views
Skip to first unread message

정성태

unread,
Jan 5, 2004, 3:30:26 AM1/5/04
to
PPT 문서를 호스트하고 있는 것은 웹브라우저일수도 있고, MFC 일수도 있을
것입니다.

제 경우에는 웹브라우저에서 제어하려고 하는데요.
웹브라우저에서,Navigate 메서드를 통해서 해당 PPT 파일을 열었습니다.
OLEDocument 로 작동이 되는 거죠.

DocumentComplete 이벤트에서

PowerPoint.Presentation show = (PowerPoint.Presentation)_axBr.Document;
// C# 코드
show.SlideShowWindow.View.Exit();

위와 같이 해서 Document 를 Presentation 으로 변환시켰습니다.

---------------------------------------------------------

이제 어떤 제어를 할 수 있는지는 Powerpoint.exe 를 실행시켜서 VBA 매크로를
이용하면 코드를 얻어낼 수 있습니다.

일례로, 선택한 부분의 Font 크기를 바꾸는 것을 해보니,


ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(Start:=1,
Length:=4).Select
ActiveWindow.Selection.TextRange.Font.Size = 40
ActiveWindow.Selection.SlideRange.Shapes("Litebulb").Select

VBA 매크로에는 위와 같이 기록되어져 있더군요.

--------------------------------------------------------

다시 돌아가서 ... 얻었던 PowerPoint.Presentation show 변수를 이용해서,
ActiveWindow 에 접근하려고 했습니다.

object objWindow = show.Application.ActiveWindow // C# 코드

로 구할 수 있더군요. 그런데... ^^; objWindow 에는 null 이 들어가 있습니다.

이리저리 구해봐도, 위의 VBA 매크로를 C# 으로 구현할수가 없더군요.

PowerPoint 가 제어가 안될리가 없을 텐데. 혹시, MFC 나 WebBrowser 에서
호스팅해서 구현해 보신분 계시나요?


///////// 아래는 C# 으로 된 전체 소스입니다. ///////////////////


using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;

namespace WindowsApplication
{
/// <summary>
/// Form1에 대한 요약 설명입니다.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private AxSHDocVw.AxWebBrowser _axBr;
/// <summary>
/// 필수 디자이너 변수입니다.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
InitializeComponent();
}

/// <summary>
/// 사용 중인 모든 리소스를 정리합니다.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form 디자이너에서 생성한 코드
/// <summary>
/// 디자이너 지원에 필요한 메서드입니다.
/// 이 메서드의 내용을 코드 편집기로 수정하지 마십시오.
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new
System.Resources.ResourceManager(typeof(Form1));
this.button1 = new System.Windows.Forms.Button();
this._axBr = new AxSHDocVw.AxWebBrowser();
((System.ComponentModel.ISupportInitialize)(this._axBr)).BeginInit();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(480, 0);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// _axBr
//
this._axBr.Enabled = true;
this._axBr.Location = new System.Drawing.Point(0, 8);
this._axBr.OcxState =
((System.Windows.Forms.AxHost.State)(resources.GetObject("_axBr.OcxState")))
;
this._axBr.Size = new System.Drawing.Size(464, 392);
this._axBr.TabIndex = 2;
this._axBr.DocumentComplete += new
AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEventHandler(this._axBr_Documen
tComplete);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.AutoScroll = true;
this.ClientSize = new System.Drawing.Size(616, 490);
this.Controls.Add(this._axBr);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this._axBr)).EndInit();
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// 해당 응용 프로그램의 주 진입점입니다.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void Form1_Load(object sender, System.EventArgs e)
{
object flags = null;
object targetFrameName = null;
object postData = null;
object headers = null;

_axBr.Navigate( "C:\\Documents and
Settings\\Administrator\\Desktop\\test.ppt", ref flags, ref targetFrameName,
ref postData, ref headers );
}

private void button1_Click(object sender, System.EventArgs e)
{
// powerpoint
PowerPoint.Presentation show = (PowerPoint.Presentation)_axBr.Document;

///////////// 아래에서 null 이 반환됨. ///////////////
object obj = show.Application.ActiveWindow;
}

private void _axBr_DocumentComplete(object sender,
AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
{
PowerPoint.Presentation show = (PowerPoint.Presentation)_axBr.Document;
show.SlideShowWindow.View.Exit();
}

}
}


0 new messages