I am trying to format the Excel that is being exported from radGrid and I can't seem to get it to pick up any of the styles. I am using:
It finds "CompanyName" I can make it visible false and it goes away. But it won't pick up the "excelHeaderStyle". Am I doing something wrong. Is there a way to style it?
Thanks!
protected void imgBtnExportCSV_Click(object sender, EventArgs e){ foreach (GridDataItem item in grdLeadList.MasterTableView.Items) //loop through each grid item { if (item.Selected) { selectedItems.Add(item.ItemIndex); } } grdLeadList.ExportSettings.ExportOnlyData = true; grdLeadList.ExportSettings.OpenInNewWindow = true; grdLeadList.MasterTableView.Columns.FindByUniqueName("ClientSelectColumn").Visible = false; grdLeadList.MasterTableView.Columns.FindByUniqueName("EditCommandColumn1").Visible = false; grdLeadList.MasterTableView.Columns.FindByUniqueName("CompanyName").ItemStyle.CssClass = "excelHeaderStyle"; grdLeadList.ExportSettings.FileName = "ColderLeads"; grdLeadList.MasterTableView.ExportToCSV(); }It finds "CompanyName" I can make it visible false and it goes away. But it won't pick up the "excelHeaderStyle". Am I doing something wrong. Is there a way to style it?
Thanks!
8 Answers, 1 is accepted
0
Jayesh Goyani
Top achievements
Rank 2
answered on 16 Dec 2011, 06:15 PM
Hello ,
Thanks,
Jayesh Goyani
protected void ExportActivity() { RadGrid1.ExportSettings.IgnorePaging = true; RadGrid1.ExportSettings.HideStructureColumns = true; RadGrid1.ExportSettings.ExportOnlyData = true; RadGrid1.ExportSettings.OpenInNewWindow = true; RadGrid1.ExportSettings.FileName = "FileNameTest"; // you can set style here foreach (GridDataItem item in RadGrid1.Items) { // for particuler item item["CompanyName"].Font.Name = "Calibri"; item["CompanyName"].Style["font-size"] = "8pt"; item["CompanyName"].Style["background-color"] = "#FFF"; item["CompanyName"].Style["vertical-align"] = "middle"; // for whole row item.Font.Name = "Calibri"; } RadGrid1.MasterTableView.ExportToPdf(); }Thanks,
Jayesh Goyani
0
Justin
Top achievements
Rank 1
answered on 16 Dec 2011, 11:03 PM
Hello Jayesh!
Thanks for the response.
I gave that a try and the formatting doesn't seem to be picked up in the CSV when it's exported. Any ideas?
Thanks!
Thanks for the response.
I gave that a try and the formatting doesn't seem to be picked up in the CSV when it's exported. Any ideas?
Thanks!
0
Shinu
Top achievements
Rank 2
answered on 19 Dec 2011, 05:45 AM
Hello Justin,
Give a try with the following code.
C#:
-Shinu.
Give a try with the following code.
C#:
protected void RadGrid1_ExportCellFormatting(object sender, ExportCellFormattingEventArgs e){ GridDataItem item1 = e.Cell.Parent as GridDataItem; if (e.FormattedColumn.UniqueName == "UniqueName") { TableCell cell = item["UniqueName"]; cell.Style["background-color"] = "Red"; }}-Shinu.
0
Justin
Top achievements
Rank 1
answered on 19 Dec 2011, 03:14 PM
Thanks!
How do I call that method, is there an event in the grid I call it from? I should also point out I am exporting to CSV. Can I still use this method?
How do I call that method, is there an event in the grid I call it from? I should also point out I am exporting to CSV. Can I still use this method?
0
Hello Justin,
The CSV format is based on a plain text - it is widely used to display simple tabular data without any formatting.
If you want to apply some styles, please consider exporting to Word/Excel.
I hope this helps.
Regards,
Mira
the Telerik team
The CSV format is based on a plain text - it is widely used to display simple tabular data without any formatting.
If you want to apply some styles, please consider exporting to Word/Excel.
I hope this helps.
Regards,
Mira
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Justin
Top achievements
Rank 1
answered on 19 Dec 2011, 09:09 PM
Thanks!
I'm using this to format my Excel document:
But how do you format the headers?
I'm using this to format my Excel document:
protected void RadGrid1_ExportCellFormatting(object sender, ExportCellFormattingEventArgs e){ GridDataItem item1 = e.Cell.Parent as GridDataItem; if (e.FormattedColumn.UniqueName == "UniqueName") { TableCell cell = item["UniqueName"]; cell.Style["background-color"] = "Red"; }}But how do you format the headers?
0
Shinu
Top achievements
Rank 2
answered on 20 Dec 2011, 07:33 AM
Hello,
Try the following code snippet to format the header.
CS:
-Shinu.
Try the following code snippet to format the header.
CS:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) { if (e.Item is GridHeaderItem) { e.Item.Style["background-color"] = "Red"; } }-Shinu.
0
Hello Justin,
You can use the code above if you rebind the grid before export (when you enable IgnorePaging, the grid will rebind).
When IgnorePaging="false" , you should rebind RadGrid manually, otherwise this approach won't work.
Please examine the Word/Excel export (HTML-based) topic for additional information.
Kind regards,
Mira
the Telerik team
You can use the code above if you rebind the grid before export (when you enable IgnorePaging, the grid will rebind).
When IgnorePaging="false" , you should rebind RadGrid manually, otherwise this approach won't work.
Please examine the Word/Excel export (HTML-based) topic for additional information.
Kind regards,
Mira
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now