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

how to make header bold while export to excel

5 Answers 1533 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Gopinath
Top achievements
Rank 2
Gopinath asked on 06 Dec 2012, 11:30 AM
Hi,

I need to make the header text to bold while exporting Grid to excel.

In my page ,there no Grid control.
So to use export option of Grid , i have created a dynamic Grid Control and binding the data to it. 

As per requirements, i need to provide show-dialog box with a  default name (user can change name if he wants)

Below is my code

             AuthGridView authGridView = new AuthGridView();
            authGridView.AutoGenerateColumns = true;
            authGridView.ItemsSource = this.searchResults;

            SaveFileDialog dialog = new SaveFileDialog();
            dialog.DefaultExt = "*.xls";
            dialog.Filter = "Excel files (*.xls)|*.xls";
            dialog.DefaultFileName = DateTime.Now.ToString("yyyyMMddHHmmss");

            if (dialog.ShowDialog() == true)
            {
                using (Stream stream = dialog.OpenFile())
                {
                    GridViewExportOptions exportOptions = new GridViewExportOptions();
                    exportOptions.Format = ExportFormat.ExcelML;
                    exportOptions.ShowColumnFooters = true;
                    exportOptions.ShowColumnHeaders = true;
                    exportOptions.ShowGroupFooters = true;      

                    authGridView.Export(stream, exportOptions);
                }
            }

5 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 06 Dec 2012, 11:45 AM
Hi,

You can tamper with the exported content form within the ElementExporting event handler.

Kind regards,
Pavel Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Gopinath
Top achievements
Rank 2
answered on 06 Dec 2012, 04:23 PM
thanks a lot it solved my issue!!!
0
Swetha
Top achievements
Rank 1
answered on 24 Jul 2013, 09:13 PM
Hi Telerik Team,

I have a table with htmltextbox in the column cells. I want to display certain texts in the table in Bold letters.
I inserted <B> </B> tags for those rows in the table and it worked fine in pdf.
But the htmltextbox is not displaying those rows in bold in Excel.

Can you please help me on this?
0
Swetha
Top achievements
Rank 1
answered on 26 Jul 2013, 02:52 PM
I got it done. I applied a formatting rule for that particular columns and rows.
0
Darshan
Top achievements
Rank 1
answered on 10 Jan 2019, 06:19 PM

The exact code you can use for this is below.

private static void ElementExportingToDocument(object sender, GridViewElementExportingToDocumentEventArgs e)
        {
            if (e.Element == ExportElement.HeaderRow)
            {
                (e.VisualParameters as GridViewDocumentVisualExportParameters).Style = new CellSelectionStyle()
                {
                    FontSize = 16,
                    IsBold = true,
                    //Fill = new PatternFill(PatternType.Solid, Colors.Blue, Colors.Blue),
                    //ForeColor = new ThemableColor(Colors.White)
                };
            }
        }

Tags
GridView
Asked by
Gopinath
Top achievements
Rank 2
Answers by
Pavel Pavlov
Telerik team
Gopinath
Top achievements
Rank 2
Swetha
Top achievements
Rank 1
Darshan
Top achievements
Rank 1
Share this question
or