다음 스크립트에서 .xls 파일을 .csv 파일로 변환합니다.OleDBDataReader : 하나 이상의 필수 매개 변수에 값이 지정되지 않았습니다.
Const cDelimiter As Char = "~"c 'Delimiter for the new CSV File
Const fileHasHeader As String = "YES"
Dim sSheetName As String = String.Empty
Dim sConnection As String =
String.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 12.0;HDR={1};IMEX=1""", fullPathSource, fileHasHeader)
'
Try
Using oleExcelConnection As New OleDb.OleDbConnection(sConnection)
oleExcelConnection.Open()
Using dtTablesList = oleExcelConnection.GetSchema("Tables")
If dtTablesList.Rows.Count > 0 Then
sSheetName = dtTablesList.Rows(0)("TABLE_NAME").ToString
End If
' Check if the data sheet has a worksheet(table)
If sSheetName <> "" Then
Dim oleExcelCommand As OleDb.OleDbCommand = oleExcelConnection.CreateCommand()
oleExcelCommand.CommandText = "Select * From [" & sSheetName & "]"
oleExcelCommand.CommandType = CommandType.Text
Dim oleExcelReader As OleDb.OleDbDataReader = oleExcelCommand.ExecuteReader
Dim dtCols As DataTable = oleExcelConnection.GetOleDbSchemaTable()
For Each elem In dtCols.Columns
Dim string123 As String = (elem.ToString)
Next
'Dim command As New OleDb.OleDbCommand(insertSQL)
'Date.Now.ToString().Replace(":", "-").Replace(".", "-"))
Using objStreamWriter As New IO.StreamWriter(String.Format("{0}.csv", fullPathTarget))
'Row Count not in use so far
Dim countRow As Integer = 0
Dim strToRow As String = Nothing
'Read the XLS(x) file until end
While oleExcelReader.Read()
'Empty String for next run
Dim rowString As String = ""
'Check dynamically for length of rows
For i As Integer = 0 To oleExcelReader.FieldCount - 1 Step 1
'Here would be the place tó remove any unwanted delimiters within the data
'If oleExcelReader.GetValue(i).ToString.Contains(",") Then
'End If
'Append String to write end the end of each row
rowString = rowString & oleExcelReader.GetValue(i).ToString() & cDelimiter
Next
'Write data to file
objStreamWriter.WriteLine(rowString)
countRow += countRow
End While
End Using
'End using will close all open connections
End If
End Using
'End using will close all open connections
End Using
'End using will close all open connections
을 그리고 지금은 빈 행을 제거하는 필터를 추가 할 : 이 지금까지 작동
oleExcelCommand.CommandText = "Select * From [" & sSheetName & "] WHERE [APPLICATION] <> ''"
: 그래서 나는이 선 (또한 작업) 그와
oleExcelCommand.CommandText = "Select * From [" & sSheetName & "]"
교체
및 다른 변형 (작동 중) :
oleExcelCommand.CommandText = "Select * From [" & sSheetName & "] WHERE [APPLICATION] <> '' AND [USERNAME] <> ''"
그러나이 충돌 :
oleExcelCommand.CommandText = "Select * From [" & sSheetName & "] WHERE [APPLICATION] <> '' OR [USERNAME] <> ''"
왜 내가이 whereclause에 OR을 사용할 수 없다는 것입니다. 평범한 SQL이 아닌가?
온라인에서는 예외 ("하나 이상의 필수 매개 변수가 지정되지 않았습니다")가 표시됩니다.
Dim oleExcelReader As OleDb.OleDbDataReader = oleExcelCommand.ExecuteReader
은 그냥 사용할 수 있습니까 ... [USERNAME] <> " '"'? – topshot
@topshot 예, 신호 단어 인 것 같습니다 ... 나는 이해하지 못합니다 ... – Ulpin