C# 将字节[]转换为excel文件(xlsx)

C# 将字节[]转换为excel文件(xlsx),c#,arrays,xlsx,C#,Arrays,Xlsx,我需要使用C#将字节数组转换为excel文件,以便将其上载到Sharepoint中 以下代码以字节数组的形式从客户端读取输入文件: public object UploadFile(HttpPostedFile file) { byte[] fileData = null; using (var binaryReader = new BinaryReader(file.InputStream)) { fileData = binaryReader.Read

我需要使用C#将字节数组转换为excel文件,以便将其上载到Sharepoint中

以下代码以字节数组的形式从客户端读取输入文件:

public object UploadFile(HttpPostedFile file)
{
    byte[] fileData = null;
    using (var binaryReader = new BinaryReader(file.InputStream))
    {
        fileData = binaryReader.ReadBytes(imageFile.ContentLength);

        // convert fileData to excel              
    }
}

我怎么做

听起来您只是在查找
File.writealBytes(路径、内容)
。但是,如果输入文件可能很大,则最好使用
API:

using(var destination = File.Create(path)) {
    file.InputStream.CopyTo(destination);
}
编辑:看起来
HttpPostedFile
有一个
SaveAs
方法,所以只需:

file.SaveAs(path);

你说的皈依是什么意思?xlsx文件是一组字节。您想将其写入磁盘吗?@nvoigt是的,我想将其写入/保存到临时路径我想将byte[]转换为可读格式,因为我必须将其上载到sharepoint,我想我无法按原样传递文件。
BinaryReader
在这里没有位置。
BinaryReader
的主要用途是当您将其用作
BinaryWriter
的孪生兄弟来拼凑一些粗略的序列化。@Dan
byte[]
是一种可读格式。。。