Excel generation - custom data from DB

edited October 2013 in FastReport .NET
Hi,

I develope some application that needs reporting data to excel. I found the best solution for me but still don't know why to store connectionstring and select command in frx file because i want to use business object to generate data. I do tests on name, surname and pesel data so:
<?xml version="1.0" encoding="utf-8"?>
<Report ScriptLanguage="CSharp" ReportInfo.Created="10/09/2013 10:02:08" ReportInfo.Modified="10/09/2013 14:54:43" ReportInfo.CreatorVersion="2013.2.5.0">
  <Dictionary>
    <MsSqlDataConnection Name="Connection" ConnectionString="blablablalblabla">
      <TableDataSource Name="Table" Alias="MIS-Rynek" DataType="System.Int32" Enabled="true" SelectCommand="SELECT Name, Surname, PESEL FROM [User] U 
JOIN User_Data UD ON U.User_Id = UD.User_Id">
        <Column Name="Name" DataType="System.String"/>
        <Column Name="Surname" DataType="System.String"/>
        <Column Name="PESEL" DataType="System.String"/>
      </TableDataSource>
    </MsSqlDataConnection>
  </Dictionary>
  <ReportPage Name="Page1">
    <ReportTitleBand Name="ReportTitle1" Width="718.2" Height="37.8"/>
    <PageHeaderBand Name="PageHeader1" Top="41.8" Width="718.2" Height="18.9">
      <TextObject Name="Text2" Left="47.25" Width="94.5" Height="18.9" Text="Name" Font="Arial, 10pt, style=Bold"/>
      <TextObject Name="Text4" Left="160.65" Width="94.5" Height="18.9" Text="Surname" Font="Arial, 10pt, style=Bold"/>
      <TextObject Name="Text6" Left="274.05" Width="94.5" Height="18.9" Text="PESEL" Font="Arial, 10pt, style=Bold"/>
    </PageHeaderBand>
    <DataBand Name="Data1" Top="64.7" Width="718.2" Height="18.9">
      <TextObject Name="Text1" Left="47.25" Width="94.5" Height="18.9" Fill.Color="LightCoral" Text="[Iterator1.Name]"/>
      <TextObject Name="Text3" Left="160.65" Width="94.5" Height="18.9" Text="[Iterator1.Surname]"/>
      <TextObject Name="Text5" Left="274.05" Width="94.5" Height="18.9" Text="[Iterator1.PESEL]"/>
    </DataBand>
    <PageFooterBand Name="PageFooter1" Top="87.6" Width="718.2" Height="37.8"/>
  </ReportPage>
</Report>

AND in C#
public FileResult UsersReport()
        {
            FastReport.Export.Xml.XMLExport xmlExport = new FastReport.Export.Xml.XMLExport();
            FastReport.Export.Pdf.PDFExport pdfExport = new FastReport.Export.Pdf.PDFExport();
            pdfExport.ShowProgress = false;
            pdfExport.Subject = "Subject";
            pdfExport.Title = "xxxxxxx";
            pdfExport.Compressed = true;
            pdfExport.AllowPrint = true;
            pdfExport.EmbeddingFonts = true;
            FastReport.Export.OoXML.Excel2007Export exclExport = new FastReport.Export.OoXML.Excel2007Export();
                         
            Report report = new Report();            
            report.Load(Server.MapPath("~/Content/docs/Users.frx"));
            
            var usrs = SgUser.GetUsers().Select(m => m.Login.ToLower() == "admin");
            report.RegisterData(usrs.AsEnumerable(), "Table");
            //DataSourceBase dsb = report.GetDataSource("Table");
            ((DataBand)report.Pages[0].ChildObjects[2]).DataSource = null;// report.GetDataSource("Table");            

            FastReport.Users report1 = new FastReport.Users();
            report1.RegisterData(usrs.AsEnumerable(), "Table");
            report1.Data1.DataSource = report1.GetDataSource("Table");            

            report1.Prepare();                            
            report.Prepare();           

            report.Export(xmlExport, Server.MapPath("~/mis.xml"));
            report.Export(pdfExport, Server.MapPath("~/mis.pdf"));
            report.Export(exclExport, Server.MapPath("~/mis.xlsx"));

            return File(Server.MapPath("~/mis.xlsx"), "application/octet-stream", "mis.xlsx");
        }

This example working for me but why I need to store connection string and select command in frx? I use my own connection string from applicataion and Business object to report the data. When I delete Connection section from frx file, example is not working even if I add my connection string and my enumerable data.

Comments

  • edited 2:31AM
    I solved my problem. It was easy [img]style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> There were conflict with names in DataSaource and then conflict in names getting from BusinessObject. You can close the thread.[/img]
This discussion has been closed.