Home > Net >  Excle import database external component anomalies, how to solve for bosses to solve
Excle import database external component anomalies, how to solve for bosses to solve

Time:04-30

CodePudding user response:

Then write their own code manually import
1. Download the NPOI.
to baidu2. Read the excel to the datatable
3. The datatable write database

 
"' & lt; Summary>
"' the excel data imported into the DataTable
"' & lt;/summary>
"' & lt; Param name="sheetName & gt;" The name of the excel work thin sheet & lt;/param>
"' & lt; Param name="isFirstRowColumn & gt;" The first line is the DataTable column name & lt;/param>
"' & lt; Returns> The returned DataTable
The Public Function ExcelToDataTable (ByVal sheetName As String, ByVal isFirstRowColumn As Boolean) As DataTable
Dim sheet As ISheet=Nothing
Dim data As New DataTable ()
Dim while the startRow As Integer=0
Try
Fs=New FileStream (fileName, FileMode. Open, FileAccess. Read)
If fileName. IndexOf (". XLSX ") & gt; 0 Then
'the 2007 version
The workbook=New XSSFWorkbook (fs)
ElseIf fileName. IndexOf (". XLS ") & gt; 0 Then
'the 2003 version
The workbook=New HSSFWorkbook (fs)
End the If

If sheetName IsNot Nothing Then
Sheet=workbook. GetSheet (sheetName)
If sheet Is Nothing Then
'if you don't find the specified sheetName corresponding sheet, then try to get the first sheet
Sheet=workbook. GetSheetAt (0)
End the If
The Else
Sheet=workbook. GetSheetAt (0)
End the If
If sheet IsNot Nothing Then
Dim firstRow As IRow=sheet. GetRow (0)
Dim cellCount As Integer=firstRow. LastCellNum
'line of the last cell number is the total number of columns
If isFirstRowColumn Then
For I As Integer=firstRow. FirstCellNum To cellCount - 1
Dim As cell ICell=firstRow. GetCell (I)
If the cell IsNot Nothing Then
Dim cellValue As String=cell. StringCellValue
If cellValue IsNot Nothing Then
Dim the column As New DataColumn (cellValue)
Data. The Columns. The Add (column)
End the If
End the If
Next
While the startRow=sheet. FirstRowNum + 1
The Else
While the startRow=sheet. FirstRowNum
End the If

'the last column label
Dim the rowCount As Integer=sheet. LastRowNum
For I As Integer=while the startRow To rowCount
Dim row As IRow=sheet. GetRow (I)
If the row Is Nothing Then
The Continue For
End the If
'there is no data lines of the default is null
Dim dataRow As dataRow=data. NewRow ()
For j As Integer=row FirstCellNum To cellCount - 1
If the row. GetCell (j) IsNot Nothing Then
'in the same way, there is no data cells are the default is null
DataRow (j)=row. GetCell (j). The ToString ()
End the If
Next
Data. The Rows. The Add (dataRow)
Next
End the If

The Return data
Catch the ex As Exception
'the Console. WriteLine (" Exception: "+ ex. Message)
Return Nothing
End the Try
End the Function

CodePudding user response:

Try two methods:
1. Path don't appear in Chinese to try;
2. Import code, this can definitely,

CodePudding user response:

Recommend SpreadsheetGear excel development

CodePudding user response:

Import from within the code, please refer to what meaning be?
  • Related