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

RadGridView Export to excel office 2007 issues

18 Answers 263 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Rama
Top achievements
Rank 1
Rama asked on 01 Aug 2010, 09:27 PM
Hi,
    I am using the sample code for exporting to excel using exportML option. I have the following issues:
1)       The file that it is creating is with the extension XML. I cannot open the file manually, it gives me a message "The converter failed to save the file". I am using Office 2007.

2) After saving the file in XML format,  he sample code creates the file but how do i open the file programatically?


Thanks.

18 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 03 Aug 2010, 01:09 PM
Hi Rama,

Straight to your questions:

1. I could not reproduce the problem in our Exporting demo. Can you try please?

2. In Silverlight, to open a file on the client you need to use the OpenFileDialog class. Also, that dialog should be shown as a result of a user action, e.g. clicking on a button.

Hope this helps.

All the best,
Veskoni
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
Rama
Top achievements
Rank 1
answered on 03 Aug 2010, 02:38 PM
Hi Veskoni,
    Can you please provide me with the code that is under the link that you suggested in your previous email? I want to open the file programmatically without any user intervention. How do i do that?

Thanks.
0
Rama
Top achievements
Rank 1
answered on 03 Aug 2010, 03:08 PM
Hi Veskoni,
    This question is seperate from my previous question. I have the following XAML and trying to export to excel does not export the column header: What is the solution to this?

<telerikgrid:GridViewDataColumn FooterCellStyle="{StaticResource GridViewDefaultFooterCellStyle}" HeaderCellStyle="{StaticResource GridViewDefaultHeaderCellStyle}" 
DataMemberBinding="{Binding NextLotPurchases.Value,Mode=TwoWay,Converter={StaticResource ZStoSConverter}}"
CellStyleSelector="{StaticResource selector}"
x:Name="gdcLotPurchases">
<telerikgrid:GridViewDataColumn.Header>
<StackPanel HorizontalAlignment="Center">
<TextBlock Text="Lot" TextWrapping="Wrap" HorizontalAlignment="Center"/>
<TextBlock Text="Purchases" TextWrapping="Wrap" HorizontalAlignment="Center"/>
</StackPanel>    
</telerikgrid:GridViewDataColumn.Header>
0
Rama
Top achievements
Rank 1
answered on 03 Aug 2010, 03:29 PM
Hi Veskoni,
    This is pertaining to my last email. How do i break the header into 2 lines:

Header="New Gross \r\n Profit(%)"
 does not work.

This is an urgent issue please respond.
0
Veselin Vasilev
Telerik team
answered on 03 Aug 2010, 03:57 PM
Hello Rama,

You cannot open a file dialog without the user intervention. This is done for security reasons and I am not aware of any workaround.

Again, trying on the online demo - I cannot reproduce the problem with exporting the Headers.

As for the multiline header - yes, this is possible. The Header property is of type object and you can place anything in it, including a TextBlock:

<telerik:GridViewComboBoxColumn.Header>
     <TextBlock Text="Long Header Long Header" TextWrapping="Wrap" />
</telerik:GridViewComboBoxColumn.Header>

Hope this helps.

Best wishes,
Veskoni
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
Rama
Top achievements
Rank 1
answered on 03 Aug 2010, 04:07 PM
Veskoni,
    You keep on giving me the link to demo, but where is the code?

ALso, because I am using text blocks to break my headers, the export is not exporting the header. Again, here is the XAML:
What is my option?

<telerikgrid:GridViewDataColumn.Header>
                                        <StackPanel HorizontalAlignment="Center">
                                            <TextBlock Text="New Gross" TextWrapping="Wrap" HorizontalAlignment="Center"/>
                                            <TextBlock Text="Profit(%)" TextWrapping="Wrap" HorizontalAlignment="Center"/>
                                        </StackPanel>
                                    </telerikgrid:GridViewDataColumn.Header>
0
Veselin Vasilev
Telerik team
answered on 03 Aug 2010, 04:30 PM
Hello Rama,

To view the code of the demo just click on the View Code link. Here is a screenshot:


To export the header which contains textblocks you can subscribe to the ElementExporting event and manually construct the value:

private void clubsGrid_ElementExporting(object sender, GridViewElementExportingEventArgs e)
{
    if (e.Element == ExportElement.HeaderCell && e.Value is StackPanel)
    {
        StackPanel sp = e.Value as StackPanel;
        string value = string.Empty;
 
        foreach (TextBlock tb in sp.Children)
        {
            value += tb.Text + " ";            
        }
 
        e.Value = value;
    }
}



Sincerely yours,
Veskoni
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
Rama
Top achievements
Rank 1
answered on 03 Aug 2010, 04:47 PM
Hi,
    The link was going to some other page, not the one that you are showing on your previous page. Here is the link that you gave me, try that:  online demo.

The example does not work. it gives error:  "Operator '&&' cannot be applied to operands of type 'bool' and 'object'"

on this line:

if(e.Element == ExportElement.HeaderCell && e.Value isStackPanel)

also give error: "Cannot implicitly convert type 'object' to 'System.Windows.Controls.StackPanel' "

on this line:

StackPanel sp = e.Value asStackPanel;
0
Veselin Vasilev
Telerik team
answered on 03 Aug 2010, 04:59 PM
Hello Rama,

The link is working for me. Can you please try in another browser?

Find attached a sample working project.


Regards,
Veskoni
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
Rama
Top achievements
Rank 1
answered on 03 Aug 2010, 05:04 PM
Hi,
    Try to open the solution file that is contained within the zip file. The project does not open in 2010. Is there a phone number that I can call you and get resolved all my telerik issues?

Thanks
0
Rama
Top achievements
Rank 1
answered on 03 Aug 2010, 05:08 PM
Hi,
    When i try to open the solution, i get the following:

One or more projects in the solution were not loaded correctly.

Then the project is empty.

Thanks,
0
Rama
Top achievements
Rank 1
answered on 03 Aug 2010, 06:12 PM
Hi,
    Please respond, this is an urgent issue:

1) When i try to open the project that you just uploaded, it errors out.

2) I want a sample of the code where i can save the exported file to an extension where excel 2007 can open without any errors.

Thanks.
0
Rama
Top achievements
Rank 1
answered on 03 Aug 2010, 07:42 PM
Hi Veskoni,
    How can I expedite this thread. I am in need of urgent help. Please respond to my last posting. Or send me an email privately where I can provide my phone number and we can speak on the phone to resolve all the telerik issues.

Thanks.
0
Veselin Vasilev
Telerik team
answered on 04 Aug 2010, 02:59 PM
Hello Rama,

We do not provide phone support. You can open a support ticket if you need a 24h response time (in business days).

What errors do you get when you open the solution I attached? It is a VS 2010 solution, so you should be able to open it without any troubles. It contains all the necessary assemblies so you should just run it.

If you still have a problem opening the solution - please try creating a blank new project and copy/paste the code from my sample.

As for your second question - is it related to this troubleshooting article:
Warning message when opening the excel file with exported data


Sincerely yours,
Veskoni
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
Rama
Top achievements
Rank 1
answered on 04 Aug 2010, 09:26 PM
Hi Veskoni,
    Here is an example code that is listed on one of your RadGridView demos at the following link: I need to use the object "HeaderBackgroundPicker" as it is used in your example. What namespace do i need to use it??????

http://demos.telerik.com/silverlight/#GridView/Exporting


using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Telerik.Windows.Controls;
using System.Net;
using System.IO;
using System.Linq;
using Telerik.Windows.Data;
using System.Windows.Media;
using System.Windows;
using System.Text;
using System.Windows.Controls;

#if !SILVERLIGHT
using Microsoft.Win32;
#endif

namespace Telerik.Windows.Examples.GridView.Exporting
{
    /// <summary>
    /// Interaction logic for Example.xaml
    /// </summary>
    public partial class Example
    {
        public Example()
        {
            InitializeComponent();
        }

        private void RadGridView1_ElementExporting(object sender, GridViewElementExportingEventArgs e)
        {
            if (e.Element == ExportElement.HeaderRow || e.Element == ExportElement.FooterRow
                || e.Element == ExportElement.GroupFooterRow)
            {
                e.Background = HeaderBackgroundPicker.SelectedColor;
                e.Foreground = HeaderForegroundPicker.SelectedColor;
                e.FontSize = 20;
                e.FontWeight = FontWeights.Bold;
            }
            else if (e.Element == ExportElement.Row)
            {
                e.Background = RowBackgroundPicker.SelectedColor;
                e.Foreground = RowForegroundPicker.SelectedColor;
            }
            else if (e.Element == ExportElement.Cell &&
                e.Value != null && e.Value.Equals("Chocolade"))
            {
                e.FontFamily = new FontFamily("Verdana");
                e.Background = Colors.LightGray;
                e.Foreground = Colors.Blue;
            }
            else if (e.Element == ExportElement.GroupHeaderRow)
            {
                e.FontFamily = new FontFamily("Verdana");
                e.Background = Colors.LightGray;
                e.Height = 30;
            }
            else if (e.Element == ExportElement.GroupHeaderCell &&
                e.Value != null && e.Value.Equals("Chocolade"))
            {
                e.Value = "MyNewValue";
            }
            else if (e.Element == ExportElement.GroupFooterCell)
            {
                GridViewDataColumn column = e.Context as GridViewDataColumn;
                QueryableCollectionViewGroup qcvGroup = e.Value as QueryableCollectionViewGroup;

                if (column != null && qcvGroup != null && column.AggregateFunctions.Count() > 0)
                {
                    e.Value = GetAggregates(qcvGroup, column);
                }
            }
        }

        private string GetAggregates(QueryableCollectionViewGroup group, GridViewDataColumn column)
        {
            List<string> aggregates = new List<string>();

            foreach (AggregateFunction f in column.AggregateFunctions)
            {
                foreach (AggregateResult r in group.AggregateResults)
                {
                    if (f.FunctionName == r.FunctionName && r.FormattedValue != null)
                    {
                        aggregates.Add(r.FormattedValue.ToString());
                    }
                }
            }

            return String.Join(",", aggregates.ToArray());
        }

        private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            string extension = "";
            ExportFormat format = ExportFormat.Html;

            RadComboBoxItem comboItem = ComboBox1.SelectedItem as RadComboBoxItem;
            string selectedItem = comboItem.Content.ToString();

   switch (selectedItem)
   {
    case "Excel": extension = "xls";
     format = ExportFormat.Html;
     break;
    case "ExcelML": extension = "xml";
     format = ExportFormat.ExcelML;
     break;
    case "Word": extension = "doc";
     format = ExportFormat.Html;
     break;
    case "Csv": extension = "csv";
     format = ExportFormat.Csv;
     break;
   }                       

            SaveFileDialog dialog = new SaveFileDialog();
   dialog.DefaultExt = extension;
   dialog.Filter = String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", extension, selectedItem);
   dialog.FilterIndex = 1;

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

                    RadGridView1.Export(stream, exportOptions);
                }
            }
        }      
    }
}

0
Vlad
Telerik team
answered on 05 Aug 2010, 06:21 AM
Hi,

 HeaderBackgroundPicker is actually RadColorPicker. You can check the example code for more info. 

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
Rama
Top achievements
Rank 1
answered on 05 Aug 2010, 02:25 PM
Hi Vlad,
     I want the exported excel columns have the same color as the Radgridview. How do i accomplish that?

Thnx.
0
Vlad
Telerik team
answered on 09 Aug 2010, 08:41 AM
Hello,

Why not use printing in this case? The grid will look exactly the same.

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
Tags
GridView
Asked by
Rama
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Rama
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or