Hi guys,
before I export grid to pdf I need to write couple of titles lines include header from another grid.My pdf format should look like this:
Title: NYC DEPT OF EDUCATION
BUREAU OF COMPENSATION
ROSTER - 9/08 thru 06/09
Header coming from another grid:
TOTAL DAYS - 80 TOTAL AMOUNT - 1900
And then detail data which I exporting to PDF.
Please help me with that issue.So far I only have the following code:
PriReportGrid.ExportSettings.Pdf.PageTitle = "NEW YORK CITY DEPT.OF EDUCATION ";
PriReportGrid.MasterTableView.ExportToPdf();
Thanks so much
15 Answers, 1 is accepted
You can insert custom bits of HTML in the PdfExporting event.
protected
void
RadGrid1_PdfExporting(
object
sender, GridPdfExportingArgs e)
{
e.RawHTML ...
}
Best regards,
Daniel
the Telerik team
can you be more specific and provide for me example in pdf exporting event how to create multiple title lines.
Thanks so much for your help..
Here is a sample code-snippet:
protected
void
RadGrid1_PdfExporting(
object
sender, GridPdfExportingArgs e)
{
e.RawHTML =
"<div>Line1</div><div>Line2</div>"
+ e.RawHTML;
}
Regards,
Daniel
the Telerik team
it is working,however its working only for constant title.If I want to include some data in the title.For example if I have a DataTable consisting of dates and I want to create a title included that dates.
How can I do that.
Thanks again and Happy New Year.
You have the complete freedom to build your custom HTML code in the way you prefer. For instance, you can traverse your table, add the results to a StringBuilder, and then pass the generated string to the RawHTML property.
Best regards,
Daniel
the Telerik team
StringBuilder sb = new StringBuilder();
sb.AppendLine(
"<div>NEW YORK CITY DEPT.OF EDUCATION</div>");
sb.AppendLine(
"<div>BUREAU OF PEDAGOGIC COMPENSATION</div>");
sb.AppendLine(
"PER DIEM ROSTER");
sb.AppendLine(DateFrom.ToShortDateString());
sb.AppendLine(
" ");
sb.AppendLine(
"THRU");
sb.AppendLine(
" ");
sb.AppendLine(DateTo.ToShortDateString());
sb.AppendLine(
"<div>Eis-Id:");
sb.AppendLine(HeaderData.Rows[0][3].ToString());
sb.AppendLine(
"Name:");
sb.AppendLine(HeaderData.Rows[0][0].ToString() + HeaderData.Rows[0][1].ToString());
sb.AppendLine(
"</div>");
sb.AppendLine(
"<div>Empl-Id:");
sb.AppendLine(HeaderData.Rows[0][3].ToString());
sb.AppendLine(
"Total Days:");
sb.AppendLine(HeaderData.Rows[0][4].ToString());
sb.AppendLine(
"Total Amount:");
sb.AppendLine(
"$" + String.Format("{0:C}", HeaderData.Rows[0][5].ToString()));
sb.AppendLine(
"</div>");
e.RawHTML = sb + e.RawHTML;
My questions is:How can I apply style to this titles.I need set different colors.
As always thanks for your help.
Just add the desired inline styles to the DIV element. Simplified code-snippet is available below:
protected
void
RadGrid1_PdfExporting(
object
sender, GridPdfExportingArgs e)
{
e.RawHTML =
"<div style='color: #606010; background-color: #88afea; font-weight: bold;'>this is a test</div>"
+ e.RawHTML;
}
Regards,
Daniel
the Telerik team
I have a string builder:
sb.AppendLine(
"Total Amount:");
sb.AppendLine(
"$" + String.Format("{0:C}", HeaderData.Rows[0][5].ToString()));
sb.AppendLine(
"</div>");
sb.AppendLine(
"<div style='color: #008040; font-style:bold; font-size:12px'>Location:");
sb.AppendLine((
string)ViewState["SelectedLocation"]);
I want to put blank line between two titles after sb.AppendLine("</div>");
How can I do that.
Thanks so much for your help.
The easiest way would be to insert a paragraph element:
<
p
></
p
>
Regards,
Daniel
the Telerik team
I have another question for you:
I have a radgrid with a negative amount (for example -$1117.04) and I try to export to excel.In excel this field is displaying in red color and in parentnesis like this ($1117.04).I know that is the way radgrid is exporting but my users do not undastand that and want to see this number as negative number like this: -$1117.04.
How can I do that.
Thanks so much..
You could choose different approach depending on the Excel format you use:
1) HTML - Word/Excel export (HTML-based)
2) ExcelML - ExcelML basics
Let me know if you need any specific instructions
Best regards,
Daniel
the Telerik team
I am using ExcelML format.Please,can you give me a example how to export negative number and display negative number in excel spreadsheet.
As always thank you very much for your help.
Ok, I attached a demo project to this post. Let me know whether this helps.
Regards,
Daniel
the Telerik team
Hi Daniel,
I am sorry I should be more specific on this.
I have a following code:
<telerik:GridBoundColumn HeaderText="Available" DataField="MONEYLEFT" UniqueName="MONEYLEFT" ReadOnly="True" DataFormatString="{0:$#####.#0}" SortExpression="MONEYLEFT" HeaderButtonType="TextButton">
<HeaderStyle Width="60px" />
<ItemStyle Width="60px" />
/telerik:GridBoundColumn>
(Look at the dataformatstring) in the grid its appeared as negative but when I am exporting to Excel it looks like this:(1711.85).
Thanks for your help.
P.S.Also I forgot to mentioned this grid in the user control.
The DataFormatString will not affect the exported file when you use the ExcelML format.
Please try the following custom format:
style.NumberFormat.FormatType = NumberFormatType.General;
style.NumberFormat.Attributes[
"ss:Format"
] =
"#;-#"
;
Alternatively you could use one of the predefined number formats. See the Number Formats section in the ExcelML export help topic for more information.
Best regards,
Daniel
the Telerik team