关于数据MSFlexgrid控件中的数据导出到Excel问题。

战箫 程序员  2004-03-17 08:45:06
我在我的xp系统上做了一个与数据库连接的程序,其中数据放在了一个MSFlexGrid控件中,然后我导出到Excel文件中,很正常。但安装到了别人的一台win98系统中时,无法导出到Excel,提示说“自动化失败”,他的win98系统只安装了系统,VB6环境和Office2000,没有安装其他的。我想是不是少安装什么东西了,哪位兄弟帮助解决此问题?
...全文
28 点赞 收藏 5
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
daisy8675 2004-03-18
問題在於98 和2K,Xp很多東西不相同,缺少庫文件情況都有,如果用Application可能會缺少叫什麼來著,忘了
你打包以後,直接copy過去看是否能運行。要麼就去下庫
回复
战箫 2004-03-17
但是两台电脑安装的都是office2000版本的。在VB中引用的也都是excel 9.0的啊。
回复
华芸智森 2004-03-17
你用第二种方法.
也许对方电脑安装的EXCEL版本与你的不一样.
第二种方法对方根本就不需要安装EXCEL.
它只是导出一种TAB分格符的文本文件.在各种版本的EXCEL下都能打开.
回复
战箫 2004-03-17
楼上仁兄,我说的是我的程序在我的电脑中好使,在别人的电脑中不好使,并不是程序本身的问题啊。我如果能让在别人的电脑中也好使?
回复
华芸智森 2004-03-17

下面是我程序中的两个模块...参考一下.

1.标准的导出方法.

Sub ExcelFull(OFile As String) '导出为EXCEL
Dim i As Long
Dim J As Long
Dim XlApp As Object
Dim XlBook As Object
Dim XlSheet As Object
Dim TmpStr As String
Dim RowMax As Long
Dim ColMax As Long

On Error Resume Next
Set XlApp = CreateObject("Excel.Application")
If XlApp Is Nothing Then
MsgBox "系统没有安装Excel!", vbOKOnly + 16, "成绩统计"
Exit Sub
End If
Screen.MousePointer = 11
XlApp.Visible = False
RowMax = MainFrm.MainGrid.Rows
ColMax = MainFrm.MainGrid.Cols
FullBar.Max = MaxVal + 1
FullBar.Value = 0
NewVal = 0: OleVal = 0
FullBar.Visible = True
DoEvents
With XlApp
Set XlBook = XlApp.Workbooks.Add
Set XlSheet = XlBook.Worksheets(1)
.Sheets(1).Name = "成绩表"
For i = 5 To RowMax - 1
For J = 1 To ColMax - 1
TmpStr = MainFrm.MainGrid.TextMatrix(i, J)
If i = 5 Then
If J > 4 And J < ColMax - 3 And J Mod 2 = 0 Then TmpStr = "名次"
End If
XlSheet.Cells(i - 4, J) = TmpStr
Next J
NewVal = i * MaxVal \ RowMax
If OleVal <> NewVal Then
FullBar.Value = NewVal
OleVal = NewVal
End If
Next i
FullBar.Value = FullBar.Max
XlBook.SaveAs OFile
XlBook.FileClose
XlBook.Close SaveChanges:=False
.quit
Set XlSheet = Nothing
Set XlBook = Nothing
Set XlApp = Nothing
Screen.MousePointer = 0
End With
End Sub

2.最快速的导出方法,可以不安装EXCEL.

Sub RtfTextFull(FileName As String)
Dim MaxRows As Long
Dim MaxCols As Long
Dim StarRow As Long
Dim ConTents As String
Dim LoopI As Long
Dim EndRow As Long
Dim TmpStr As String
Dim Tmp As String
Dim a As Long
Dim FileID As Long

With MainFrm.MainGrid
FileID = FreeFile()
MaxRows = .Rows - 1: MaxCols = .Cols - 1
FullBar.Max = MaxVal + 1
FullBar.Value = 0: FullBar.Visible = True
NewVal = 0: OleVal = 0
FullBar.Visible = True
DoEvents
TmpStr = .TextMatrix(5, 0)
For a = 1 To MaxCols
Tmp = .TextMatrix(5, a)
If a > 4 And a < MaxCols - 2 And a Mod 2 = 0 Then Tmp = "名次"
TmpStr = TmpStr & vbTab & Tmp
Next a
'---------------------------------------------------------
Open FileName For Output As #FileID
Print #FileID, TmpStr
For a = 6 To MaxRows
.Row = a: .Col = 0
.RowSel = a: .ColSel = MaxCols
ConTents = .Clip
Print #FileID, ConTents
NewVal = a * MaxVal \ MaxRows
If OleVal <> NewVal Then
FullBar.Value = NewVal
OleVal = NewVal
End If
Next a
Close #FileID
.Row = 6: .Col = 1
End With
End Sub


回复
相关推荐
发帖

1187

社区成员

VB 数据库(包含打印,安装,报表)
申请成为版主
帖子事件
创建了帖子
2004-03-17 08:45
社区公告
暂无公告