Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Tue May 17, 2022 8:59 am

When importing an excel file through the tutorial example below
If the column names are the same, an error occurs.
is there any way to solve this?


Dim workbook As Workbook = New Workbook
workbook.LoadFromFile(..\ FandH.xlsx)
Dim sheet As Worksheet = workbook.Worksheets(0)
Me.dataGridView1.DataSource = sheet.ExportDataTable

zorro012
 
Posts: 2
Joined: Mon Apr 25, 2022 12:20 pm

Tue May 17, 2022 10:33 am

Hello,

Thanks for your inquiry.

Because the ExportDataTable method needs to export the worksheet data as System.Data.DataTable. But System.Data.DataTable does not allow the existence of columns with the same name. So you got this error. This is not a problem caused by Spire.Xls.
In addition, we provide an overloaded method of ExportDataTable to set the column names not to be exported when exporting data. You can use it to avoid this error.
Hope it can help you.
Code: Select all
this.dataGrid1.DataSource = sheet.ExportDataTable(sheet.AllocatedRange,false,true);
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Return to Spire.XLS