create excel application instance . and open excel file . example: xlsApp as Excel.Application xlsWorkBook as Excel.WorkBook
xlxWorkBook=xlsApp.Open("ddd.xls") and read data from it . read help in msdn , you can found something . or read vba help of excel . u will know that .good luck
感谢您使用微软产品。
您可以通过以下途径把数据库中的数据倒入Excel。 1.把记录集中的数据填入Excel表的范围 2.把对ODBC或OLEDB查询到的数据作为一个Excel worksheet您可以参考下面链接中的方法中的例子。 Q295646 HOWTO: Transfer Data from ADO Data Source to Excel with ADO http://support.microsoft.com/support/kb/articles/q295/6/46.aspQ247412 INFO: Methods for Transferring Data to Excel from Visual Basic http://support.microsoft.com/support/kb/articles/q247/4/12.asp 然后,您可以使用Microsoft Excel 10.0 Object Library中的类和对象用EXCEL制做报表或图表。 如下例在用户按button时用EXCEL制做图表并旋转: Private Sub Command1_Click() SendMessage Combo1.hwnd, CB_SHOWDROPDOWN, 1, 0 Dim ExcelApp As Object Dim ExcelChart As Object Dim ChartTypeVal As Integer Dim i As Integer
'-4100 is the value for the MS Excel constant xl3DColumn. Visual 'Basic does not understand MS Excel constants, so the value must be 'used instead. ChartTypeVal = -4100
'Creates OLE object to MS Excel ' the registered OLE application name for MS Excel version 97 is ' excel.application.8 Set ExcelApp = CreateObject("excel.application")
'Sending VB Applications Edition commands to MS Excel via the new OLE 'object to create a new workbook fill in numbers, create the chart, and 'rotate the chart. ExcelApp.Visible = True ExcelApp.Workbooks.Add ExcelApp.Range("a1").Value = 3 ExcelApp.Range("a2").Value = 2 ExcelApp.Range("a3").Value = 1 ExcelApp.Range("a1:a3").Select Set ExcelChart = ExcelApp.Charts.Add() ExcelChart.Type = ChartTypeVal For i = 30 To 180 Step 10 ExcelChart.Rotation = i Next End Sub
详细信息请参考以下链接: HOWTO: VB3: Create Excel Chart with OLE Automation from VB http://support.microsoft.com/support/kb/articles/q112/4/17.asp
SAMPLE: XLCLIENT: Automation Client for Excel http://support.microsoft.com/support/kb/articles/q141/7/59.asp
HOWTO: VB3: Dynamically Create Excel 5 Charts in OLE 2 Control http://support.microsoft.com/support/kb/articles/q114/2/63.asp
xlsWorkBook as Excel.WorkBook
xlxWorkBook=xlsApp.Open("ddd.xls")
and read data from it . read help in msdn , you can found something . or read vba help of excel . u will know that .good luck
您可以通过以下途径把数据库中的数据倒入Excel。
1.把记录集中的数据填入Excel表的范围
2.把对ODBC或OLEDB查询到的数据作为一个Excel worksheet您可以参考下面链接中的方法中的例子。
Q295646 HOWTO: Transfer Data from ADO Data Source to Excel with ADO
http://support.microsoft.com/support/kb/articles/q295/6/46.aspQ247412 INFO: Methods for Transferring Data to Excel from Visual Basic
http://support.microsoft.com/support/kb/articles/q247/4/12.asp
然后,您可以使用Microsoft Excel 10.0 Object Library中的类和对象用EXCEL制做报表或图表。
如下例在用户按button时用EXCEL制做图表并旋转:
Private Sub Command1_Click()
SendMessage Combo1.hwnd, CB_SHOWDROPDOWN, 1, 0
Dim ExcelApp As Object
Dim ExcelChart As Object
Dim ChartTypeVal As Integer
Dim i As Integer
'-4100 is the value for the MS Excel constant xl3DColumn. Visual
'Basic does not understand MS Excel constants, so the value must be
'used instead.
ChartTypeVal = -4100
'Creates OLE object to MS Excel
' the registered OLE application name for MS Excel version 97 is
' excel.application.8
Set ExcelApp = CreateObject("excel.application")
'Sending VB Applications Edition commands to MS Excel via the new OLE
'object to create a new workbook fill in numbers, create the chart, and
'rotate the chart.
ExcelApp.Visible = True
ExcelApp.Workbooks.Add
ExcelApp.Range("a1").Value = 3
ExcelApp.Range("a2").Value = 2
ExcelApp.Range("a3").Value = 1
ExcelApp.Range("a1:a3").Select
Set ExcelChart = ExcelApp.Charts.Add()
ExcelChart.Type = ChartTypeVal
For i = 30 To 180 Step 10
ExcelChart.Rotation = i
Next
End Sub
详细信息请参考以下链接:
HOWTO: VB3: Create Excel Chart with OLE Automation from VB
http://support.microsoft.com/support/kb/articles/q112/4/17.asp
SAMPLE: XLCLIENT: Automation Client for Excel
http://support.microsoft.com/support/kb/articles/q141/7/59.asp
HOWTO: VB3: Dynamically Create Excel 5 Charts in OLE 2 Control
http://support.microsoft.com/support/kb/articles/q114/2/63.asp
- 微软全球技术中心 VB技术支持
本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款
(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
为了为您创建更好的讨论环境,请参加我们的用户满意度调查
(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。
======================