Сохраните байтовый массив для Excel FileC#

Место общения программистов C#
Ответить
Anonymous
 Сохраните байтовый массив для Excel File

Сообщение Anonymous »

Я получаю байтовый массив от отчета SSRS. Затем я хочу сохранить его в Excel на сервере для дальнейшей обработки.
Я могу экспортировать его в браузере клиента, но при попытке сохранить файл на сервере, который он сохраняет. Но дает ошибку во время открытия «Excel не может открыть файл, потому что формат файла или расширение файла недопустимо».Microsoft.Reporting.WebForms.ReportViewer rview = new Microsoft.Reporting.WebForms.ReportViewer();
//Web Address of your report server (ex: http://rserver/reportserver)

rview.ServerReport.ReportServerUrl = new Uri("http://rserver/reportserver");

rview.ServerReport.ReportPath = "/Report Project2/Comment";

string mimeType, encoding, extension, deviceInfo;
string[] streamids;
Microsoft.Reporting.WebForms.Warning[] warnings;
string format = "Excel"; //Desired format goes here (PDF, Excel, or Image)

deviceInfo = "" + "True" + "";
byte[] bytes = rview.ServerReport.Render(format, deviceInfo, out mimeType, out encoding, out extension, out streamids, out warnings);

try
{
System.IO.FileStream _FileStream = new System.IO.FileStream(Server.MapPath("output.xlsx"), System.IO.FileMode.Create, System.IO.FileAccess.Write);
_FileStream.Write(bytes, 0, bytes.Length);
//_FileStream.Close();
}
catch (Exception _Exception)
{
Console.WriteLine("Exception caught in process: {0}", _Exception.ToString());
}
< /code>
Не знает, как использовать формат Infor, Deviceinfo и т. Д., Который я использую с объектом Spose для сохранения Excel в браузере клиента.Response.Clear();

if (format == "PDF")
{
Response.ContentType = "application/pdf";
Response.AddHeader("Content-disposition", "filename=output.pdf");
}
else if (format == "Excel")
{
Response.ContentType = "application/excel";
Response.AddHeader("Content-disposition", "filename=output.xls");
}
Response.OutputStream.Write(bytes, 0, bytes.Length);
Response.OutputStream.Flush();
Response.OutputStream.Close();
Response.Flush();
Response.Close();


Подробнее здесь: https://stackoverflow.com/questions/193 ... excel-file
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»