getcsv
This commit is contained in:
parent
0b8e18e666
commit
4e5cf05396
@ -1876,6 +1876,64 @@ errh:
|
|||||||
|
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
|
Function FILEp_GetCSV(filepath As String) As String()
|
||||||
|
|
||||||
|
Dim fileNo As Integer
|
||||||
|
Dim fileContent As String
|
||||||
|
Dim fileLines() As String
|
||||||
|
Dim dataArray() As String
|
||||||
|
Dim splitArray() As String
|
||||||
|
Dim rowCount As Long, colCount As Long
|
||||||
|
Dim i As Long, j As Long
|
||||||
|
Dim final() As String
|
||||||
|
|
||||||
|
' Get an available file number
|
||||||
|
fileNo = FreeFile
|
||||||
|
|
||||||
|
' Open the file with the available file number
|
||||||
|
Open filepath For Input As fileNo
|
||||||
|
|
||||||
|
' Read the entire file content into a single string
|
||||||
|
fileContent = Input(LOF(fileNo), fileNo)
|
||||||
|
|
||||||
|
' Close the file
|
||||||
|
Close fileNo
|
||||||
|
|
||||||
|
' Split the file content into lines
|
||||||
|
fileLines = Split(fileContent, vbCrLf)
|
||||||
|
|
||||||
|
' Get the number of rows (lines)
|
||||||
|
rowCount = UBound(fileLines) - LBound(fileLines)
|
||||||
|
|
||||||
|
' Check if there are any lines in the file
|
||||||
|
If rowCount > 0 Then
|
||||||
|
' Split the first line into columns (using comma as a delimiter)
|
||||||
|
dataArray = Split(fileLines(0), ",")
|
||||||
|
|
||||||
|
' Get the number of columns
|
||||||
|
colCount = UBound(dataArray) - LBound(dataArray)
|
||||||
|
|
||||||
|
' Redimension the dataArray to the appropriate size
|
||||||
|
ReDim dataArray(0 To rowCount, 0 To colCount)
|
||||||
|
|
||||||
|
' Loop through the lines and columns to populate the dataArray
|
||||||
|
For i = 0 To rowCount
|
||||||
|
' Split the current line into columns
|
||||||
|
splitArray = Split(fileLines(i), ",")
|
||||||
|
|
||||||
|
' Loop through the columns
|
||||||
|
For j = 0 To colCount
|
||||||
|
' Assign the values to the dataArray
|
||||||
|
dataArray(i, j) = splitArray(j)
|
||||||
|
Next j
|
||||||
|
Next i
|
||||||
|
FILEp_GetCSV = dataArray
|
||||||
|
Else
|
||||||
|
MsgBox "The file is empty or not available."
|
||||||
|
End If
|
||||||
|
|
||||||
|
End Function
|
||||||
|
|
||||||
Public Function ADOp_Exec(ByRef con As Integer, ByVal sql As String, Optional ApproxSixe As Long, Optional InclHeaders As Boolean, Optional ByVal value As ADOinterface, Optional ConnectTo As String, Optional IntgrtdSec As Boolean, Optional UserName As String, Optional Password As String, Optional textconfigs As String) As Boolean
|
Public Function ADOp_Exec(ByRef con As Integer, ByVal sql As String, Optional ApproxSixe As Long, Optional InclHeaders As Boolean, Optional ByVal value As ADOinterface, Optional ConnectTo As String, Optional IntgrtdSec As Boolean, Optional UserName As String, Optional Password As String, Optional textconfigs As String) As Boolean
|
||||||
|
|
||||||
On Error GoTo errflag
|
On Error GoTo errflag
|
||||||
|
Loading…
Reference in New Issue
Block a user