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

using ExportToExcelML to export only selected cells

5 Answers 134 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 05 May 2011, 07:16 PM
I was wondering if it is at all possible to export only the highlighted/selected cells of a grid using this function?

5 Answers, 1 is accepted

Sort by
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 06 May 2011, 08:18 AM
Hello Mark,

There is no clean way to do this, but you can do the following, set the exporter HiddenRowOption to DoNotExport, hide all other rows, export the grid, restore the hidden rows and reselect the initial selected rows.

Please take a look at the following example:
void btn_Click(object sender, EventArgs e)
{
    var selectedRows = radGridView1.SelectedRows.ToArray();
    foreach (var row in radGridView1.Rows.ToArray())
    {
        if (!row.IsSelected)
        {
            row.IsVisible = false;
        }
    }
 
    ExportToExcelML exporter = new ExportToExcelML(this.radGridView1);
    exporter.HiddenRowOption = HiddenOption.DoNotExport;
    exporter.ExportVisualSettings = true;
    string fileName = "C:\\ExportedData123.xls";
    exporter.RunExport(fileName);
 
    foreach (var row in radGridView1.Rows.ToArray())
    {
        row.IsVisible = true;
 
        if (selectedRows.Contains(row))
        {
            row.IsSelected = true;
        }
    }
}

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga

Telerik WinForms MVP
0
Mark
Top achievements
Rank 1
answered on 06 May 2011, 07:27 PM
So it is not really possible to do this by selected cells, only by rows then?
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 06 May 2011, 08:29 PM
Hello again,

You can do the same thing with the columns by hiding columns and set to not export hidden columns, to hide some columns but i don't believe that you can do it like this with cells.

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga

Telerik WinForms MVP
0
Mark
Top achievements
Rank 1
answered on 06 May 2011, 08:34 PM
Thanks for all the help.  Do you think it would be possible to do the same thing based on hiding columns and rows, based on which ones should be visible, assuming selected cells are all adjacent?
0
Martin Vasilev
Telerik team
answered on 10 May 2011, 04:34 PM
Hello Mark,
 
Like Emanuel has already pointed, the only way to export just the selected cells is to hide the other rows and columns and use the DoNotExport option. Feel free to implement your scenario hiding and bringing back to visual whichever combination of rows and columns you find appropriate for your needs.

Do not hesitate to write back if you have any other questions.

Regards,
Martin Vasilev
the Telerik team
Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
Tags
GridView
Asked by
Mark
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Mark
Top achievements
Rank 1
Martin Vasilev
Telerik team
Share this question
or