modExtenciones.ReadExcelFile valida clumnas repetidas
This commit is contained in:
@@ -177,6 +177,52 @@ Namespace Extensiones
|
|||||||
Dim dataTable As DataTable = New DataTable()
|
Dim dataTable As DataTable = New DataTable()
|
||||||
Dim worksheet As GemBox.Spreadsheet.ExcelWorksheet = excelFile.Worksheets(0)
|
Dim worksheet As GemBox.Spreadsheet.ExcelWorksheet = excelFile.Worksheets(0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
' VALIDACIÓN DE COLUMNAS DUPLICADAS
|
||||||
|
Try
|
||||||
|
If firstRowHasHeaders Then
|
||||||
|
Dim columnNames As New List(Of String)()
|
||||||
|
|
||||||
|
For col As Integer = 0 To worksheet.Rows(curRow).AllocatedCells.Count - 1
|
||||||
|
Dim cellValue As Object = worksheet.Rows(curRow).Cells(col).Value
|
||||||
|
Dim colName As String = If(cellValue Is Nothing, $"Unnamed Column {col + 1}",
|
||||||
|
cellValue.ToString())
|
||||||
|
|
||||||
|
columnNames.Add(colName)
|
||||||
|
Next
|
||||||
|
|
||||||
|
|
||||||
|
Dim duplicates As New List(Of String)()
|
||||||
|
Dim dict As New Dictionary(Of String, Integer)(StringComparer.OrdinalIgnoreCase)
|
||||||
|
|
||||||
|
For Each name In columnNames
|
||||||
|
If dict.ContainsKey(name) Then
|
||||||
|
dict(name) += 1
|
||||||
|
Else
|
||||||
|
dict(name) = 1
|
||||||
|
End If
|
||||||
|
Next
|
||||||
|
|
||||||
|
For Each kvp In dict
|
||||||
|
If kvp.Value > 1 Then
|
||||||
|
duplicates.Add(kvp.Key)
|
||||||
|
End If
|
||||||
|
Next
|
||||||
|
|
||||||
|
|
||||||
|
If duplicates.Count > 0 Then
|
||||||
|
Alert(New Object, "El archivo de Excel contiene columnas duplicadas, las columnas duplicadas son: " & String.Join(", ", duplicates), TipoMensaje.MsgAdvertencia)
|
||||||
|
Return New DataTable
|
||||||
|
End If
|
||||||
|
End If
|
||||||
|
Catch ex As Exception
|
||||||
|
|
||||||
|
End Try
|
||||||
|
' FIN DE LA VALIDACIÓN
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
For cols = 0 To worksheet.Rows(curRow).AllocatedCells.Count - 1
|
For cols = 0 To worksheet.Rows(curRow).AllocatedCells.Count - 1
|
||||||
|
|
||||||
If firstRowHasHeaders Then
|
If firstRowHasHeaders Then
|
||||||
|
|||||||
Reference in New Issue
Block a user