私は最近、PowerPoint ファイルを XpsDocument として WPF に埋め込んでみました。
これは、DocumentViewer プロパティを MainWindow.xaml グリッドに埋め込む単純な WPF アプリケーションです。
<Window x:Class="PowerPoint2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:PowerPoint2"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<DocumentViewer
Name="DocumentviewPowerPoint"
VerticalAlignment="Top"
HorizontalAlignment="Left" />
</Grid>
「DocumentviewPowerPoint」にバインドされたドキュメントを作成するには、開いた PowerPoint ファイルを Xps 形式に変換し、この変数を前述の XAML プロパティにバインドします。
using System;
using System.IO;
using System.Windows;
using System.Windows.Xps.Packaging;
using Microsoft.Office.Core;
using Microsoft.Office.Interop.PowerPoint;
using Application = Microsoft.Office.Interop.PowerPoint.Application;
namespace PowerPoint2
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
const string powerPointFile = @"c:\temp\ppt.pptx";
var xpsFile = Path.GetTempPath() + Guid.NewGuid() + ".pptx";
var xpsDocument = ConvertPowerPointToXps(powerPointFile, xpsFile);
DocumentviewPowerPoint.Document = xpsDocument.GetFixedDocumentSequence();
}
private static XpsDocument ConvertPowerPointToXps(string pptFilename, string xpsFilename)
{
var pptApp = new Application();
var presentation = pptApp.Presentations.Open(pptFilename, MsoTriState.msoTrue, MsoTriState.msoFalse,
MsoTriState.msoFalse);
try
{
presentation.ExportAsFixedFormat(xpsFilename, PpFixedFormatType.ppFixedFormatTypeXPS);
}
catch (Exception ex)
{
MessageBox.Show("Failed to export to XPS format: " + ex);
}
finally
{
presentation.Close();
pptApp.Quit();
}
return new XpsDocument(xpsFilename, FileAccess.Read);
}
}
}
プログラムを実行すると、これはすべてうまく機能し、WPF に埋め込まれた Xps ドキュメントが表示されます。
私の質問は、PowerPoint を一連のスクロール可能なスライドとして表示するだけでなく、実際のスライド ショーとして表示するためにコードをさらに変更するにはどうすればよいですか? 「適切な」プレゼンテーションのように、ユーザーがマウスをクリックするたびに次のスライドに移動できるように、さらに更新したいと思います。私の問題は、XpsDocument Api の使用法に慣れていないことです。これらを使用して目的を達成する場合なのか、Xps 形式に変換されるプレゼンテーション変数の設定プロパティにあるのかわかりません。 .