且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何以编程打开并保存在C#或Perl PowerPoint演示文稿作为HTML / JPEG?

更新时间:2023-02-15 08:11:32

下面将打开 C:\presentation1.ppt 和幻灯片保存为 C:\Presentation1\slide1.jpg

The following will open C:\presentation1.ppt and save the slides as C:\Presentation1\slide1.jpg etc.

如果你需要得到互操作程序集,它。正在工具可在Office安装程序,也可以从的这里(Office 2003)中。你应该能够找到其他的版本从那里,如果你有一处较新版本的链接。

If you need to get the interop assembly, it is available under 'Tools' in the Office install program, or you can download it from here (office 2003). You should be able to find the links for other versions from there if you have a newer version of office.

using Microsoft.Office.Core;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;

namespace PPInterop
{
  class Program
  {
	static void Main(string[] args)
	{
		var app = new PowerPoint.Application();

		var pres = app.Presentations;

		var file = pres.Open(@"C:\Presentation1.ppt", MsoTriState.msoTrue, MsoTriState.msoTrue, MsoTriState.msoFalse);

		file.SaveCopyAs(@"C:\presentation1.jpg", Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsJPG, MsoTriState.msoTrue);
	}
  }
}

修改
思南的版本使用导出看起来是一个好一点的选择,因为你可以指定一个输出分辨率。对于C#,更改上面的最后一行:

Sinan's version using export looks to be a bit better option since you can specify an output resolution. For C#, change the last line above to:

file.Export(@"C:\presentation1.jpg", "JPG", 1024, 768);