edfreels
asked on
.rdlc report conversion to excel
I have a report I built using C#; the report generates the data fine. The export option on the reports toolbar has Excel or PDF. I can manually select Excel and it will save my document accordingly.
My question is, is there a way to programmatically either, export the data as an excel document, or save the report, then convert it to an xls?
I know this is lame, but the only code I have so far for this is:
Form1 F = new Form1();
//
F.Show();
//
** this where I want to try and save the result, and export it as an Excel doc.
Thanks ahead of time experts.
My question is, is there a way to programmatically either, export the data as an excel document, or save the report, then convert it to an xls?
I know this is lame, but the only code I have so far for this is:
Form1 F = new Form1();
//
F.Show();
//
** this where I want to try and save the result, and export it as an Excel doc.
Thanks ahead of time experts.
ASKER
I am not trying to take an existing spread sheet and format it with this tool. I have a report already written, I simply want to automate the results to Excel where a macro will run against it. This example will not suffice in that I am not adding someone elses .dll to my code or network. I need to see some code that will allow me to re-create the process. I did check the site, but there are no examples of taking an .rdlc and converting it to an Excel format that I had seen. It is part of the 'Export' function on the toolbar of the report, so I know it is do-able. I just don't see how the example from the link listed will do it.
Thank you for the response though MogulManic.
Thank you for the response though MogulManic.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I had to make some adjustments for my environment, but it worked nonetheless. This was my modified solution for Excel.
private void exportToExcel(string fileFolder)
{
System.IO.FileInfo fi = new System.IO.FileInfo(fileFol der);
//
if (fi.Exists)
fi.Delete();
Warning[] warnings;
string[] streamids;
string mimeType, encoding, filenameExtension;
byte[] bytes = reportViewer1.LocalReport. Render("Ex cel",null, out mimeType, out encoding,out filenameExtension,out streamids, out warnings);
System.IO.FileStream fs = System.IO.File.Create(file Folder);
fs.Write(bytes,0,bytes.Len gth);
fs.Close();
}
private void exportToExcel(string fileFolder)
{
System.IO.FileInfo fi = new System.IO.FileInfo(fileFol
//
if (fi.Exists)
fi.Delete();
Warning[] warnings;
string[] streamids;
string mimeType, encoding, filenameExtension;
byte[] bytes = reportViewer1.LocalReport.
System.IO.FileStream fs = System.IO.File.Create(file
fs.Write(bytes,0,bytes.Len
fs.Close();
}
see more clear code
Code to render the report in PDF format using C#
http://forums.asp.net/p/1549431/3795020.aspx
Code to render the report in PDF format using C#
http://forums.asp.net/p/1549431/3795020.aspx
example
Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string filenameExtension;
byte[] bytes = reportViewer.LocalReport.Render( "PDF", null, out mimeType, out encoding, out filenameExtension, out streamids, out warnings);
using (FileStream fs = new FileStream("output.pdf", FileMode.Create))
{
fs.Write(bytes, 0, bytes.Length);
}
http://www.carlosag.net/Tools/ExcelXmlWriter/
It uses Excel 2003's XML format to generate a spreadsheet. Carlos even has a code generation tool that takes an existing spreadsheet and generates the code that would produce the spreadsheet. All you need to do is replace the static content with loops that retrieves the content from your data.