Merge ReadCSVFileWithUtf8 into ReadCSVFile with charset parameter

This commit is contained in:
updsv7
2026-04-13 19:02:04 +09:00
parent c482518135
commit 35bdc1479b
2 changed files with 23 additions and 1 deletions

View File

@@ -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

View File

@@ -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