I wanted to export only one colum into datagridview
My code is here:
OpenFileDialog fdlg = new OpenFileDialog();
fdlg.Title = "select Excel file";
fdlg.Filter = "Excel files | *.xls";
fdlg.FilterIndex = 2;
fdlg.RestoreDirectory = true;
if (fdlg.ShowDialog() == DialogResult.OK)
{
string filename = fdlg.FileName;
XLS.Application myapp = new XLS.Application();
XLS.Workbook wb = myapp.Workbooks.Open(filename);
XLS.Worksheet sheet = (XLS.Worksheet)wb.Worksheets.get_Item(1);
I am getting problem here
Thanks
Darma
Thanks
Darma
Sharon WhitePosted Nov 22, 2012, 10:58 PM
I use a .NET Excel component to export one column to DataGridView.
Here is my code. Maybe it can give you some suggestions.
Workbook workbook = new Workbook();
workbook.LoadFromFile(@"D:\Documents\TestSample.xlsx");
Worksheet sheet = workbook.Worksheets[0];
//Export First column to DataGridView
this.dataGridView1.DataSource = sheet.ExportDataTable(1,1,12,1,false);
//sheet.ExportDataTable(int FirstRow,int FirstColumn,int MaxRow, int MaxColumn, bool Export ColumnNames)