Search code examples
c#.netvisual-studio-2017gembox-spreadsheet

"ExportToDataGridView" Does not exist in .NET GemBox


Ive been trying to find why this happend but for some reason .net of gembox.spreadsheet.winformutilities wont provide ExportToDataGridView on the code:

using System.Windows.Forms;
using GemBox.Spreadsheet;
using GemBox.Spreadsheet.WinFormsUtilities;namespace Excel
{
    public partial class UserControl1 : UserControl
    {

    private void bunifuFlatButton2_Click(object sender, EventArgs e)
            {
                OpenFileDialog open = new OpenFileDialog();
                open.Filter = "Al files (*.*)|*.*|";
                open.FilterIndex = 1;

                if (open.ShowDialog()== DialogResult.OK)
                {
                    ExcelFile ef = new ExcelFile();
                    ExcelWorksheet ws = ef.Worksheets.Add("Export");

                    DataGridViewConverter.***ExportToDataGridView***(ef.Worksheets.ActiveWorksheet, this.dataGridView1, new ExportToDataGridViewOptions() { ColumnHeaders = true });
                }
            }
       }
 }

thank you for your answer in advance!


Solution

  • The problem occurred because of the name collision:

    namespace Excel
    {
        public partial class UserControl1 : UserControl
        {
            public static class DataGridViewConverter
            {
    
            }
        }
    }
    

    So there are two classes of same name:

    • Excel.UserControl1.DataGridViewConverter
    • GemBox.Spreadsheet.WinFormsUtilities.DataGridViewConverter

    The solution is to either use the class's full name, or you could define an alias name, for example:

    // ...
    using System.Windows.Forms;
    using GemBox.Spreadsheet;
    using GemBoxDataGridViewConverter = GemBox.Spreadsheet.WinFormsUtilities.DataGridViewConverter;
    
    namespace Excel
    {
        public partial class UserControl1 : UserControl
        {
            private void bunifuFlatButton2_Click(object sender, EventArgs e)
            {
                GemBoxDataGridViewConverter.ExportToDataGridView(...);
            }
        }
    }
    

    Also as an FYI, you can download a working example from GitHub or check the Windows Forms online example.