将PowerPoint转换为视频 [英] Convert PowerPoint to Video

查看:375
本文介绍了将PowerPoint转换为视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

if (path != "")
{
    bool validName = false;
    string nFile = "newFile";

    PowerPoint._Presentation objPres;

    objApp = new PowerPoint.Application();
    objApp.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
    objApp.WindowState = Microsoft.Office.Interop.PowerPoint.PpWindowState.ppWindowMinimized;

    objPres = objApp.Presentations.Open(txtSearch.Text, MsoTriState.msoTrue, MsoTriState.msoTrue, MsoTriState.msoTrue);
    Console.WriteLine("File name: " + txtSearch.Text);
    try
    {
    
        txtStat.Text = "Starting Conversion";
        
        if (!nFile.Contains(".wmv")) nFile += ".wmv";


                objPres.SaveAs(path + "\\" + nFile, PowerPoint.PpSaveAsFileType.ppSaveAsWMV, MsoTriState.msoTrue);


        txtStat.Text = "Done";
        objPres.Close();
        objApp.Quit();
        
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex);
    }
}
else
{
    MessageBox.Show("Please select a file PowerPoint file to convert");
}





以上是我用来尝试将PowerPoint转换为视频。我正在使用Microsoft.Office.Interop.PowerPoint来执行此操作。我的问题是它转换了第一张幻灯片,但之后它显示了非常奇怪的绿色条纹和奇怪的颜色。



非常感谢任何帮助!



Above is my I am using to try and convert a PowerPoint into a video. I am using Microsoft.Office.Interop.PowerPoint in order to do this. My issue is that it converts the first slide but after that it displays really strange looking green bars and weird colors.

Any help with this will be greatly appreciated!

推荐答案

你需要等待视频到完成。在视频完成之前,您的代码将退出PowerPoint。下面是一个有效的例子。



注释

*我更改了你的变量路径 strPath 以便我可以使用 Path.Combine

*我将 PowerPoint._Presentation 更改为 PowerPoint.Presentation



额外

还有其他值 PpMediaTaskStatus 你应该检查在之后循环。请参阅 PpMediaTaskStatus枚举 [< a href =http://msdn.microsoft.com/en-us/library/microsoft.office.interop.powerpoint.ppmediataskstatus(v=office.14).aspx\"target =_ blanktitle =New Window > ^ ]。



You need to wait for the video to be completed. Your code exits PowerPoint before the video has been completed. Below is an example that works.

Notes
* I changed your variable path to strPath so that I could use Path.Combine.
* I changed PowerPoint._Presentation to PowerPoint.Presentation.

Additional
There are other values of PpMediaTaskStatus that you should check after the while loop. See PpMediaTaskStatus Enumeration[^].

if (!string.IsNullOrEmpty(strPath)) {
	bool validName = false;
	string nFile = "newFile";
	PowerPoint.Application objApp;
	PowerPoint.Presentation objPres;
	objApp = new PowerPoint.Application();
	objApp.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
	objApp.WindowState = PowerPoint.PpWindowState.ppWindowMinimized;
	objPres = objApp.Presentations.Open(txtSearch.Text, MsoTriState.msoTrue, MsoTriState.msoTrue, MsoTriState.msoTrue);
	Console.WriteLine("File name: " + txtSearch.Text);
	try {
		txtStat.Text = "Starting Conversion";
		if (!nFile.Contains(".wmv")) {
			nFile += ".wmv";
		}
		objPres.SaveAs(System.IO.Path.Combine(strPath, nFile), PowerPoint.PpSaveAsFileType.ppSaveAsWMV, MsoTriState.msoTrue);
		// Wait for creation of video file
		while (objApp.ActivePresentation.CreateVideoStatus == PowerPoint.PpMediaTaskStatus.ppMediaTaskStatusInProgress || objApp.ActivePresentation.CreateVideoStatus == PowerPoint.PpMediaTaskStatus.ppMediaTaskStatusQueued) {
			Application.DoEvents();
			System.Threading.Thread.Sleep(500);
		}

		txtStat.Text = "Done";
		objPres.Close();
		objApp.Quit();
                // Release COM Objects
		System.Runtime.InteropServices.Marshal.FinalReleaseComObject(objPres);
		objPres = null;
		System.Runtime.InteropServices.Marshal.FinalReleaseComObject(objApp);
		objApp = null;
		GC.Collect();
		GC.WaitForPendingFinalizers();

	} catch (Exception ex) {
		Console.WriteLine(ex);
	}
} else {
	MessageBox.Show("Please select a file PowerPoint file to convert");
}


这篇关于将PowerPoint转换为视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆