怎么快速得到csv文件的行数?
Open SystemSet.PlaneXL.Text For Input As #1
Line Input #1, strFile
SystemSet.Progress.Min = 0
SystemSet.Progress.Max = UBound(Split(Input$(LOF(1), 1), vbCrLf))
Private Sub Command1_Click()
Dim bytFile() As Byte, strFile As String, strTmp As String
Dim n As Long
Open "D:\Program Files\Microsoft Visual Studio\VC98\Lib\WIN32API.CSV" For Binary As #1
ReDim bytFile(LOF(1) - 1)
Get #1, , bytFile
Close #1
strFile = StrConv(bytFile, vbUnicode)
strTmp = Replace(strFile, vbCrLf, "")
n = (LenB(strFile) - LenB(strTmp)) / 2 + 1
MsgBox n
End Sub
Option Explicit
Private Sub Command1_Click()
Dim FileNumber As Long, Filebyte() As Byte, Arr() As String
FileNumber = FreeFile
Open "D:\GreenSoft\easyMule\config\ip-to-country.csv" For Binary As #FileNumber '打开CSV文件
ReDim Filebyte(1 To LOF(FileNumber))
Get #FileNumber, , Filebyte
Arr = Split(StrConv(Filebyte, vbUnicode), vbCrLf)
Debug.Print UBound(Arr) '取得数据行数
Close #FileNumber
End Sub
'引用对象库:Microsoft Excel 11.0 Object Library
Option Explicit
Private Sub Command1_Click()
On Error GoTo Errhandler
Dim xlExcel As New Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
xlExcel.Application.Visible = False
xlExcel.Workbooks.Open "D:\GreenSoft\easyMule\config\ip-to-country.csv" '打开CSV文件
xlExcel.Workbooks(1).Activate
Set xlSheet = xlExcel.Workbooks(1).Worksheets(1) 'Sheet1表
xlSheet.Activate '激活Sheet1表
Debug.Print xlExcel.ActiveSheet.UsedRange.Rows.Count '取有效数据行数
xlBook.Close
xlExcel.Quit
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlExcel = Nothing
Errhandler:
Exit Sub
End Sub