Merge ReadCSVFileWithUtf8 into ReadCSVFile with charset parameter
This commit is contained in:
@@ -151,3 +151,25 @@ Function ReadCSVFileWithUtf8(ByVal filePath As String) As Variant
|
||||
|
||||
ReadCSVFileWithUtf8 = Split(textContent, vbLf)
|
||||
End Function
|
||||
|
||||
Function ReadCSVFile(ByVal filePath As String, Optional ByVal charset As String = "shift_jis") As Variant
|
||||
If filePath = "" Then
|
||||
ReadCSVFile = Array()
|
||||
Exit Function
|
||||
End If
|
||||
|
||||
Dim stream As Object
|
||||
Dim textContent As String
|
||||
|
||||
Set stream = CreateObject("ADODB.Stream")
|
||||
With stream
|
||||
.Type = 2
|
||||
.Charset = charset
|
||||
.Open
|
||||
.LoadFromFile filePath
|
||||
textContent = .ReadText
|
||||
.Close
|
||||
End With
|
||||
|
||||
ReadCSVFile = Split(textContent, vbLf)
|
||||
End Function
|
||||
|
||||
@@ -19,7 +19,7 @@ Sub Z1_ImportMasterDetailData()
|
||||
If filePath = "" Then Exit Sub
|
||||
|
||||
' Step 2: Read CSV
|
||||
lines = ReadCSVFileWithUtf8(filePath)
|
||||
lines = ReadCSVFile(filePath, "utf-8")
|
||||
|
||||
' Step 3: Validate column count
|
||||
If Not ValidateCSVColumnCount(lines, 7) Then Exit Sub
|
||||
|
||||
Reference in New Issue
Block a user