Officeオートメーションを使用せずにPowerPointプレゼンテーションを生成するためのテクニックにはどのようなものがありますか?
-
05-07-2019 - |
質問
Officeオートメーションを使用してPowerPointプレゼンテーションを自動的に生成することは可能ですが、これはサーバーでの使用は推奨されません。 Officeオートメーションを使用せずにPowerPointプレゼンテーションを生成するにはどうすればよいですか?
解決
言及されなかった別のオプションは、私たちが最終的に取ったルートで、
最初に、置き換えが必要なコンテンツの代わりにトークンを配置した汎用テンプレートファイルを準備しました。次に、DocumentFormat.OpenXmlへの参照をプロジェクトに追加する必要があります。コード自体は、DocumentFormat.OpenXmlおよびDocumentFormat.OpenXml.Packaging名前空間を参照します。最後に、スライドをループするコードは次のようになります。
// Open the presentation
PresentationDocument presentation = PresentationDocument.Open(fileName, true);
// Loop through all of the slides in the presentation
foreach (SlidePart slide in presentation.PresentationPart.SlideParts)
{
// Read the XML out of the slide
XmlDocument xml = new XmlDocument();
xml.Load(slide.GetStream());
// TODO: Your XML manipulation code here
// Save the updated slide
xml.Save(slide.GetStream());
}
// Save the updated presentation
presentation.Close();
他のヒント
PowerPoint形式のドキュメントを生成できるライブラリを使用するサーバー側コードを作成できます。たとえば、Javaでは、 Apache POI-HSLF を使用して、プログラムでPPTファイルを生成できます。
何をする必要があるかによっては、「テンプレート」PPTファイルで開始し、プログラムで変更してコンテンツを挿入または編集する方が簡単な場合があります。
サーバー側のテクノロジーがASP.NETの場合、 Aspose.Slides 。それは非常に強力でうまく機能しますが、何をしたいかによっては費用対効果の高いソリューションではないかもしれません。