• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 957
  • Last Modified:

.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.
0
edfreels
Asked:
edfreels
1 Solution
 
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
 
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now