从内存流中发送excel文件 [英] Email excel file from memory stream

查看:147
本文介绍了从内存流中发送excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

有没有办法将数据写入内存流中的Excel文件并通过电子邮件发送,而无需将其保存在vb.net中?这是场景:我正在研究一个从SQL服务器检索数据集的vb.net控制台应用程序。要求是我必须以Excel格式通过电子邮件发送此数据集而不在光盘上创建文件。有没有办法做到这一点?



先谢谢你的帮助....

汤姆

Hi All,
Is there a way to write data to an Excel file in the memory stream and email it without saving it in vb.net? Here''s the scenario: I am working on a vb.net console app that retrieves a dataset from SQL server. The requirement is that I have to email this dataset in Excel format without creating a file on the disc. Is there a way to do this?

Thanks in advance for your help....
Tom

推荐答案

您应该能够将任何文件呈现为字节数组。当我在浏览器中将RDLC渲染为PDF或Excel文件时,我会一直这样做。我将它们渲染为一个字节数组,然后将其写入响应流。在你的情况下,你只需将字节数组添加到Attachment对象。





VB

You should be able to render any file as a byte array. I do this all the time when I render RDLCs as PDF or Excel files in the browser. I render them to a byte array then write this to the response stream. In your case you would just add the byte array into an Attachment object.


VB
Dim att As New Attachment(New MemoryStream(bytes), name)





C#



C#

Attachment att = new Attachment(new MemoryStream(bytes), name);


这篇关于从内存流中发送excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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