.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.
LVL 1
edfreelsAsked:
Who is Participating?
 
Bob LearnedCommented:
I believe this code should give you a start to get your Excel file created:


using System;
    using System.IO;

...


    byte[] pdfContent = viewer.LocalReport.Render("PDF", null, null, null, null, null, null);
    
    //Create PDF file on disk
    string pdfPath = "C:\\temp\\reportBarcode.pdf";

    using (FileStream pdfFile = new FileStream(pdfPath, FileMode.Create))
    {
        pdfFile.Write(pdfContent, 0, pdfContent.Length);
    }
    
    //Open PDF file
    Process.Start(pdfPath);

Open in new window

0
 
MogalManicCommented:
You could use something like this library:
  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.
0
 
edfreelsAuthor Commented:
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.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
edfreelsAuthor Commented:
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(fileFolder);
            //
            if (fi.Exists)
                fi.Delete();
            Warning[] warnings;
            string[] streamids;
            string mimeType, encoding, filenameExtension;
            byte[] bytes = reportViewer1.LocalReport.Render("Excel",null,out mimeType, out encoding,out filenameExtension,out streamids, out warnings);
            System.IO.FileStream fs = System.IO.File.Create(fileFolder);
            fs.Write(bytes,0,bytes.Length);
            fs.Close();
        }
0
 
dj_alikCommented:
see more clear code
Code to render the report in PDF format using C#
http://forums.asp.net/p/1549431/3795020.aspx
0
 
dj_alikCommented:
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);
}

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.