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

ExportToExcelML Problem Q2 2010

8 Answers 192 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Thomas
Top achievements
Rank 1
Thomas asked on 20 Jul 2010, 11:37 AM
Hello,

RunExport throws now this Exception: "Cannot find any base cell element!".

My Code:

ExportToExcelML exporter = new ExportToExcelML(gridview);
            exporter.HiddenColumnOption = HiddenOption.DoNotExport;
            exporter.ExportVisualSettings = true;
            exporter.SummariesExportOption = SummariesOption.ExportOnlyBottom;
            exporter.HiddenRowOption = HiddenOption.DoNotExport;
            exporter.SheetName = "Export";

            string filename = Path.Combine(Path.GetTempPath(), "excel_export.xls");

            try
            {
                exporter.RunExport(filename);
                return filename;
            }
            catch (Exception e)
            {
                return string.Empty;
            }

I have no idea what i have to change.

Regards,
Thomas

8 Answers, 1 is accepted

Sort by
0
Martin Vasilev
Telerik team
answered on 22 Jul 2010, 01:58 PM
Hi Thomas,

Thank you for writing.

Actually, this is a know issue with Q2 2010 release. Most probably you have some conditional formatting applied to the RadGridView and a bug with determining the base cell element leads to the described exception. Unfortunately, there is not a suitable work-around for this situation except removing the conditional formatting. The good news is that we have already fixed this and this issue will not be presented in the upcoming service pack.

Please, excuse us for the caused inconvenience. Let me know if you have any additional questions.

Regards,
Martin Vasilev
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
Thomas
Top achievements
Rank 1
answered on 22 Jul 2010, 02:04 PM
My implementation doesnt use ConditionalFormatting.

It is a derived RadGridView with TextBox- and DecimalColumns with bounded data. Also i am using CellFormatting, CellPaint and the new Style object.

Regards,
Thomas
0
Bernd Mueller
Top achievements
Rank 1
answered on 23 Jul 2010, 02:39 PM
Hello everyone,

this error message also comes up when i modify the back color of a cell element.
The strange thing is that it is only a problem with the backcolor of a cell in the non odd row.
@Telerik-Team: Please try this code and you will get the error when doing the excel export:

Private Sub RadGrid1CellFormatting(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles RadGrid1.CellFormatting
            If e.CellElement.RowElement.IsOdd Then
                ' no problem
                e.CellElement.BackColor = Color.White
            Else
                ' export not working when changing back color
                e.CellElement.BackColor = Color.White
            End If
End Sub
0
Martin Vasilev
Telerik team
answered on 26 Jul 2010, 05:27 PM
Hi guys,

Thank you for your feedback.

Actually the reason for the exception is the same for the quoted scenarios as when there is a Conditional Formatting applied. We believe that we have already addressed that and the fix will be available in the upcoming service pack release.

Once again, please excuse us for the inconvenience. 

Regards,
Martin Vasilev
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
Thomas
Top achievements
Rank 1
answered on 09 Aug 2010, 12:21 PM
Hello,

when is the release planned?
0
Martin Vasilev
Telerik team
answered on 12 Aug 2010, 10:15 AM
Hi Thomas,

The Q2 2010 Service Pack 1 is already released. Please download it and let me know whether you experience any issues.

Kind regards,
Martin Vasilev
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
codicezerouno
Top achievements
Rank 1
answered on 28 Sep 2010, 11:09 AM
Hi,

I think I'm figuring out a similar problem:
I'm formatting a gridview by using CellFormatting event; then I need to export grid to excel but cell colors are not exported.

I tried this workaround by using event ExcelCellFormatting of the exporter:

void xlsExporter_ExcelCellFormatting(object sender, Telerik.WinControls.UI.Export.ExcelML.ExcelCellFormattingEventArgs e)
        {
            if (e.GridRowInfoType == typeof(Telerik.WinControls.UI.GridViewDataRowInfo))
            {
                //e.CancelConditionalFormatting = true;
                var gridCellElement = dataGrid.TableElement.GetCellElement(dataGrid.Rows[e.GridRowIndex], dataGrid.Columns[e.GridColumnIndex]);
                if (gridCellElement != null)
                    e.ExcelStyleElement.InteriorStyle.Color = gridCellElement.BackColor;
            }
        }

Now I get cell colors exported but only if the entire grid is visible.

Where am I wrong? Could you help to solve this problem?

Thanks in advance. Stefano.
0
Martin Vasilev
Telerik team
answered on 01 Oct 2010, 01:03 PM
Hello Stefano Cadò,

Thank you for writing.

You have experienced the described issue because of the grid virtualization. If the cell is not visible, its cell element is not created and GetCellElement returns null. You can get the virtualized cell element as shown below:
public static GridCellElement GetCellElement(RadGridView gridInstance, int rowIndex, int colIndex)
        {
            GridCellElement cellElement =
                gridInstance.TableElement.GetCellElement(gridInstance.Rows[rowIndex], gridInstance.Columns[colIndex]);
  
            if (cellElement == null)
            {
                GridTableElement tableElement = gridInstance.TableElement;
                RowElementProvider rowProvider = tableElement.RowScroller.ElementProvider as RowElementProvider;
                CellElementProvider cellProvider = tableElement.ColumnScroller.ElementProvider as CellElementProvider;
  
                GridDataRowElement gridRowElement = rowProvider.GetElement(gridInstance.Rows[rowIndex], null) as GridDataRowElement;
                gridRowElement.InitializeRowView(tableElement);
                gridRowElement.Initialize(gridInstance.Rows[rowIndex]);
                gridRowElement.SuspendLayout();
  
                GridVirtualizedCellElement virtualizedCellElement =
                            cellProvider.GetElement(gridInstance.Columns[colIndex], gridRowElement) as GridVirtualizedCellElement;
                gridRowElement.Children.Add(virtualizedCellElement);
                virtualizedCellElement.Attach(gridInstance.Columns[colIndex], gridRowElement);
                virtualizedCellElement.SetContent();
  
                cellElement = virtualizedCellElement;
  
                gridRowElement.ResumeLayout(false);
            }
  
            if (cellElement == null)
            {
                throw new Exception("Cannot get cell element");
            }
  
            return cellElement;
        }

I hope this helps. Let me know if you have any other questions.

Kind regards,
Martin Vasilev
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
Thomas
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
Thomas
Top achievements
Rank 1
Bernd Mueller
Top achievements
Rank 1
codicezerouno
Top achievements
Rank 1
Share this question
or