유용한함수(엑셀 파일 내용 불러들이는 함수)5
Posted by Albert 4932Day 18Hour 8Min 50Sec ago [2011-10-18]
Function ReadCsvFile(ByVal path)
Dim objFSO, oInStream, sLine, sSeg
Dim start_index, end_index, check_str, return_str
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set rowData = Server.CreateObject("Scripting.Dictionary")
'파일체크
If objFSO.FileExists( Server.MapPath( path ) ) Then
'파일오픈
Set oInStream = objFSO.OpenTextFile( Server.MapPath( path ), ForReading, False )
k = 1
Do Until oInStream.AtEndOfStream
sLine = oInStream.ReadLine
'// 콤마처리
Do while InStr(sLine, """") > 0
If InStr(sLine, """") Then
start_index = InStr(1, sLine, """")
end_index = InStr(InStr(1, sLine, """")+1, sLine, """")-InStr(1, sLine, """") + 1
check_str = Mid(sLine, start_index, end_index)
return_str = Replace(check_str, ",", ",")
return_str = Replace(return_str, """", "")
sLine = Replace(sLine, check_str, return_str)
'response.write sLine
'response.write "<br>"
End If
Loop
sSeg = Split( sLine, "," )
For y = 0 To UBound(sSeg)
sSeg(y) = Replace(sSeg(y), ",", ",")
Next
rowData.item(k) = sSeg
k = k + 1
Loop
oInStream.Close
Set oInStream = Nothing
Else
Response.Write "CVS File not found!"
End If
Set objFSO = Nothing
ReadCsvFile = rowData.items
End Function