asp.net - Generate Powerpoint file on the fly

2019-04-05 12:57发布

问题:

I have a client of my web based application who heavily uses the data from our system for powerpoint presentations.

We currently allow data to export in more traditional file types...PDF, CSV, HTML, and a few others. Powerpoint doesn't seem to be really automated.

Is there a way, on the ASP.NET server side, to automate the creation and on-demand download of a powerpoint file format for a report from a system?

回答1:

In this article, Steve suggests using Aspose's Slide application.

He also explains step by step on how to generate the PowerPoint file.

Here are some code excerpts (in VB):

Opening an existing PowerPoint file:

 Dim fs As  System.IO.FileStream = _

   New System.IO.FileStream("c:\mypath\myfile.ppt", _

   System.IO.FileMode.Open, System.IO.FileAccess.Read)

Dim MyPres As Presentation = New Presentation(fs)

fs.Close() 

Looping the slides and outputting their template formats:

Dim slides  As Slides = MyPres.Slides

For i As Integer = 0 To slides.Count - 1

   Response.Write(MyPres.Slides(i).Layout.ToString + "<br>")

Next

In his article, he describes more in detail on how to do it.



回答2:

There's some documentation on MSDN about the OpenXML format that they're using:

  • Manipulating Excel 2007 and PowerPoint 2007 Files with the Open XML Format API (Part 1 of 2)
  • Manipulating Excel 2007 and PowerPoint 2007 Files with the Open XML Format API (Part 2 of 2)


回答3:

Well you have two ways of really doing this, without third party tools. The first would be with Automation of PowerPoint, but that requires that your server have PowerPoint installed. The second is to utilize the new pptx file file format and generate the powerpoint document using XML.

I have found that the best way to get started on the XML side is to simply create a powerpoint that does what you want, then save it and look at the XML. You can also review the microsoft documentation. Overall working with the XML formats is pretty easy.

Lastly, there might be some third party items out there, but be careful that they don't require COM automation.



回答4:

In regards to the previous poster, your statement is incorrect.

You really only have one option for server side ASP.NET automation of this process. Use the open xml links mentioned by Ben in the original answer...

Manipulating Excel 2007 and PowerPoint 2007 Files with the Open XML Format API (Part 1 of 2) Manipulating Excel 2007 and PowerPoint 2007 Files with the Open XML Format API (Part 2 of 2)

The reason for this is that server side automation of office is completely unsupported and is bad coding practise, running com automation servers that are designed for interactive usage in a non-interactive environment is a potential recipe for disaster.

so in summary use the open xml api and generate your pptx's.



回答5:

There are also other third-party options similar to Aspose Slides, such as OfficeWriter's PowerPoint Writer.

I'm not exactly sure how Aspose Slides works, but with PowerPoint Writer you have an existing, formatted PowerPoint presentation with data markers in it, the you process it with PowerPoint Writer to replace the data markers with data. Here are some examples.



回答6:

there is another method ,convert your power point presentation to images or xps(silver light presentation) and then use some sort of json(jquery) to show and download them.

i implement the images and xps silver light presentation in my web application