救命了,大家来帮我啊

small_pig 2002-12-09 01:27:47
我在开发一个mis项目,目前就差报表了,由于格式问题打算先做好几个excel的模版
然后用程序调用模版,并向模版中输入数据,在如何调用已做好的模版,和向里边输入数据阿????????????????
...全文
46 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
mouseanAnya 2002-12-09
  • 打赏
  • 举报
回复
一段参考程序:
Option Explicit
Dim EXCAPP As Object '定义一个EXCEL对象

Private Sub CmdCancel_Click()
Unload Me
End
End Sub

Private Sub CmdOutToExcel_Click()
On Error Resume Next
Dim fs
Dim deffile As String, Hfile As String, sfilename As String


Set fs = CreateObject("Scripting.FileSystemObject")
deffile = App.Path & "\abc.xls" '模板文件名称
CommonDialog1.Filter = "*.xls|*.xls"
CommonDialog1.ShowSave
If CommonDialog1.FileName <> "" Then
sfilename = CommonDialog1.FileName
Hfile = Dir(sfilename)
If Hfile = "" Then
fs.CopyFile deffile, sfilename
Else
If MsgBox("此文件已存在!你是否要覆盖此文件?", vbYesNo, "询问") = vbYes Then
fs.CopyFile deffile, sfilename, True
End If
End If
Else
Set fs = Nothing
Exit Sub
End If
Set fs = Nothing
If fill_execl_col = True Then
MsgBox "已将数据成功导入电子表格!"
Else
MsgBox "操作有误!请检查操作是否正确……!"
End If

End Sub

Private Sub Form_Load()
'DataEnvironment1.rsCommand1.Source = ""
End Sub
'填充execl单元
Private Function fill_execl_col(ByVal sfilename As String) As Boolean
On Error GoTo err:
Dim i As Integer
Dim n As Integer
Set EXCAPP = CreateObject("EXCEL.application")
EXCAPP.Visible = False
EXCAPP.Workbooks.Open (sfilename)
For i = 0 To mshflexgrid1.Rows - 1

For n = 0 To mshflexgrid1.Columns - 1

EXCAPP.Worksheets(1).Cells(n, i + 1).Value = mshflexgrid1.Textmatrix(i,n)
Next
Next
EXCAPP.Workbooks(1).Save
EXCAPP.Workbooks(1).Close
EXCAPP.Application.Quit
Set EXCAPP = Nothing
err:
If err.Number <> 0 Then
fill_execl_col = False

EXCAPP.Application.Quit
Set EXCAPP = Nothing
Else
fill_execl_col = True
End If
End Function
asussony 2002-12-09
  • 打赏
  • 举报
回复
引用Execl的对象,对其操作。你可以在VBA版看看。

809

社区成员

发帖
与我相关
我的任务
社区描述
VB 多媒体
社区管理员
  • 多媒体
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧