create report from XML => exported result is empty

Stimulsoft Reports.NET discussion
tr_ansis
Posts: 11
Joined: Mon Jun 27, 2011 7:08 am

create report from XML => exported result is empty

Post by tr_ansis »

Hi, I have been trying very hard to get a report filled with data from an XML File. I have read the FAQ and found several answers to similar problems (here for example), but can't get it to work.

Here's my code:

Code: Select all

Private Function GetReport() As StiReport
        Dim report As StiReport = New StiReport()
        Dim data As DataSet = New DataSet("test")
        data.ReadXmlSchema("D:\TEMP\sample.xsd")
        data.ReadXml("D:\TEMP\sample.xml")
        report.RegData("MyDataSet", data)
        report.Dictionary.Synchronize()
        report.Render(False)
        Return report
    End Function
This method will be called from methods that export to HTML, Pdf and Excel. Here's an example:

Code: Select all

Function HTML() As MvcHtmlString
        Dim report As StiReport = GetReport()
        Dim exportservice = New StiHtmlExportService()

        Dim stream = New MemoryStream()
        exportservice.ExportHtml(report, stream)
        Dim reader = New StreamReader(stream)
        stream.Position = 0
        Dim test As String = (reader.ReadToEnd)

        Return MvcHtmlString.Create(test)
    End Function

 Function Excel() As ActionResult
        Dim report = GetReport()

        Dim s = New Stimulsoft.Report.Export.StiExcelExportService()
        Dim mySettings = New StiExcelExportSettings()
        Dim fs = New FileStream("MyFile.xls", FileMode.Create, FileAccess.ReadWrite)
        s.ExportExcel(report, fs, mySettings)

        Return File(fs, "application/vnd.ms-excel", "GridExcelExport.xls")
    End Function
To be clear, none of the export methods show any data.

If I use this code an empty screen appears. If I add a line to the GetReport-method that loads a sample report, empty tables are shown. I just cannot get the data to be shown.

What am I doing wrong? In the debugger the report does seem to contain data (I use 'seem' because I thought my code was suppose to work).
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

create report from XML => exported result is empty

Post by HighAley »

Hello.

Please send us a simple project with data which reproduces the problem.

Thank you.
tr_ansis
Posts: 11
Joined: Mon Jun 27, 2011 7:08 am

create report from XML => exported result is empty

Post by tr_ansis »

I have created a sample solution for VS 2010. I have also included my sample report which I created with the designer. Thanks for your help
Attachments
1224.MvcReportBuilder.rar
(459.48 KiB) Downloaded 420 times
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

create report from XML => exported result is empty

Post by HighAley »

Hello.

Unfortunately, currently Stimulsoft Reports don't support MVC applications and we do not have plans to develop this feature. Sorry.

Thank you.
tr_ansis
Posts: 11
Joined: Mon Jun 27, 2011 7:08 am

create report from XML => exported result is empty

Post by tr_ansis »

I know I use MVC, but that shouldn't matter. All methods that export use the export service of Stimulsoft. For example, the method that gets the Report as HTML returns a HTML-string. Using MVC should be irrelevant at that point. The export service should export the report to the memory stream. From there on I should be able to do with the stream what ever I want; return it to the browser as xls, pdf or html for example. Could you tell me why the stream isn't filled correctly? Is the XML wrong?

To give you some info. We are planning to buy a license from stimulsoft if we can solve this problem. We are developing an international transportation planning system. We are very keen on getting this solved. MVC is just used on the Ui. Creating a real report will probably be done in a background service (of which I have found some other examples on the forums). My solution is just to get to know your software and create a proof of concept.

Thank you
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

create report from XML => exported result is empty

Post by HighAley »

Hello.
tr_ansis wrote:I know I use MVC, but that shouldn't matter. All methods that export use the export service of Stimulsoft. For example, the method that gets the Report as HTML returns a HTML-string. Using MVC should be irrelevant at that point. The export service should export the report to the memory stream. From there on I should be able to do with the stream what ever I want; return it to the browser as xls, pdf or html for example. Could you tell me why the stream isn't filled correctly? Is the XML wrong?
Please after exporting report move position to the begin of file

Code: Select all

s.ExportExcel(report, fs, mySettings)
fs.Seek(0, SeekOrigin.Begin)
In the report template you must firstly describe how to use data from xml-file which you registering in code. Your report template uses Products table but there is no such table in sample.xml.

Thank you.
tr_ansis
Posts: 11
Joined: Mon Jun 27, 2011 7:08 am

create report from XML => exported result is empty

Post by tr_ansis »

Thank you for replying. I don't understand your answer completely. With "report template" do you mean the mrt file I included in the solution I posted? From this post I assumed a report can be generated without a mrt file. Was I correct? Can it be done?
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

create report from XML => exported result is empty

Post by HighAley »

Hello.
tr_ansis wrote:Thank you for replying. I don't understand your answer completely. With "report template" do you mean the mrt file I included in the solution I posted? From this post I assumed a report can be generated without a mrt file. Was I correct? Can it be done?
Yes, you can create report at runtime. You can see it in the attached sample project.

It will be easier to use report template (mrt file) to generate report. You can can set a data connection and an appearance of report in Designer then save as mrt file. Then you can use it in your code.

Thank you.
Attachments
1237.DynamicCreateReport.zip
(15.46 KiB) Downloaded 431 times
tr_ansis
Posts: 11
Joined: Mon Jun 27, 2011 7:08 am

create report from XML => exported result is empty

Post by tr_ansis »

Thank you for confirming my assumption that it is possible to create a report at runtime. Thank you also for your suggested workflow. I will look into that. I think we can create a template for all reports at design time and use that for all the related reports.

If I'm not going to use a template is it necessary to write all the code after

Code: Select all

report.Dictionary.Synchronize();
in your example?

I found the solution you provided on an other post earlier, but couldn't get it to run. The following line produces a nullreference exeption

Code: Select all

double columnWidth = page.Width/dt.Columns.Count;
on dt. This was one of the reasons I started this thread on this forum.

I tried your example with my xml file, but it still produces a nullreferenceExeption. I'm not sure how to procede.
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

create report from XML => exported result is empty

Post by HighAley »

Hello.
tr_ansis wrote:If I'm not going to use a template is it necessary to write all the code after

Code: Select all

report.Dictionary.Synchronize();
in your example?
If you're not going to generate a report you don't need that code. But your must Load mrt report before registering Data.

Code: Select all

report.Load("d:\\Report.mrt"); 
report.RegData(ds);
report.Dictionary.Synchronize();
tr_ansis wrote:I found the solution you provided on an other post earlier, but couldn't get it to run. The following line produces a nullreference exeption

Code: Select all

double columnWidth = page.Width/dt.Columns.Count;
on dt. This was one of the reasons I started this thread on this forum.

I tried your example with my xml file, but it still produces a nullreferenceExeption. I'm not sure how to procede.
Maybe there is no Categories table in your xml file therefore this line produce nullreference exeption.

If you still have any problems please send us your project to reproduce them.

Thank you.
Post Reply