0

我正在使用库 MPXJ效果很好,但我现在希望用户能够上传他们自己的文件(asp.net-mvc 站点),它作为 HttpPostedFileBase 在服务器端表单发布,然后我转换为内存流使用:

    var stream = new MemoryStream();
    httpPostedFile.InputStream.CopyTo(stream);

鉴于此,我试图弄清楚如何将它作为 MemoryStream 读取(相对于磁盘上的文件位置)

现在我有这样的事情:

    public ProjectFile Import(string filePathandName)
    {
        MPPReader reader = new MPPReader();
        ProjectFile project = reader.read(filePathandName);

我想要这样的东西:

    public ProjectFile Import(MemoryStream stream)
    {
        MPPReader reader = new MPPReader();
        ProjectFile project = reader.read(stream);

这可能是“本机”还是我需要将文件保存在我的服务器上然后从那里读入(试图避免该选项)?

4

2 回答 2

1

MPPReader.Read()方法只接受 4 种类型的参数,其中没有一种是 aMemoryStream并且除了一种似乎是在库本身中定义的类型:

  • java.io.文件
  • java.io.InputStream
  • org.apache.poi.poifs.filesystem.POIFSFileSystem
  • 细绳

您当前正在使用该string参数,因为它需要一个路径,但是您可能得到的最接近的方法似乎是尝试将现有MemoryStream对象复制到InputStream库中找到的类型并使用该类型(如果存在该类型的支持)。

于 2016-04-14T13:06:01.937 回答
1

MPXJ 附带一对称为的类DotNetInputStreamDotNetOutputStream它们充当 .Net 流的包装器,因此它们可以在 MPXJ 期望 JavaInputStreamOutputStream.

以下是来自的相关评论DotNetInputStream

/// <summary>
/// Implements a wrapper around a .Net stream allowing it to be used with MPXJ
/// where a Java InputStream is expected.
/// This code is based on DotNetInputStream.java from the Saxon project http://www.sf.net/projects/saxon
/// Note that I've provided this class as a convenience so there are a matching pair of
/// input/output stream wrapper shopped with MPXJ. IKVM also ships with an input stream wrapper:
/// ikvm.io.InputStreamWrapper, which you could use instead of this one.
/// </summary>

您应该能够使用此类来实现您在问题中描述的内容。

于 2016-04-15T09:53:20.730 回答