Need to do something like tabs in EXCEL

14 posts, 1 answers
  1. Mark
    Mark avatar
    82 posts
    Member since:
    Jan 2015

    Posted 17 Jun 2015 Link to this post

    I have a VB.NET web application (4.0) Telerik Reporting Q1 2013.  What I need to do is something like tabs in excel where each tab is a different date.  I have datatables to bind the report to.  The online documentation is not as good as I hoped it would be so any direction would be greatly appreciated.

    Thanks

  2. David
    David avatar
    118 posts
    Member since:
    Jan 2011

    Posted 17 Jun 2015 in reply to Mark Link to this post

    Have you reviewed the "Report Book" options?  I have found that if I export a "Report book", each report becomes a worksheet in the workbook (the filename of the report book).  Thus if you create a single report book with 5 reports (consisting of your proposed tabs data), you would end up with a single .XLS document having 5 worksheets in it.  The document name of each report becomes the worksheet name in excel.

     

    I use that method to export huge collections of reports.

     

     

  3. Mark
    Mark avatar
    82 posts
    Member since:
    Jan 2015

    Posted 18 Jun 2015 in reply to David Link to this post

    No I have not as I am doing my first report ever.  So this is foreign to me at this point..  Can you elaborate more on how I can accomplish what you are suggesting?
  4. David
    David avatar
    118 posts
    Member since:
    Jan 2011

    Posted 18 Jun 2015 in reply to Mark Link to this post

    Well, first, read the documentation on the Telerik Report Book object.  It is a superset to the Report object. That is to say it a single document which contains a collection of reports.  

                                    Telerik.Reporting.ReportBook ourBook = new Telerik.Reporting.ReportBook();

                                    Telerik.Reporting.Report rpt1 = new Telerik.Reporting.Report();
                                    Telerik.Reporting.Report rpt2 = new Telerik.Reporting.Report();
                                    Telerik.Reporting.Report rpt3 = new Telerik.Reporting.Report();

                                    // at this point each report object should have all of its data and parameters set
                                    // you will obviously need to do that elsewhere

                                    rpt1.DocumentName = "Sheet1";
                                    rpt2.DocumentName = "Sheet2";
                                    rpt3.DocumentName = "Sheet3";

                                    ourBook.Reports.AddRange(new List<Telerik.Reporting.Report>() { rpt1, rpt2, rpt3 });

                                    Telerik.Reporting.Processing.ReportProcessor rProc = new Telerik.Reporting.Processing.ReportProcessor();
                                    Telerik.Reporting.InstanceReportSource irs = new Telerik.Reporting.InstanceReportSource();
                                    System.Collections.Hashtable dinfo = new System.Collections.Hashtable();
                                    irs.ReportDocument = ourBook;
                                    Telerik.Reporting.Processing.RenderingResult result = rProc.RenderReport("XLS", irs, dinfo);
                                    using (System.IO.FileStream fs = new System.IO.FileStream("Myfilename.xls", System.IO.FileMode.Create))
                                    {
                                        fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
                                        fs.Close();
                                    }

     

    Sorry for the C# but that should give you a clue.  The end result of that is a a single '.XLS" document containing three worksheets entitled "Sheet1", "Sheet2", and "Sheet3"

  5. Mark
    Mark avatar
    82 posts
    Member since:
    Jan 2015

    Posted 18 Jun 2015 in reply to David Link to this post

    Thanks, Seems just what I need.  No worries about the C# as I code in both.  This job is a VB one.  Will post once I give it a try. 
  6. David
    David avatar
    118 posts
    Member since:
    Jan 2011

    Posted 18 Jun 2015 in reply to Mark Link to this post

    I would point out one minor glitch in the process.  The "document name" must adhere to the naming conventions of your output format.  In the case of Excel you must be 31 or fewer characters and not contain certain special characters.  It makes sense however it is annoying to find out the hard way.

     

  7. Mark
    Mark avatar
    82 posts
    Member since:
    Jan 2015

    Posted 18 Jun 2015 in reply to David Link to this post

    Thanks for the tip.  It will be just a date so I should be fine.
  8. Mark
    Mark avatar
    82 posts
    Member since:
    Jan 2015

    Posted 23 Jun 2015 Link to this post

    Getting an error (see below)

    Here is my code:

    Dim rptSheet As New Report
    rptSheet.DocumentName = tmpStartDate.ToString("MM.dd.yyyy")

    rptMSVS.Reports.Add(rptSheet)

    Dim rpt As New sbrSummary 
    rpt.DataSource = dtTop

     

    Dim rptProcessor As New Telerik.Reporting.Processing.ReportProcessor()
    Dim instance As New InstanceReportSource()
    Dim hshTable As New Hashtable()
    instance.ReportDocument = rptMSVS

     

    Error on this line: Object reference not set to an instance of an object.

    Dim result As Telerik.Reporting.Processing.RenderingResult = rptProcessor.RenderReport("XLS", instance, hshTable)

  9. Nasko
    Admin
    Nasko avatar
    1045 posts

    Posted 23 Jun 2015 Link to this post

    Hello Mark,

    The code
    Dim rptSheet As New Report
    will create a new object of type Telerik.Reporting.Report. However, in this state the object will be empty i.e., it will not contain any report items, report sections, etc.

    You need to create a new report, as described in the How To: Create a Report (Visual Studio) help article and then create an instance of that report:
    Dim rptSheet As New MyReport


    Regards,
    Nasko
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  10. Mark
    Mark avatar
    82 posts
    Member since:
    Jan 2015

    Posted 23 Jun 2015 in reply to Nasko Link to this post

    Thanks for the reply.  I do not have that option in the version I have (see original post).
  11. David
    David avatar
    118 posts
    Member since:
    Jan 2011

    Posted 23 Jun 2015 in reply to Mark Link to this post

    You seems to have gotten things in reverse.  The "rptSheet" is the report you are trying to export.  I am guessing you really mean "rpt" (ie sbrSummary)..  Your code creates a new instance of the object typed as a Telerik Report however you never define its basic structure as which report, what its structure is and so forth.  I believe that is what you meant to do with sbrSummary.

     I also do not see any ReportBook object.  The report book object is a collection of Report objects which is then exported.  You seem to be attempting to export each individual report.  That should be done to the report book object not the individual reports.

  12. Nasko
    Admin
    Nasko avatar
    1045 posts

    Posted 23 Jun 2015 Link to this post

    Hello Mark,

    In this case you can create a new report in Visual Studio from the Add > New Item... > Telerik Report <version> project context menu.

    Regards,
    Nasko
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  13. Mark
    Mark avatar
    82 posts
    Member since:
    Jan 2015

    Posted 23 Jun 2015 in reply to Nasko Link to this post

    I do have a report created(new page) and a report viewer to test on the same page.  For now I am trying to just show it in the report viewer but if that wont work I am open for the 'right' way :).    Thanks for everyones help.  Being a newbie to reports and telerik this is heading me in the right direction. 
  14. Answer
    Nasko
    Admin
    Nasko avatar
    1045 posts

    Posted 23 Jun 2015 Link to this post

    Hello Mark,

    As David suggested previously, you will most probably need to add the sbrSummary report to a report book and render it:
    'create an instance of your report and modify its definition if needed
    Dim report = New sbrSummary()
    report.DocumentName = tmpStartDate.ToString("MM.dd.yyyy")
    report.DataSource = dtTop
     
    'create a report book
    Dim reportBook = New ReportBook()
    reportBook.Reports.Add(report)
    'add other reports to the report book here
     
    Dim rptProcessor = New Telerik.Reporting.Processing.ReportProcessor()
    Dim reportSource = New InstanceReportSource()
    Dim hshTable = New Hashtable()
    reportSource.ReportDocument = reportBook
     
    'render the report book using a report processor object
    Dim result = rptProcessor.RenderReport("XLSX", reportSource, hshTable)


    Regards,
    Nasko
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top