Page 2 of 2
create report from XML => exported result is empty
Posted: Mon Aug 08, 2011 6:24 am
by HighAley
Hello.
tr_ansis wrote:If I'm not going to use a template is it necessary to write all the code after
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.
create report from XML => exported result is empty
Posted: Wed Aug 10, 2011 8:57 am
by tr_ansis
Hi,
I have created a WebForms solution to create a mrt file (the designer is not supported in MVC) and have been able to load that in my MVC project. So I have exported my sample data to Excel as was my objective. You were right. It was the mrt file that was wrong. Thank you for your advice.
So, just to be absolutely sure, to render a report you need an mrt file ór you need the code similar you provided in your example
Code: Select all
//Create TitleBand
StiHeaderBand TitleBand = new StiHeaderBand();
TitleBand.Height = 0.85;
TitleBand.Name = "TitleBand";
page.Components.Add(TitleBand);
//Create Title text on header
StiText headerText = new StiText(new RectangleD(0, 0, page.Width, 0.85));
headerText.Text = "Tacticdescription";
headerText.HorAlignment = StiTextHorAlignment.Left;
headerText.Name = "TitleHeader";
headerText.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold);
TitleBand.Components.Add(headerText);
//Create HeaderBand
StiHeaderBand headerBand = new StiHeaderBand();
headerBand.Height = 0.5;
headerBand.Name = "HeaderBand";
page.Components.Add(headerBand);
//Create Databand
StiDataBand dataBand = new StiDataBand();
dataBand.DataSourceName = "Categories";
dataBand.Height = 0.5;
dataBand.Name = "DataBand";
page.Components.Add(dataBand);
double pos = 0;
double columnWidth = page.Width/dt.Columns.Count;
int nameIndex = 1;
foreach (DataColumn dataColumn in dt.Columns)
{
//Create text on header
StiText hText = new StiText(new RectangleD(pos, 0, columnWidth, 0.5));
hText = new StiText(new RectangleD(pos, 0, columnWidth, 0.5));
hText.Text.Value = dataColumn.Caption;
hText.HorAlignment = StiTextHorAlignment.Center;
hText.Name = "HeaderText" + nameIndex.ToString();
hText.Brush = new StiSolidBrush(Color.Orange);
hText.Border.Side = StiBorderSides.All;
headerBand.Components.Add(hText);
StiText dataText = new StiText(new RectangleD(pos, 0, columnWidth, 0.5));
dataText.Text = "{shiporder." + Stimulsoft.Report.CodeDom.StiCodeDomSerializator.ReplaceSymbols(dataColumn.ColumnName) + "}";
dataText.Name = "DataText" + nameIndex.ToString();
dataText.Border.Side = StiBorderSides.All;
dataBand.Components.Add(dataText);
pos = pos + columnWidth;
nameIndex++;
}
report.Compile();
Have I understood this correctly, you need either an mrt file or code? Without both the report doesn't 'know' which data to show so the report will be empty. It doesn't show all?
Thanks again for your help.
create report from XML => exported result is empty
Posted: Thu Aug 11, 2011 6:40 am
by HighAley
Hello.
tr_ansis wrote:Have I understood this correctly, you need either an mrt file or code? Without both the report doesn't 'know' which data to show so the report will be empty. It doesn't show all?
The mrt file or code posted by you is only report template. To render a report you need a data connection with data.
This code connects xml file with data:
Code: Select all
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()
//your code
......
// or report template
report.Load("d:\\Projects\\DemoApplication\\DemoApplication\\Resources\\SimpleList.mrt");
//Than you can compile report
report.Compile();
Thank you.
create report from XML => exported result is empty
Posted: Thu Aug 11, 2011 8:29 am
by tr_ansis
:biggrin:
Thank you again. This is exactly what I needed to know. My last question was just to be absolutely sure. I'm implementing this right now.
create report from XML => exported result is empty
Posted: Thu Aug 11, 2011 9:00 am
by Andrew
Hello,
Great! Have a nice day!
Thank you.