1

我正在使用 作为参考生成一个 PowerPoint 文件。一个用户可以根据许多标准搜索其他用户。基于用户的信息保存在 PowerPoint 文件中。但我无法在服务器上保存所有 PowerPoint 文件。

因此,用户需要右键单击一个链接,选择“另存为...”,然后将文件保存在本地。

服务器上不应保存任何内容。我一直在谷歌搜索,但我不确定要寻找什么。你能指出一个好的教程吗?

我似乎是一个糟糕的谷歌用户。我从搜索字符串中删除了“powerpoint”,点击率很高。但是,任何评论都值得赞赏。

4

1 回答 1

2

You should get file as a stream, open it using open xml sdk (You need to have Open XML SDK: here).

If you are not familiar with Open XML SDK, you can also look at the blog post here which is also taken from the blog you already referenced.

Below code is a sample code how I create report and send to client using Open XML SDK with ASP.NET. I hope it can be helpful.

public void SendReport()
{
    using (Stream stream = GetReportStream())
    {
        stream.Position = 0;
        byte[] buffer = new byte[(int)stream.Length];
        stream.Read(buffer, 0, (int)stream.Length);
        System.Web.HttpContext.Current.Response.Clear();
        System.Web.HttpContext.Current.Response.Buffer = true;
        System.Web.HttpContext.Current.Response.AddHeader("Content-Type", "application/pptx");
        System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=Report;");

        System.Web.HttpContext.Current.Response.BinaryWrite(buffer);
        System.Web.HttpContext.Current.Response.Flush();
        System.Web.HttpContext.Current.Response.Close();
    }
}

private Stream GetReportStream()
{
    MemoryStream stream = new MemoryStream();
    using (FileStream file = File.Open(@"TemplateFileLocation", FileMode.Open))
    {
        byte[] buffer = new byte[file.Length];
        file.Read(buffer, 0, (int)file.Length);
        stream.Write(buffer, 0, buffer.Length);
    }
    using (PresentationDocument presentationDocument = PresentationDocument.Open(stream, true))
    {
        // Doing manipulations explained in your reference document link.

        presentationDocument.PresentationPart.Presentation.Save();
    }
    return stream;
}

Don't forget to download and check the whole solution on the link you referenced.

于 2010-09-22T12:14:23.280 回答