Adam Hubble
Top achievements
Rank 1
Adam Hubble
asked on 01 Jul 2009, 09:38 AM
Hi, I have been having a go at styling the appearance of the grid exports and have a few issues - mostly I am unsure about which e.item in code should be used to target the area I am trying to style. The example only covers general styling.
PDF
1. I need to left align one column (my productName column) but can't find a way to target just this column.
2. I would like to put some margin on the bottom of the header / or top margin on first row of the data, but can't see how to do this.
3. I would like to format the Page Title - this must be easy, but again I can't see how to do this.
Many thanks,
Matt
1. I need to left align one column (my productName column) but can't find a way to target just this column.
2. I would like to put some margin on the bottom of the header / or top margin on first row of the data, but can't see how to do this.
3. I would like to format the Page Title - this must be easy, but again I can't see how to do this.
Many thanks,
Matt
5 Answers, 1 is accepted
0
Accepted
Princy
Top achievements
Rank 2
answered on 01 Jul 2009, 10:18 AM
Hello Matt,
1) & 2) You can try out the following code and see if it helps export your grid with the required styles:
3) Refer to the following forum link which discusses o formatting the page title while exporting to pdf:
Export to PDF - PageTitle Style
Thanks
Princy.
1) & 2) You can try out the following code and see if it helps export your grid with the required styles:
| bool isPdfExport; |
| protected void Button1_Click1(object sender, EventArgs e) |
| { |
| isPdfExport = true; |
| RadGrid2.ExportSettings.OpenInNewWindow = true; |
| RadGrid2.MasterTableView.ExportToPdf(); |
| } |
| protected void RadGrid2_ItemCreated(object sender, GridItemEventArgs e) |
| { |
| if (isPdfExport) |
| { |
| if (e.Item is GridDataItem) |
| { |
| GridDataItem dataItem = (GridDataItem)e.Item; |
| dataItem["ProductName"].Style["text-align"] = "left"; |
| } |
| if (e.Item is GridHeaderItem) |
| { |
| GridHeaderItem headerItem = (GridHeaderItem)e.Item; |
| headerItem.Style["margin-bottom"] = "10pt"; |
| } |
| } |
| } |
3) Refer to the following forum link which discusses o formatting the page title while exporting to pdf:
Export to PDF - PageTitle Style
Thanks
Princy.
0
Accepted
Hello Matt,
Onto your questions:
1. This is easy. An example is shown below:
2. This is not that hard also:
3. I'm afraid this is not supported. You can't apply styles to the page title since it is rendered as a title tag (<title></title>).
I hope this helps.
Best regards,
Daniel
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Onto your questions:
1. This is easy. An example is shown below:
| protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) |
| { |
| if (e.Item is GridDataItem && isExport) |
| (e.Item as GridDataItem)["productName"].Style["text-align"] = "right"; |
| } |
2. This is not that hard also:
| protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) |
| { |
| if (e.Item is GridHeaderItem && isExport) |
| { |
| foreach (TableCell cell in e.Item.Cells) |
| cell.Style["padding-bottom"] = "30px"; |
| } |
| } |
3. I'm afraid this is not supported. You can't apply styles to the page title since it is rendered as a title tag (<title></title>).
I hope this helps.
Best regards,
Daniel
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Adam Hubble
Top achievements
Rank 1
answered on 01 Jul 2009, 11:20 AM
Thank you both.
I have another small issue with an Excel export, in my price column, null or zero values are set to "Call" in the grid on load. When I export to excel however, all of the price integer values are aligned right but any cells in the same column with "Call" are aligned left.
I'm all set if I can fix this!
Thanks,
Matt
I have another small issue with an Excel export, in my price column, null or zero values are set to "Call" in the grid on load. When I export to excel however, all of the price integer values are aligned right but any cells in the same column with "Call" are aligned left.
I'm all set if I can fix this!
Thanks,
Matt
0
Hello Matt,
I recommend you use the ExcelExportCellFormatting event:
More information is available in the following link:
Export to Microsoft Excel/Word/PDF/CSV
Best regards,
Daniel
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
I recommend you use the ExcelExportCellFormatting event:
| protected void RadGrid1_ExcelExportCellFormatting(object source, ExcelExportCellFormattingEventArgs e) |
| { |
| if (e.FormattedColumn.UniqueName == "myColumnName") |
| { |
| e.Cell.HorizontalAlign = HorizontalAlign.Center; |
| } |
| } |
More information is available in the following link:
Export to Microsoft Excel/Word/PDF/CSV
Best regards,
Daniel
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Adam Hubble
Top achievements
Rank 1
answered on 01 Jul 2009, 01:50 PM
Worked great. Thanks again.