不是用控件,而是引用Excel对象库给你一个操作Excel的例子:Dim Excel As Excel.Application
Dim ExcelWBk As Excel.Workbook
Dim ExcelWS As Excel.WorksheetPrivate Sub StartExcel()
On Error GoTo err:
Set Excel = GetObject(, "Excel.Application")
Exit Sub
err:
Set Excel = CreateObject("Excel.Application")
End SubPrivate Sub CreateWorkSheet()
Set ExcelWBk = Excel.Workbooks.Add
Set ExcelWS = ExcelWBk.Worksheets(1)
End SubPrivate Sub PopulateWorkSheet()
Dim col As Integer
Dim row As Integer
Randomize Timer ' Random, To generate random number.....
For col = 1 To 5 ' coloumn
For row = 1 To 20 ' row
ExcelWS.Cells(row, col) = Rnd() * 100
Next row
Next colEnd SubPrivate Sub FormatWorkSheet()
ExcelWS.Range("A1:E20").NumberFormat = "0.00"
End SubPrivate Sub SaveWorkSheet()
ExcelWBk.SaveAs "c:\windows\desktop\Demo.xls"
End SubPrivate Sub CloseWorkSheet()
ExcelWBk.Close
Excel.Quit
MsgBox "You can find the saved Excel Sheet on your desktop"
End Sub
Dim ExcelWBk As Excel.Workbook
Dim ExcelWS As Excel.WorksheetPrivate Sub StartExcel()
On Error GoTo err:
Set Excel = GetObject(, "Excel.Application")
Exit Sub
err:
Set Excel = CreateObject("Excel.Application")
End SubPrivate Sub CreateWorkSheet()
Set ExcelWBk = Excel.Workbooks.Add
Set ExcelWS = ExcelWBk.Worksheets(1)
End SubPrivate Sub PopulateWorkSheet()
Dim col As Integer
Dim row As Integer
Randomize Timer ' Random, To generate random number.....
For col = 1 To 5 ' coloumn
For row = 1 To 20 ' row
ExcelWS.Cells(row, col) = Rnd() * 100
Next row
Next colEnd SubPrivate Sub FormatWorkSheet()
ExcelWS.Range("A1:E20").NumberFormat = "0.00"
End SubPrivate Sub SaveWorkSheet()
ExcelWBk.SaveAs "c:\windows\desktop\Demo.xls"
End SubPrivate Sub CloseWorkSheet()
ExcelWBk.Close
Excel.Quit
MsgBox "You can find the saved Excel Sheet on your desktop"
End Sub
解决方案 »
- 周末劲爆点再加200分
- vb中如何将外部一mdb库表数据提取到vb程序指定mdb表中
- 请问实时曲线绘制,一般用mychart组件还是用pictruebox和line语句,用那种效果更好
- 如何在sql数据库中有新数据插入时直接将记录集触发给vb!!!
- 请问这样的DateReport报表怎么做?
- 如何播放资源文件中的声音文件?
- 紧急求救:谁知道funlove是什么病毒?
- 怎样用代码在窗口中加入一个控件????
- :) 土匪老镇来散分!
- 为什么不能运行?
- 我好象中病毒了!Help me.
- 关于Win2000注册表的一个问题,为什么读出来的字符串都是"a b c d e"而不是"abcde"?我明明是设置成"abcde"的呀?
在里面可以找到excel的库