vblistview导出数据(vb中list)

http://www.itjxue.com  2023-02-26 01:09  来源:未知  点击次数: 

vb listview 导出问题

Private Sub Command1_Click()

For i = 1 To ListView1.ListItems.Count

If Val(ListView1.ListItems(i).SubItems(1)) 10 Then

'导出到文本框中

Text1.Text = Text1.Text ListView1.ListItems(i).Text "(" ListView1.ListItems(i).SubItems(1) ")" vbCrLf

'导出到listbox中

List1.AddItem ListView1.ListItems(i).Text "(" ListView1.ListItems(i).SubItems(1) ")"

End If

Next i

End Sub

'以下是测试时用的.

Private Sub Form_Load()

ListView1.View = lvwReport

ListView1.ColumnHeaders(1).Text = "姓名"

ListView1.ColumnHeaders(2).Text = "成绩"

Dim a()

a() = Array("aaa", " 16", "bbb", "8", "ccc", "13", "ddd", "11", "zzz", " 5", "eee", "6")

For i = 0 To UBound(a) - 1 Step 2

Set lv = ListView1.ListItems.Add(, "a" CStr(i), a(i), 1)

lv.SubItems(1) = a(i + 1)

Next i

End Sub

VB中listview导出excel?

For i = 1 To Me.ListView1.ListItems.Count - 1

xl.Range("A" i + 1).Value = Me.ListView1.ListItems(i).Text

xl.Range("B" i + 1).Value = Me.ListView1.ListItems(i).SubItems(1)

xl.Range("C" i + 1).Value = Me.ListView1.ListItems(i).SubItems(2)

xl.Range("D" i + 1).Value = Me.ListView1.ListItems(i).SubItems(3)

xl.Range("E" i + 1).Value = Me.ListView1.ListItems(i).SubItems(4)

xl.Range("F" i + 1).Value = Me.ListView1.ListItems(i).SubItems(5)

xl.Range("G" i + 1).Value = Me.ListView1.ListItems(i).SubItems(6)

xl.Range("H" i + 1).Value = FormatStr(Me.ListView1.ListItems(i).SubItems(7))

Next i

xl.Visible = True

VB listview 导出到excel很慢

你可以使用数据库插入,VB用ADO连接那个空EXCEL,用sql语然插入,就很快了。

[vb.net] 怎么把listview中数据 导出保存到成excel文件

我回答你的第一个问题,因为后面的看不懂你的意思

函数:

Public Function ListViewtoExcel(ByVal LV As ListView) As Boolean

Try

If LV.Items.Count = 0 Then '判断记录数,如果没有记录就退出

MessageBox.Show("没有记录可以导出", "没有可以导出的项目", MessageBoxButtons.OK, MessageBoxIcon.Information)

Return False

End If

'如果有记录就导出到Excel

Dim AP_Excel As Object '定义Excel对象

Dim wk As Object '定义Workbook对象

AP_Excel = CreateObject("Excel.Application") '创建Excel对象

wk = AP_Excel.workbooks.add()

Dim i As Integer, u As Integer = 0, v As Integer = 0 '定义循环变量,行变量,列变量

For i = 1 To LV.Columns.Count '把表头写入Excel

wk.worksheets(1).cells(1, i) = LV.Columns(i - 1).Text.Trim

Next

Dim str(LV.Items.Count - 1, LV.Columns.Count - 1) '定义一个二维数组

For u = 0 To LV.Items.Count - 1 '行循环

For v = 0 To LV.Columns.Count - 1 '列循环

If v LV.Items(u).SubItems.Count Then '如果该行该列项存在

str(u, v) = LV.Items(u).SubItems(v).Text.Trim

Else '如果该行该列项不存在

str(u, v) = ""

End If

Next

Next

wk.worksheets(1).range("A2").Resize(LV.Items.Count, LV.Columns.Count).Value = str '把数组一起写入Excel

wk.worksheets(1).Cells.EntireColumn.AutoFit() '自动调整Excel列

' yy.worksheets(1).name = LV.TopLeftHeaderCell.Value.ToString '表标题写入作为Excel工作表名称

AP_Excel.visible = True '设置Excel可见

wk = Nothing '销毁组建释放资源

AP_Excel = Nothing '销毁组建释放资源

Return True '返回真

Catch ex As Exception '错误处理

MessageBox.Show(Err.Description.ToString, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error) '出错提示

Return False '返回假

End Try

End Function

调用函数:如 ListViewtoExcel(Me.ListView1)

(责任编辑:IT教学网)

更多

推荐PHP+MySQL视频文章