0

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!

  • Just in case, try using the full name for "DataGridViewConverter". In other words, try "GemBox.Spreadsheet.WinFormsUtilities.DataGridViewConverter.ExportToDataGridView(...". If problem remains, would it be possible for you to upload somewhere your project so that I can take a look at this and help you out with it? – Mario Z Feb 05 '18 at 05:25
  • I have tried your fix but it didnt work im sorry so here is the link for the project.. thx link: https://drive.google.com/drive/folders/10txvSRwBaMTbxeUwZk1YS3tMVgS9AlDu?usp=sharing – Chun Chun Maru Feb 05 '18 at 10:48
  • wait are you the one who replied my email from gembox customer care? – Chun Chun Maru Feb 05 '18 at 11:18
  • thanks m8 for answering my problem XD – Chun Chun Maru Feb 05 '18 at 14:20

1 Answers1

0

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.

Mario Z
  • 4,328
  • 2
  • 24
  • 38