This is a migrated thread and some comments may be shown as answers.

Create simple report in C#

3 Answers 1615 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Vlad
Top achievements
Rank 1
Vlad asked on 11 Jul 2012, 01:13 AM
I am new to Telerik. I have working code to create/export to PDF. How do I adapt this code to export to Excel? The PDF version just builds a string and inserts it into the body of the report.

Code is below, any help is greatly appreciated.

 

private Telerik.Reporting.Report GetPlainReport(bool showPageCountFooter = true)

{

Telerik.Reporting.

 

Report report = new Telerik.Reporting.Report();

report.PageSettings.Landscape =

 

false;

report.PageSettings.Margins.Bottom =

 

new Telerik.Reporting.Drawing.Unit(2.5D, Telerik.Reporting.Drawing.UnitType.Cm);

report.PageSettings.Margins.Left =

 

new Telerik.Reporting.Drawing.Unit(2.5D, Telerik.Reporting.Drawing.UnitType.Cm);

report.PageSettings.Margins.Right =

 

new Telerik.Reporting.Drawing.Unit(2.5D, Telerik.Reporting.Drawing.UnitType.Cm);

report.PageSettings.Margins.Top =

 

new Telerik.Reporting.Drawing.Unit(2.5D, Telerik.Reporting.Drawing.UnitType.Cm);

report.PageSettings.PaperKind = System.Drawing.Printing.

 

PaperKind.A4;

Telerik.Reporting.

 

PageHeaderSection header = new Telerik.Reporting.PageHeaderSection();

header.Height =

 

new Telerik.Reporting.Drawing.Unit(1D, Telerik.Reporting.Drawing.UnitType.Cm);

Telerik.Reporting.

 

TextBox txtTitle = new Telerik.Reporting.TextBox();

txtTitle.Location =

 

new Telerik.Reporting.Drawing.PointU(new Telerik.Reporting.Drawing.Unit(0D, Telerik.Reporting.Drawing.UnitType.Cm), new Telerik.Reporting.Drawing.Unit(0D, Telerik.Reporting.Drawing.UnitType.Cm));

txtTitle.Name =

 

"htmlTitle";

txtTitle.Style.Font.Bold =

 

true;

txtTitle.Style.Font.Name =

 

"Arial";

txtTitle.Style.Font.Size =

 

new Telerik.Reporting.Drawing.Unit(16D, Telerik.Reporting.Drawing.UnitType.Point);

txtTitle.Style.TextAlign = Telerik.Reporting.Drawing.

 

HorizontalAlign.Left;

txtTitle.Size =

 

new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(16D, Telerik.Reporting.Drawing.UnitType.Cm), new Telerik.Reporting.Drawing.Unit(1D, Telerik.Reporting.Drawing.UnitType.Cm));

txtTitle.Value =

 

"{Parameters.Title.Value}";

header.Items.Add(txtTitle);

Telerik.Reporting.

 

DetailSection body = new Telerik.Reporting.DetailSection();

body.Height =

 

new Telerik.Reporting.Drawing.Unit(22.5D, Telerik.Reporting.Drawing.UnitType.Cm);

Telerik.Reporting.

 

HtmlTextBox htmlBody = new Telerik.Reporting.HtmlTextBox();

htmlBody.Location =

 

new Telerik.Reporting.Drawing.PointU(new Telerik.Reporting.Drawing.Unit(0D, Telerik.Reporting.Drawing.UnitType.Cm), new Telerik.Reporting.Drawing.Unit(0D, Telerik.Reporting.Drawing.UnitType.Cm));

htmlBody.Name =

 

"htmlBody";

htmlBody.Size =

 

new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(16D, Telerik.Reporting.Drawing.UnitType.Cm), new Telerik.Reporting.Drawing.Unit(22.5D, Telerik.Reporting.Drawing.UnitType.Cm));

htmlBody.Value =

 

"{Parameters.Body.Value}";

body.Items.Add(htmlBody);

Telerik.Reporting.

 

PageFooterSection footer = new Telerik.Reporting.PageFooterSection();

footer.Height =

 

new Telerik.Reporting.Drawing.Unit(1D, Telerik.Reporting.Drawing.UnitType.Cm);

 

if (showPageCountFooter)

{

Telerik.Reporting.

 

TextBox txtFooter = new Telerik.Reporting.TextBox();

txtFooter.Location =

 

new Telerik.Reporting.Drawing.PointU(new Telerik.Reporting.Drawing.Unit(0D, Telerik.Reporting.Drawing.UnitType.Cm), new Telerik.Reporting.Drawing.Unit(0D, Telerik.Reporting.Drawing.UnitType.Cm));

txtFooter.Name =

 

"htmlFooter";

txtFooter.Style.TextAlign = Telerik.Reporting.Drawing.

 

HorizontalAlign.Right;

txtFooter.Size =

 

new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(16D, Telerik.Reporting.Drawing.UnitType.Cm), new Telerik.Reporting.Drawing.Unit(1D, Telerik.Reporting.Drawing.UnitType.Cm));

txtFooter.Value =

 

"=PageNumber + ' / ' + PageCount";

footer.Items.Add(txtFooter);

}

report.Items.AddRange(

 

new Telerik.Reporting.ReportItemBase[] { header, body, footer });

report.ReportParameters.Add(

 

new Telerik.Reporting.ReportParameter("Title", Telerik.Reporting.ReportParameterType.String, null));

report.ReportParameters.Add(

 

new Telerik.Reporting.ReportParameter("Body", Telerik.Reporting.ReportParameterType.String, null));

 

return report;

}


3 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 11 Jul 2012, 06:51 AM
Hello Vlad,

The following help article elaborates on exporting Telerik Reports: Exporting Report Programmatically. The first argument of the RenderReport method is the rendering extension. All available rendering extensions are listed in Rendering Extensions help article.

Greetings,
Steve
the Telerik team

BLOGGERS WANTED! Write a review about Telerik Reporting or the new Report Designer, post it on your blog and get a complimentary license for Telerik Reporting. We’ll even promote your blog and help bring you a few fresh readers. Yes, it’s that simple. And it’s free. Get started today >

0
Vlad
Top achievements
Rank 1
answered on 11 Jul 2012, 03:14 PM
Hi Steve, I have no issues in rendering to an Excel file, but all data ends up in a single cell as opposed to each data item in a separate cell.

 

 


0
Elian
Telerik team
answered on 13 Jul 2012, 04:03 PM
Hi Vlad,

The data is not in a single cell as this is impossible to accomplish except if it rendered as a whole image, which is not the case. You can check that by simply clicking on the items in the rendered excel file and observe the selection. 
If you want to make the grid visible (by default it isn't) you turn it on from the Device Information settings by setting the ShowGridlines = True. You should also note that the Background Color of the report itself is by default White. If you want the grid in the Report's area to be visible you will have to set it to transparent (as well as any other background colors). 
 
Greetings,
Elian
the Telerik team

BLOGGERS WANTED! Write a review about Telerik Reporting or the new Report Designer, post it on your blog and get a complimentary license for Telerik Reporting. We’ll even promote your blog and help bring you a few fresh readers. Yes, it’s that simple. And it’s free. Get started today >

Tags
General Discussions
Asked by
Vlad
Top achievements
Rank 1
Answers by
Steve
Telerik team
Vlad
Top achievements
Rank 1
Elian
Telerik team
Share this question
or