转换Excel工作簿为byte [] [英] Convert excel workbook to byte[]

查看:930
本文介绍了转换Excel工作簿为byte []的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个创先争优库工作簿,并希望将其转换为一个byte [],所以我可以用的文件方法存在于asp.net的MVC控制器。结果
有保存和SaveToStream的方法,但没有转换为byte []。

I have an "excel library" workbook and want to convert it to a byte[] so I could return the data with the File method exist in asp.net mvc controller.
There are "Save" and "SaveToStream" method, but no convert to byte[].

我怎样才能返回Excel文件没有之前的服务器保存?

How can I return the excel file without saving it in server before?

推荐答案

如果你有一个SaveToStream你可以传递一个的的MemoryStream 到该方法。然后,一旦所有的字节写入调用 ToArray的()在的内存流,这应该给你一个字节数组。

If you have a SaveToStream you could pass in a MemoryStream into that method. Then, once all the bytes are written call ToArray() on the memory stream, which should give you a byte array.

这篇关于转换Excel工作簿为byte []的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆