0

我一直试图找出为什么会发生这种情况,但由于某种原因,gembox.spreadsheet.winformutilities 的 .net 不会在代码上提供 ExportToDataGridView:

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 });
                }
            }
       }
 }

提前感谢您的回答!

4

1 回答 1

0

由于名称冲突而出现问题:

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

        }
    }
}

所以有两个同名的类:

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

解决方案是使用类的全名,或者您可以定义别名,例如:

// ...
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(...);
        }
    }
}

另外作为仅供参考,您可以从GitHub下载工作示例或查看Windows 表单在线示例。

于 2018-02-05T11:30:29.930 回答