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

Export (Excel) problem

13 Answers 243 Views
GridView
This is a migrated thread and some comments may be shown as answers.
George Felipe
Top achievements
Rank 1
George Felipe asked on 30 Mar 2010, 03:36 PM
Hi,

I've been messing around with the GridView export functionality and it works great. However, I have a problem when the fields in the excel are "Out of the viewing area".

Excel fields that are not initially within the viewable area are shortened and are impossible to read unless expanded. I found a workaround by adding a column width to every column...but I do not know the size of the columns so they may be cut off. Is there another way to have these fields so that the auto size works in the excel?

13 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 31 Mar 2010, 07:17 AM
Hello,

Can you post more info about how the grid is configured and exported in your scenario?

Greetings,
Vlad
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
George Felipe
Top achievements
Rank 1
answered on 31 Mar 2010, 05:12 PM
Grids that usually have lots of columns and you need to scroll to the right produce this problem (at least in my case).

Here is my Grid

<Grid x:Name="ContentGrid">         
            <telerikGrid:RadGridView x:Name="grdVariance"  AutoGenerateColumns="False" IsReadOnly="True"
                <Navigation:RadContextMenu.ContextMenu> 
                    <Navigation:RadContextMenu x:Name="radContext" ItemClick="RadContextMenu_ItemClick">                    
                    </Navigation:RadContextMenu> 
                </Navigation:RadContextMenu.ContextMenu> 
                <telerikGrid:RadGridView.Columns> 
                    <telerikGrid:GridViewDataColumn DataMemberBinding="{Binding PartNum}" Header="Part Num" /> 
                    <telerikGrid:GridViewDataColumn DataMemberBinding="{Binding PONum}" Header="PONum"/> 
                    <telerikGrid:GridViewDataColumn DataMemberBinding="{Binding POLine}" Header="POLine"/> 
                    <telerikGrid:GridViewDataColumn DataMemberBinding="{Binding PORel}" Header="PORel"/> 
                    <telerikGrid:GridViewDataColumn DataMemberBinding="{Binding Variance}" Header="PO Variance" DataFormatString="{}{0:c}"/> 
                    <telerikGrid:GridViewDataColumn DataMemberBinding="{Binding VendorID}" Header="Vendor ID" /> 
                    <telerikGrid:GridViewDataColumn DataMemberBinding="{Binding VendorName}" Header="Vendor Name"/> 
                    <telerikGrid:GridViewDataColumn DataMemberBinding="{Binding ShipName}" Header="Ship Name"/> 
                    <telerikGrid:GridViewDataColumn DataMemberBinding="{Binding ShipAddress1}" Header="Ship Address 1"/> 
                    <telerikGrid:GridViewDataColumn DataMemberBinding="{Binding ShipAddress2}" Header="Ship Address 2"/> 
                    <telerikGrid:GridViewDataColumn DataMemberBinding="{Binding ShipAddress3}" Header="Ship Address 3"/> 
                    <telerikGrid:GridViewDataColumn DataMemberBinding="{Binding ShipCity}" Header="Ship City"/> 
                    <telerikGrid:GridViewDataColumn DataMemberBinding="{Binding ShipState}" Header="Ship St"/> 
                    <telerikGrid:GridViewDataColumn DataMemberBinding="{Binding ShipZip}" Header="Ship Zip"/> 
                    <telerikGrid:GridViewDataColumn DataMemberBinding="{Binding ShipCountry }" Header="Ship Country"/> 
                    <telerikGrid:GridViewDataColumn DataMemberBinding="{Binding Buyer}" Header="Buyer"/> 
                    <telerikGrid:GridViewDataColumn DataMemberBinding="{Binding Date}" Header="Order Date" DataFormatString="{}{0:d}" /> 
                    <telerikGrid:GridViewDataColumn DataMemberBinding="{Binding DueDate}" Header="Due Date" DataFormatString="{}{0:d}" /> 
                    <telerikGrid:GridViewDataColumn DataMemberBinding="{Binding ReceiptDate}" Header="Receipt Date" DataFormatString="{}{0:d}" /> 
                    <telerikGrid:GridViewDataColumn DataMemberBinding="{Binding HelpDesk}" Header="HD Case" DataFormatString="{}{0:0}" /> 
                    <telerikGrid:GridViewDataColumn DataMemberBinding="{Binding Topic1Desc}" Header="Topic Desc 1"/> 
                    <telerikGrid:GridViewDataColumn DataMemberBinding="{Binding Topic2Desc}" Header="Topic Desc 2"/> 
                </telerikGrid:RadGridView.Columns> 
            </telerikGrid:RadGridView> 
        </Grid> 

Here is my export function

  public static void ExportGrid(RadGridView grid) 
        { 
            SaveFileDialog dialog = new SaveFileDialog() 
            { 
                DefaultExt = "xls"
                Filter = "Excel files (*.xls)|*.xls"
                FilterIndex = 1 
            }; 
 
            try 
            { 
                grid.Exporting += new EventHandler<GridViewExportEventArgs>(grid_Exporting); 
 
                if (dialog.ShowDialog() == true
                { 
                    using (Stream stream = dialog.OpenFile()) 
                    { 
 
                        grid.Export(stream, new Telerik.Windows.Controls.GridViewExportOptions() 
                        { 
                            Format = Telerik.Windows.Controls.ExportFormat.ExcelML, 
                            ShowColumnHeaders = true 
                        }); 
 
                    } 
                }  
                 
            } 
            catch (IOException) 
            { 
                MessageBox.Show("File with the current name is open. Please rename or close the open file""Error", MessageBoxButton.OK); 
            }            
        } 

Here is the Export trigger

 static void grid_Exporting(object sender, GridViewExportEventArgs e) 
        {          
            if (e.Element == ExportElement.HeaderRow || e.Element == ExportElement.FooterRow 
                || e.Element == ExportElement.GroupFooterRow) 
            { 
                e.Height = 25; 
                e.FontSize = 20; 
                e.FontWeight = FontWeights.Bold; 
            } 
            else if (e.Element == ExportElement.Row) 
            { 
                e.Height = 15; 
            } 
            else if (e.Element == ExportElement.GroupHeaderRow) 
            { 
                e.FontFamily = new FontFamily("Verdana"); 
                e.Background = Colors.LightGray; 
                e.Height = 30; 
            } 
 
            (sender as RadGridView).Exporting -= grid_Exporting; 
        } 



0
Vlad
Telerik team
answered on 06 Apr 2010, 09:10 AM
Hello,

I've tried this however didn't get such problem. You can check the attached example application for reference.

Regards,
Vlad
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
naina
Top achievements
Rank 1
answered on 22 Apr 2010, 12:26 AM
I am still getting the Error Dialogs must be user-initiated.


private

 

void btnExport_Click(object sender, RoutedEventArgs e)

 

{

 

try

 

{

 

string extension = "xls";

 

 

SaveFileDialog dialog = new SaveFileDialog()

 

{

DefaultExt = extension,

Filter =

String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", extension, "Excel"),

 

FilterIndex = 1

};

 

if (dialog.ShowDialog() == true)

 

{

 

using (Stream stream = dialog.OpenFile())

 

{

 

using (StreamWriter sw = new StreamWriter(stream, Encoding.UTF8))

 

{

sw.Write(radGridView.ToHtml());

}

stream.Close();

}

}

 

}

 

catch (IOException)

 

{

 

MessageBox.Show("File with the current name is open. Please rename or close the open file", "Error", MessageBoxButton.OK);

 

}

}




 

static void RadGridView1_Exporting(object sender, GridViewExportEventArgs e)

 

{

 

if (e.Element == ExportElement.HeaderRow )

 

{

e.Height = 25;

e.FontSize = 20;

e.FontWeight =

FontWeights.Bold;

 

}

 

else if (e.Element == ExportElement.Row)

 

{

e.Height = 15;

}

 

else if (e.Element == ExportElement.GroupHeaderRow)

 

{

e.FontFamily =

new FontFamily("Verdana");

 

e.Background =

Colors.LightGray;

 

e.Height = 30;

}

 

//(sender as RadGridView).Exporting -= grid_Exporting;

 

}

0
Vlad
Telerik team
answered on 22 Apr 2010, 07:12 AM
Hello,

Can you send us small running example application where this can be reproduced?

Greetings,
Vlad
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
naina
Top achievements
Rank 1
answered on 23 Apr 2010, 12:51 AM
This issue has been fixed.

I am trying to calculate the amount total footer in excel sheet this is not required to display on grid. Can you please send any example.

 

 

I am getting this error for DEMO CODE

 

 

Error 22    'Telerik.Windows.Controls.ExportElement' does not contain a definition for 'GroupFooterCell'

 

 

else if (e.Element == ExportElement.GroupFooterCell)

            {

                GridViewDataColumn column = e.Context as GridViewDataColumn;

                AggregateFunctionsGroup group = e.Value as AggregateFunctionsGroup;

 

                if (column != null && group != null && column.AggregateFunctions.Count() > 0)

                {

                    AggregateResultCollection aggregateResults = group.GetAggregateResults(column.AggregateFunctions);

 

                    List<string> result = new List<string>();

                    foreach (AggregateResult r in aggregateResults)

                    {

                        if (r.FormattedValue != null)

                        {

                            result.Add(r.FormattedValue.ToString());

                        }

                    }

                    e.Value = String.Join(",", result.ToArray());

                }

            }

0
Prathap Narravula
Top achievements
Rank 1
answered on 21 May 2010, 07:24 PM
Hi i am getting exporting the grid but the problem is  hwow can i ignore paging
0
Yavor Georgiev
Telerik team
answered on 26 May 2010, 08:14 AM
Hello prathap narravula,

 The GridViewExportOptions object has an Items property. Simply set it to your RadDataPager's ItemsSource property and perform the export operation.

Sincerely yours,
Yavor Georgiev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Prathap Narravula
Top achievements
Rank 1
answered on 26 May 2010, 08:37 AM

Dear Yavor Georgiev ,

Thanks for reply

i didn't find RadDataPager's ItemsSource property for Radgrid...
 
But i  used the following code for exporting Radgrid to Excel when button click

 

protected

 

void Button1_Click(object sender, EventArgs e)

 

{

RadGrid1.MasterTableView.ExportToExcel();

}

I am able to get exporting but not ignoring the paging.

Please help to get all the records.. try to send complete code to export Radgrid to Excel

Regards,
Prathap Narravula

0
Vlad
Telerik team
answered on 26 May 2010, 08:43 AM
Hello,

This code is related to our RadGrid for ASP.NET/ASP.NET AJAX. Please post your questions in the relevant forum!

Kind regards,
Vlad
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Prathap Narravula
Top achievements
Rank 1
answered on 26 May 2010, 09:10 AM


Please send me the code in Ajax.. I am also using ajax
0
Rainer
Top achievements
Rank 1
answered on 10 Jun 2011, 07:29 AM
Hello, we have the same exact behavior as described above. Ie the columns that are outside viewing area are squeezed. We use the export method copied from one of your examples. Could it be caused by some setting in excel?
0
Dimitrina
Telerik team
answered on 15 Jun 2011, 09:59 AM
Hello Rainer,

 As I understand from your post the columns outside the viewing area are squeezed, not hidden. Is that correct? 

I was able to reproduce that they are hidden, but not that they are squeezed when I am using the Export method of the RadGridView. May you please share with what example have you used to do the export? Are you doing the exporting with the Export method or with RadDocument?

Greetings,
Didie
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
George Felipe
Top achievements
Rank 1
Answers by
Vlad
Telerik team
George Felipe
Top achievements
Rank 1
naina
Top achievements
Rank 1
Prathap Narravula
Top achievements
Rank 1
Yavor Georgiev
Telerik team
Rainer
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or