我刚刚开始使用VB.net,在我的应用程序中,我需要在excel文件中有确切的使用行数我看了这篇文章Reading line count using vb.net我尝试了所有的答案,但我从来没有得到确切的行数,我也尝试了一些网站的其他代码,但什么也没有!有谁能帮帮我吗?
你好,实际上我使用的是SQL SERVER 2008,我试过这段代码。
Imports System.Diagnostics.Process
Imports System.IO
Imports System.Data.DataTable
Imports Microsoft.Office.Tools
Imports Excel
Imports Microsoft.Office.Interop
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim selectedFile As String = String.Empty
OpenFileDialog1.ShowDialog()
selectedFile = OpenFileDialog1.FileName
If (selectedFile IsNot Nothing) Then
ListBox1.Items.Add(selectedFile)
End If
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Dim fullPath As String
Dim fileResult As String
Dim numRow As Integer
fullPath = Path.GetFullPath(ListBox1.SelectedItem)
fileResult = Path.GetFileName(fullPath)
Dim file_count As Integer = File.ReadAllLines(fullPath).Length
MsgBox(file_count)但是再一次,计数不正确,我真的不知道为什么!
发布于 2012-09-05 19:59:54
将excel文件中的数据导入数据表,并对数据行进行统计。
Public Class Form1
Private Sub getexcelfile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim excelfile As New OpenFileDialog()
excelfile.ShowDialog()
If (excelfile.ShowDialog() = DialogResult.Cancel) Then
Return
Else
Dim file As String = excelfile.FileName
Dim str As String = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + file + ";Extended Properties=Excel 8.0;"
Dim con As New OleDb.OleDbConnection(str)
con.Open()
Dim ds As New OleDb.OleDbDataAdapter("Select * from [Sheet1$]", con)
Dim dt As New DataTable()
ds.Fill(dt)
Dim rowcount As Integer
rowcount = dt.Rows.Count()
End If
End Sub
End Classhttps://stackoverflow.com/questions/12280007
复制相似问题