阳台储物架图片大全:vb MSFlexGrid导出到excel
来源:百度文库 编辑:中财网 时间:2024/05/05 15:24:49
Private Sub ToExcel() '本函数用于导出商家列表信息
On Error GoTo ddd
If Trim(Text1.Text) = "" Then
Exit Sub
End If
If Right(Trim(Text1.Text), 4) <> ".xls" Then
Label1.Caption = "非法的目标文件名。"
Exit Sub
End If
If Dir(Trim(Text1.Text)) <> "" Then
MsgBox "设定的目标文件 Excel 文件已经存在,不得使用已经存在的文件的文件名。", vbInformation
Label9.Caption = "准备就绪。"
Exit Sub
End If
Label1.Caption = "正在初始化 Excel 后台工作环境。"
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set xlApp = CreateObject("Excel.Application") '创建EXCEL对象
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
xlSheet.Cells(1, 1) = "写入数据的程序的版本号:"
xlSheet.Cells(1, 2) = App.Major & "." & App.Minor & "." & App.Revision & "。 本软件更新速度较快,请及时更新最新版本。"
xlSheet.Cells(2, 1) = "导出的内容:"
xlSheet.Cells(2, 2) = "商家列表"
xlSheet.Cells(3, 1) = "数据的查询条件:"
' xlSheet.Cells(3, 2) = Label7.Caption
xlSheet.Cells(4, 1) = "导出时间:"
xlSheet.Cells(4, 2) = Now()
xlSheet.Cells(5, 1) = "导出的资料条数:"
'xlSheet.Cells(5, 2) = Label6.Caption
xlSheet.Cells.EntireColumn.AutoFit '自动调整列宽
Set xlSheet = xlBook.Worksheets(2)
Dim i As Long
Dim t As Long
t = Form2.MSFlexGrid1.Cols
Dim d As Long
d = Form2.MSFlexGrid1.Rows
Dim f As Long
For f = 1 To d
For i = 1 To t
xlSheet.Cells(f, i) = Form2.MSFlexGrid1.TextMatrix(f - 1, i - 1)
DoEvents
Next i
DoEvents
Next f
xlSheet.Cells.EntireColumn.AutoFit '自动调整列宽
Label1.Caption = "数据写入完毕,正在保存文件!"
xlApp.ActiveWorkbook.SaveAs Trim(Text1.Text)
xlBook.Close (True) '关闭工作簿
xlApp.Quit '结束EXCEL对象Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing '释放xlApp对象
Exit Sub
ddd:
Label1.Caption = "错误代码:" & Err.Number & "," & Err.Description
End Sub
On Error GoTo ddd
If Trim(Text1.Text) = "" Then
Exit Sub
End If
If Right(Trim(Text1.Text), 4) <> ".xls" Then
Label1.Caption = "非法的目标文件名。"
Exit Sub
End If
If Dir(Trim(Text1.Text)) <> "" Then
MsgBox "设定的目标文件 Excel 文件已经存在,不得使用已经存在的文件的文件名。", vbInformation
Label9.Caption = "准备就绪。"
Exit Sub
End If
Label1.Caption = "正在初始化 Excel 后台工作环境。"
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set xlApp = CreateObject("Excel.Application") '创建EXCEL对象
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
xlSheet.Cells(1, 1) = "写入数据的程序的版本号:"
xlSheet.Cells(1, 2) = App.Major & "." & App.Minor & "." & App.Revision & "。 本软件更新速度较快,请及时更新最新版本。"
xlSheet.Cells(2, 1) = "导出的内容:"
xlSheet.Cells(2, 2) = "商家列表"
xlSheet.Cells(3, 1) = "数据的查询条件:"
' xlSheet.Cells(3, 2) = Label7.Caption
xlSheet.Cells(4, 1) = "导出时间:"
xlSheet.Cells(4, 2) = Now()
xlSheet.Cells(5, 1) = "导出的资料条数:"
'xlSheet.Cells(5, 2) = Label6.Caption
xlSheet.Cells.EntireColumn.AutoFit '自动调整列宽
Set xlSheet = xlBook.Worksheets(2)
Dim i As Long
Dim t As Long
t = Form2.MSFlexGrid1.Cols
Dim d As Long
d = Form2.MSFlexGrid1.Rows
Dim f As Long
For f = 1 To d
For i = 1 To t
xlSheet.Cells(f, i) = Form2.MSFlexGrid1.TextMatrix(f - 1, i - 1)
DoEvents
Next i
DoEvents
Next f
xlSheet.Cells.EntireColumn.AutoFit '自动调整列宽
Label1.Caption = "数据写入完毕,正在保存文件!"
xlApp.ActiveWorkbook.SaveAs Trim(Text1.Text)
xlBook.Close (True) '关闭工作簿
xlApp.Quit '结束EXCEL对象Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing '释放xlApp对象
Exit Sub
ddd:
Label1.Caption = "错误代码:" & Err.Number & "," & Err.Description
End Sub
VB-MSFlexGrid数据如何导入到DataReport中打印
vb MSFlexGrid控件
VB中msflexgrid控件问题
关于VB的MSFlexGrid控件
关于VB导出到excel文件
关于VB中的MSFlexGrid控件的属性
VB,MSFlexGrid 控件,如何快速清空?
如何在VB里面实现导出ACCESS到EXCEL
VB中,把一个MSFlexGrid的样式copy给另一个MSFlexGrid
急问:vb中MSHFlexGrid与MSFlexGrid的区别
vb编程 MSFlexGrid 控件的几个小问题
vb如何导出应用程序
VB里DataGird导出Excel
vb如何将文本框中信息导出到.xml中去
在vb中如何使 MSFlexGrid内可以输入内容?谢谢!
请问VB中的DBCombo,DBList,DBGrid,MSFlexGrid控件都在哪里啊
VB问题:msflexgrid控件中如果实现listbox效果选择多行呢
vb 中的msflexgrid 怎样合并列? 我很想知道代码。谢谢大哥大姐了!!
VB问题:MSFlexGrid控件笔数增加一定数据就溢出
vb中有什么和MSFLEXGRID相似但是功能却强一些的控件吗?
谁知道VB里面MSFlexGrid控件的哪个属性是返回所选中单元格的行数的
VB里DataGird控件中的数据导出到Excel文件详细的代码以及所用到的控件,部件
VB.NET怎样实现导入导出文本文件
VB的数据保存和导出!