项目需求:
1.服务器控制屏幕播放ppt等文档
2.通过传参的形式来修改播放文件,一共5个屏幕
方案1:
通过网页传参实现播放ppt,结果发现虽然实现了播放但是实际是是本地播放ppt,代码如下
public partial class mingdao : System.Web.UI.Page
{
static bool closeflag = false;
protected void Page_Load(object sender, EventArgs e)
{
string pptFileName = null;
OperatePPT op = new OperatePPT();
//op.PPTOpen(@"D:\QQPCmgr\Desktop\ppt\a.ppx");
pptFileName = Request.QueryString["name"];
/*Begin: Adde by PN:错误提示*/
//if (!op.PPTAuto(@"D:\QQPCmgr\Desktop\ppt\" + pptFileName, 3))
//{
// //if(openflag)
// //{
// // openflag = false;
// //}
// //else
// //{
// // Response.Write(string.Format("<script>alert('没有找到{0}')</script>", pptFileName));
// //}
// if (openflag)
// {
// Response.Write(string.Format("<script>alert('没有找到{0}')</script>", pptFileName));
// }
// openflag = true;
//}
/*End: Adde by PN:错误提示*/
op.PPTAuto(@"c:\ppt\" + pptFileName, 3);
Response.Write(string.Format("<script>alert('没有找到{0}')</script>", pptFileName));
}
}
namespace PPTDraw.PPTOperate
{
/// <summary>
/// PPT文档操作实现类.
/// </summary>
public class OperatePPT
{
#region=========基本的参数信息=======
POWERPOINT.Application objApp = null;
POWERPOINT.Presentation objPresSet = null;
POWERPOINT.SlideShowWindows objSSWs;
POWERPOINT.SlideShowTransition objSST;
POWERPOINT.SlideShowSettings objSSS;
POWERPOINT.SlideRange objSldRng;
bool bAssistantOn;
double pixperPoint = 0;
double offsetx = 0;
double offsety = 0;
#endregion
#region===========操作方法==============
/// <summary>
/// 打开PPT文档并播放显示。
/// </summary>
/// <param name="filePath">PPT文件路径</param>
public void PPTOpen(string filePath)
{
//防止连续打开多个PPT程序.
if (this.objApp != null) { return; }
try
{
objApp = new POWERPOINT.Application();
//以非只读方式打开,方便操作结束后保存.
objPresSet = objApp.Presentations.Open(filePath, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse);
//Prevent Office Assistant from displaying alert messages:
bAssistantOn = objApp.Assistant.On;
objApp.Assistant.On = false;
objSSS = this.objPresSet.SlideShowSettings;
objSSS.Run();
}
catch (Exception ex)
{
this.objApp.Quit();
}
}
/// <summary>
/// 自动播放PPT文档.
/// </summary>
/// <param name="filePath">PPTy文件路径.</param>
/// <param name="playTime">翻页的时间间隔.【以秒为单位】</param>
public bool PPTAuto(string filePath, int playTime)
{
try
{
int c = 0;
//防止连续打开多个PPT程序.
if (this.objApp != null) { return true; }
objApp = new POWERPOINT.Application();
objPresSet = objApp.Presentations.Open(filePath, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse);
// 自动播放的代码(开始)
int Slides = objPresSet.Slides.Count;
int[] SlideIdx = new int[Slides];
for (int i = 0; i < Slides; i++) { SlideIdx[i] = i + 1; };
objSldRng = objPresSet.Slides.Range(SlideIdx);
objSST = objSldRng.SlideShowTransition;
//设置翻页的时间.
objSST.AdvanceOnTime = Microsoft.Office.Core.MsoTriState.msoCTrue;
objSST.AdvanceTime = playTime;
//翻页时的特效!
objSST.EntryEffect = POWERPOINT.PpEntryEffect.ppEffectCircleOut;
//Prevent Office Assistant from displaying alert messages:
//bAssistantOn = objApp.Assistant.On;
//objApp.Assistant.On = true;
//Run the Slide show from slides 1 thru 3.
objSSS = objPresSet.SlideShowSettings;
objSSS.StartingSlide = 1;
objSSS.EndingSlide = Slides;
objSSS.Run();
//Wait for the slide show to end.
objSSWs = objApp.SlideShowWindows;
/*Begin:Update by 2017/9/4 PN:ppt播放修改*/
while (objSSWs.Count >= 1) System.Threading.Thread.Sleep(playTime * 10);
//for (c = 0; c < objSSWs.Count; c++)
//{
// int j = 0;
// for (j = 0; j < Slides; j++)
// System.Threading.Thread.Sleep(playTime * 10000);
//}
/*End:Update by 2017/9/4 PN:ppt播放修改*/
//System.Threading.Thread.Sleep((playTime+1) * (Slides+1) * 1000);
if(filePath.Contains("close"))
{
objPresSet.Close();
objApp.Quit();
}else
{
objPresSet.Close();
objApp.Quit();
}
return true;
}
catch
{
return false;
}
}
/// <summary>
/// PPT下一页。
/// </summary>
public void NextSlide()
{
if (this.objApp != null)
this.objPresSet.SlideShowWindow.View.Next();
}
/// <summary>
/// PPT上一页。
/// </summary>
public void PreviousSlide()
{
if (this.objApp != null)
this.objPresSet.SlideShowWindow.View.Previous();
}
/// <summary>
/// 关闭PPT文档。
/// </summary>
public void PPTClose()
{
//装备PPT程序。
//if (this.objPresSet != null)
//{
// 判断是否退出程序,可以不使用。
// objSSWs = objApp.SlideShowWindows;
// if (objSSWs.Count >= 1)
// {
// this.objPresSet.Save();
// }
// this.objPresSet.Close();
//}
//if(this.objPresSet != null)
if (this.objApp != null)
this.objApp.Quit();
GC.Collect();
}
#endregion
}
}
显然这个方案不能满足我的需求功能
方案2:
通过将ppt等文档全部转换成swf 格式文件,然后 服务器端架网站,客户端就可以通过网页播放 下载demo链接:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<object width="400" height="320">
<param name="movie" value="播放器URL" />
<param name="quality" value="high" />
<embed src="<%=swf%>" type="application/x-shockwave-flash" width="1080" height="1920"/>
</object>
</div>
</form>
</body>
</html>
public partial class _Default : System.Web.UI.Page
{
public string swf;
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
string swfName = Request.QueryString["name"];
swf = "swf/" + swfName;
}
}
}