标题:MSFlexGrid如何用textbox输入数据?如何用commanddialog导入Excel数据和保存 ...
取消只看楼主
lllloo
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2017-4-14
结帖率:0
已结贴  问题点数:20 回复次数:1 
MSFlexGrid如何用textbox输入数据?如何用commanddialog导入Excel数据和保存数据在电脑上
MSFlexGrid如何用textbox输入数据?如何用commanddialog导入Excel数据和保存数据在电脑上?
求助各位大神老师们
而且一个页面上有三个MSFlexGrid,能不能一次导入数据,还是要一个一个导入?
搜索更多相关主题的帖子: Excel 如何 而且 
2017-04-15 13:43
lllloo
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2017-4-14
得分:0 
回复 2楼 ZHRXJR
能不能帮我看一下这下边的代码问题出在哪里 ,导入不了数据 说是Set exlapp = CreateObject("excel.application")这一句有问题  谢谢大神
Private Sub Command2_Click()
CommonDialog1.DialogTitle = "载入调出点数据"
CommonDialog1.Filter = "Excel 文件(*.xls)|*.xls"
CommonDialog1.CancelError = False
CommonDialog1.ShowOpen

With MSFlexGrid1

Dim rw, cl As Integer
Dim exlapp As Object
Set exlapp = CreateObject("excel.application")

On Error GoTo 100

If Dir(Parh + CommonDialog1.FileName) <> "" Then
exlapp.Workbooks.Open (CommonDialog1.FileName)

MSFlexGrid1.Rows = exlapp.Sheets(1).UsedRange.Rows.Count
MSFlexGrid1.Cols = exlapp.Sheets(1).UsedRange.Columns.Count

For rw = 1 To MSFlexGrid1.Rows - 1
MSFlexGrid1.TextMatrix(rw, 0) = rw - 1
MSFlexGrid1.RowHeight(rw) = 350
Next rw
MSFlexGrid1.RowHeight(0) = 350
MSFlexGrid1.ColAlignment(0) = 4
For cl = 1 To MSFlexGrid1.Cols - 1
MSFlexGrid1.TextMatrix(0, cl) = "调出点" & cl
MSFlexGrid1.ColWidth(cl) = 1300
MSFlexGrid1.ColAlignment(cl) = 4
Next cl
MSFlexGrid1.ColWidth(0) = 1300

For rw = 1 To MSFlexGrid1.Rows - 1
For cl = 1 To MSFlexGrid1.Cols - 1
MSFlexGrid1.TextMatrix(rw, cl) = exlapp.Sheets(1).Cells(rw + 1, cl + 1)
Next cl
Next rw
exlapp.Quit
Text1.Left = MSFlexGrid1.Left + MSFlexGrid1.ColPos(1) + 50
Text1.Top = MSFlexGrid1.Top + MSFlexGrid1.RowPos(1) + 50
Text1 = MSFlexGrid1.TextMatrix(1, 1)
Text1.SetFocus
Exit Sub

ElseIf Dir(Path + CommonDialog1.FileName) = "" Then
MsgBox "请确认文件是否存在!", 0 + 48, "文件错误"
Exit Sub
End If

100:
If Err.Number <> 32755 Then
MsgBox "数据载入已取消!", 48, "警告"
End If
End With
End Sub
2017-04-16 14:38



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-476141-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.195865 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved