这是很久以前写把EXCEL里的数据填到listview里面你自己再修改下吧 很简单的东西 Set xlApp1 = New Excel.Application xlApp1.Visible = False Set xlBook1 = xlApp1.Workbooks.Open(Me.CmDlgD.FileName) Set xlsheet1 = xlBook1.Worksheets(1) For i = 1 To Me.lvListView.ListItems.Count If Me.lvListView.ListItems.Item(i).SubItems(5) = "存在" Then xlsheet1.Cells(i, 1) = Me.lvListView.ListItems.Item(i).SubItems(1) xlsheet1.Cells(i, 2) = Me.lvListView.ListItems.Item(i).SubItems(2) xlsheet1.Cells(i, 3) = Me.lvListView.ListItems.Item(i).SubItems(3) xlsheet1.Cells(i, 4) = Me.lvListView.ListItems.Item(i).SubItems(4) xlsheet1.Cells(i, 5) = Me.lvListView.ListItems.Item(i).SubItems(5) End If Next xlBook.Close True xlBook1.SaveAs Me.CmDlgD.FileName xlApp1.Quit Set xlBook1 = Nothing Set xlsheet1 = Nothing Set xlApp1 = Nothing
我用记事本给你写了一段网页中读取Excel数据的代码,希望能给你帮忙。 <html> <head> <title>在HTML读取Excel文件</title> </head> <body id="mybody"> </body> <Script Language=VBS> Dim i,j Dim oExcel Dim oWorkBook Dim oSheet dim strHTML Set oExcel = CreateObject("Excel.Application") Set oWorkBook = oExcel.Workbooks.Open("c:\temp.xls") '此处的文件名改为实际使用的Excel文件。 Set oSheet = oWorkBook.Worksheets(1) strHTML = strHTML & "<p align=center>这是从Excel中读取的数据</p>" strHTML = strHTML & "<table border=1 align=center>" & vbcrlf For i = 1 To oSheet.UsedRange.Rows.Count strHTML = strHTML & "<tr>" & vbcrlf For j = 1 To oSheet.UsedRange.Columns.Count strHTML = strHTML & "<td width=100>" & CStr(oSheet.Cells(i,j).Value) & "</td>" & vbcrlf Next strHTML = strHTML & "</tr>" & vbcrlf Next strHTML = strHTML & "</table>" & vbcrlf mybody.innerHTML = strHTML oWorkBook.Close False oExcel.Quit Set oSheet = Nothing Set WorkBook = Nothing Set oExcel = Nothing </Script> </html>
你这是把listview里的数据填到EXCEL里面吧?
Set xlApp1 = New Excel.Application xlApp1.Visible = False Set xlBook1 = xlApp1.Workbooks.Open("文件地址\文件名") Set xlsheet1 = xlBook1.Worksheets(1) 变量=xlsheet1.Cells(1, 1) '得到1,1这个格子里的内容使用这些代码前应该从"工程"->"引用"中钩选想MicroSoft Excel ....
很简单的东西 Set xlApp1 = New Excel.Application
xlApp1.Visible = False
Set xlBook1 = xlApp1.Workbooks.Open(Me.CmDlgD.FileName)
Set xlsheet1 = xlBook1.Worksheets(1)
For i = 1 To Me.lvListView.ListItems.Count
If Me.lvListView.ListItems.Item(i).SubItems(5) = "存在" Then
xlsheet1.Cells(i, 1) = Me.lvListView.ListItems.Item(i).SubItems(1)
xlsheet1.Cells(i, 2) = Me.lvListView.ListItems.Item(i).SubItems(2)
xlsheet1.Cells(i, 3) = Me.lvListView.ListItems.Item(i).SubItems(3)
xlsheet1.Cells(i, 4) = Me.lvListView.ListItems.Item(i).SubItems(4)
xlsheet1.Cells(i, 5) = Me.lvListView.ListItems.Item(i).SubItems(5)
End If
Next
xlBook.Close True
xlBook1.SaveAs Me.CmDlgD.FileName
xlApp1.Quit
Set xlBook1 = Nothing
Set xlsheet1 = Nothing
Set xlApp1 = Nothing
<html>
<head>
<title>在HTML读取Excel文件</title>
</head>
<body id="mybody">
</body>
<Script Language=VBS>
Dim i,j
Dim oExcel
Dim oWorkBook
Dim oSheet
dim strHTML Set oExcel = CreateObject("Excel.Application")
Set oWorkBook = oExcel.Workbooks.Open("c:\temp.xls") '此处的文件名改为实际使用的Excel文件。
Set oSheet = oWorkBook.Worksheets(1) strHTML = strHTML & "<p align=center>这是从Excel中读取的数据</p>"
strHTML = strHTML & "<table border=1 align=center>" & vbcrlf
For i = 1 To oSheet.UsedRange.Rows.Count
strHTML = strHTML & "<tr>" & vbcrlf
For j = 1 To oSheet.UsedRange.Columns.Count
strHTML = strHTML & "<td width=100>" & CStr(oSheet.Cells(i,j).Value) & "</td>" & vbcrlf
Next
strHTML = strHTML & "</tr>" & vbcrlf
Next
strHTML = strHTML & "</table>" & vbcrlf mybody.innerHTML = strHTML
oWorkBook.Close False
oExcel.Quit
Set oSheet = Nothing
Set WorkBook = Nothing
Set oExcel = Nothing
</Script>
</html>
xlApp1.Visible = False
Set xlBook1 = xlApp1.Workbooks.Open("文件地址\文件名")
Set xlsheet1 = xlBook1.Worksheets(1)
变量=xlsheet1.Cells(1, 1) '得到1,1这个格子里的内容使用这些代码前应该从"工程"->"引用"中钩选想MicroSoft Excel ....
将listview中一行中的数据按列赋值给Cell(row,col)中