主题:请教各位达人,怎样将MSHFlexGrid表格中的内容写入excel表格中?
从网上下载的那个很有名的贝叶斯分类算法数据挖掘源程序,对界面作了一些修改,因为希望数据分析的结果能以excel表的格式保存起来(已经有了对所选数据),于是根据网上查到的资料,在frmWizardDataMiningResults窗体模块中加了一段代码,如下:
Private Sub mnuSaveResults_Click()
'Create a xls document to save the result
Dim xlapp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Set xlapp = CreateObject("Excel.Application")
Set xlbook = xlapp.Workbooks.Add()
Set xlsheet = xlbook.Worksheets("Sheet1")
Dim I As Integer, J As Integer
For I = 0 To MSHFlex.Rows - 1
For J = 0 To MSHFlex.Cols - 1
excel_sheet.Cells(I + 1, J + 1) = MSHFlex.TextMatrix(I, J) 'Exl里是从1开始
Next J
Next I
xlbook.SaveAs "客户数据分类结果.xls" '另存文件
xlbook.Close '关闭工作簿
Set xlbook = Nothing '从内存中清除
xlapp.Quit '关闭excel
Set xlapp = Nothing '从内存中清除
End Sub
现在看来,理解有误[em22],因为点击菜单中“工具”-〉“保存分析结果”结果是显示实时错误'424' 要求对象
那么,究竟应该怎样修改,才能使点击相应菜单功能的时候实现结果保存到excel?
Private Sub mnuSaveResults_Click()
'Create a xls document to save the result
Dim xlapp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Set xlapp = CreateObject("Excel.Application")
Set xlbook = xlapp.Workbooks.Add()
Set xlsheet = xlbook.Worksheets("Sheet1")
Dim I As Integer, J As Integer
For I = 0 To MSHFlex.Rows - 1
For J = 0 To MSHFlex.Cols - 1
excel_sheet.Cells(I + 1, J + 1) = MSHFlex.TextMatrix(I, J) 'Exl里是从1开始
Next J
Next I
xlbook.SaveAs "客户数据分类结果.xls" '另存文件
xlbook.Close '关闭工作簿
Set xlbook = Nothing '从内存中清除
xlapp.Quit '关闭excel
Set xlapp = Nothing '从内存中清除
End Sub
现在看来,理解有误[em22],因为点击菜单中“工具”-〉“保存分析结果”结果是显示实时错误'424' 要求对象
那么,究竟应该怎样修改,才能使点击相应菜单功能的时候实现结果保存到excel?