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

Format Excel from Export

3 Answers 121 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Justin
Top achievements
Rank 1
Justin asked on 19 Dec 2011, 11:25 PM
I am exporting to Excel from radGrid and three different things I can not figure out. And I was hoping someone had some insight.

1. I want to style the headers of the columns, how do you do this?
2. I want to put an image in the top left of the Excel sheet, is this possible?
3. I want to show grid lines in the Excel instead of a white background. But only in Excel not the grid.

I'm able to get the normal data styled using this:

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";
 }
}

Thanks for any help, I'm pretty stuck.

3 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 20 Dec 2011, 06:26 AM
Hello Justin,


Option 1 :
foreach (GridHeaderItem headerItem in RadGrid1.MasterTableView.GetItems(GridItemType.Header))
            {
                headerItem.Style["color"] = "#000";
                headerItem.Style["background-color"] = "#FFFFCC";
                foreach (TableCell cell in headerItem.Cells)
                {
                    cell.Style["text-align"] = "left";
                    cell.Style["font-weight"] = "bold";
                }
            }

Option 2 :
protected void RadGrid1_GridExporting(object source, GridExportingArgs e)
    {
     string customHTML = "<img src=\"images/test.jpg\" />";
        e.ExportOutput = e.ExportOutput.Replace("<body>", String.Format("<body>{0}", customHTML));
    }

Option 3:
foreach (GridDataItem item in RadGrid1.Items)
            {
                item.Style["border"] = "1px solid black";
 
            }
 
 
            RadGrid1.MasterTableView.ExportToPdf();



Thanks,
Jayesh Goyani
0
Justin
Top achievements
Rank 1
answered on 20 Dec 2011, 04:01 PM
Thanks Jayesh!

Those worked! Two things I'm having problem with I was hoping you knew the answer to.

My headers are links because they are sortable in the grid. How do you make it so they aren't links in Excel? Also when I add the image it overlaps the data exported, it there a way to push the data down?

Thanks!
0
Jayesh Goyani
Top achievements
Rank 2
answered on 21 Dec 2011, 06:54 AM
Hello,

My headers are links because they are sortable in the grid. How do you make it so they aren't links in Excel( set  <ExportSettings ExportOnlyData="true"> )? Also when I add the image it overlaps the data exported, it there a way to push the data down? (Set Div's Height in Style).

Let me know if any concern.

Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Justin
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Justin
Top achievements
Rank 1
Share this question
or