This project has moved. For the latest updates, please go here.

Writing Bytestream using EPPlus

Apr 10, 2012 at 8:10 AM
Edited Apr 10, 2012 at 10:08 AM

Hi,

Greetings and thanks for the excellent tool. It helped me a lot while developing. I am stuck in a scenario. I hav already a rdlc file from where i am getting bytestream to export the rdlc content to Excel. Is there any way to write the bytestream using EPPlus. Thanks in advance.  

 

Atarpan

Apr 12, 2012 at 3:16 AM

found an workaround ... i have rendered the localreport to an image and converted it to a image byte array ....put the bytearray to the excel sheet and Bingo!!! it worked but its still coming as image if someone has better approch to keep the data as it is ,please suggest . Thanks in advance.

Coordinator
Apr 12, 2012 at 5:54 PM

Hi,

EPPlus can only read and write xlsx, so I cant think of a way to solve your problem.

Apr 13, 2012 at 7:33 AM
Edited Apr 13, 2012 at 7:46 AM

Hi, Thanks for your reply . yes, i am totally agree with you, EPPlus writes only to xlsx... the data i am getting from an report is in byte array format for an Excel .. we have already some method there to put images ..

byte[] data = File.ReadAllBytes(@"someimage.jpg");
MemoryStream ms = new MemoryStream(data);
using (System.Drawing.Image img = System.Drawing.Image.FromStream(ms))
                    {
                        if (img != null)
                        {
                            ExcelPicture pic = ws.Drawings.AddPicture("Pic1", img);
                            pic.SetSize(pictureWidth, pictureHeight);
                        }
                    }

can you please suggest how can i put an excel MemoryStream to an excel worksheet. I am getting byte array from that rdlc in below format

string reportType = "Excel";
        string mimeType;
        string encoding;
        string fileNameExtension;

        string deviceInfo =
        "<DeviceInfo>" +
        "  <OutputFormat>Excel</OutputFormat>" +
        "  <PageWidth>20in</PageWidth>" +
        "  <PageHeight>15in</PageHeight>" +
        "  <MarginTop>0.5in</MarginTop>" +
        "  <MarginLeft>1in</MarginLeft>" +
        "  <MarginRight>1in</MarginRight>" +
        "  <MarginBottom>0.5in</MarginBottom>" +
        "</DeviceInfo>";

        Warning[] warnings;
        string[] streams;
        byte[] renderedBytes;

        renderedBytes = rptlocalReportName.LocalReport.Render(
            reportType,
            deviceInfo,
            out mimeType,
            out encoding,
            out fileNameExtension,
            out streams,
            out warnings);
        return renderedBytes;