积极答复者
求助:ifix 4.0脚本中调用excel保存报表

问题
-
以下是代码:
On Error Resume Next
Dim strDateTime As String
Dim strDate As String
Dim strHourMinute As String
Dim iRow As Integer
Dim strTemplateName As String
strDateTime = Format(Now(), "yyyy-MM-dd,hh:mm:ss")
strDate = Left(strDateTime, 10)
strHourMinute = Right(Left(strDateTime, 13), 2) & ":00"
iRow = Right(Left(strDateTime, 13), 2)
Dim IsCreate As Boolean
Set fs = CreateObject("Scripting.FileSystemObject")
IsCreate = fs.FileExists(System.ProjectPath & "\APP\日报表\日报表" & strDate & ".htm")
Set fs = Nothing
If IsCreate Then '日报表文件已创建,则打开。
strTemplateName = (System.ProjectPath & "\APP\日报表\日报表" & strDate & ".htm")
Else '日报表文件不存在,则使用模板创建。
strTemplateName = System.ProjectPath & "\APP\报表模板\日报表模板.htm"
End If
'打开创建Excel对象。
Set msExcel = CreateObject("Excel.Application")
With msExcel
.Visible = True 'EXCEL不可见
.Workbooks.Open strTemplateName, , False
.ActiveWorkbook.ActiveSheet.Select
.DisplayAlerts = False '报警窗口不可见
.Wait (Now() + 0.00002)
End With
'填日期时间
msExcel.WorkSheets(1).Cells(2, 1).Value = "日期:" & strDate
msExcel.WorkSheets(1).Cells(3, 2).Value = strHourMinute
''填数据
msExcel.WorkSheets(1).Cells(4, iRow + 2).Value = readvalue("LEVEL_0")
msExcel.WorkSheets(1).Cells(5, iRow + 2).Value = readvalue("LEVEL_1")
msExcel.WorkSheets(1).Cells(6, iRow + 2).Value = readvalue("LEVEL_2")
msExcel.WorkSheets(1).Cells(7, iRow + 2).Value = readvalue("LEVEL_3")
msExcel.WorkSheets(1).Cells(8, iRow + 2).Value = readvalue("LEVEL_4")
msExcel.WorkSheets(1).Cells(9, iRow + 2).Value = readvalue("PRESSURE_0")
msExcel.WorkSheets(1).Cells(10, iRow + 2).Value = readvalue("PRESSURE_1")
msExcel.WorkSheets(1).Cells(11, iRow + 2).Value = readvalue("PRESSURE_2")
msExcel.WorkSheets(1).Cells(12, iRow + 2).Value = readvalue("PRESSURE_3")
msExcel.WorkSheets(1).Cells(13, iRow + 2).Value = readvalue("PRESSURE_4")
msExcel.WorkSheets(1).Cells(14, iRow + 2).Value = readvalue("PRESSURE_5")
msExcel.WorkSheets(1).Cells(15, iRow + 2).Value = readvalue("PRESSURE_6")
msExcel.WorkSheets(1).Cells(16, iRow + 2).Value = readvalue("FLOW_0")
msExcel.WorkSheets(1).Cells(17, iRow + 2).Value = readvalue("FLOW_1")
msExcel.WorkSheets(1).Cells(18, iRow + 2).Value = readvalue("FLOW_2")
msExcel.WorkSheets(1).Cells(19, iRow + 2).Value = readvalue("FLOW_3")
msExcel.WorkSheets(1).Cells(20, iRow + 2).Value = readvalue("FLOW_4")
msExcel.WorkSheets(1).Cells(21, iRow + 2).Value = readvalue("FLOW_5")
msExcel.WorkSheets(1).Cells(22, iRow + 2).Value = readvalue("FREQUENCY_0")
msExcel.WorkSheets(1).Cells(23, iRow + 2).Value = readvalue("FREQUENCY_1")
msExcel.WorkSheets(1).Cells(24, iRow + 2).Value = readvalue("FREQUENCY_2")
msExcel.WorkSheets(1).Cells(25, iRow + 2).Value = readvalue("FREQUENCY_3")
msExcel.WorkSheets(1).Cells(26, iRow + 2).Value = readvalue("FREQUENCY_4")
msExcel.WorkSheets(1).Cells(27, iRow + 2).Value = readvalue("FREQUENCY_5")
msExcel.WorkSheets(1).Cells(28, iRow + 2).Value = readvalue("FREQUENCY_6")
msExcel.WorkSheets(1).Cells(29, iRow + 2).Value = readvalue("FREQUENCY_7")
'保存Excel并退出
Dim strSaveName As String
strSaveName = System.ProjectPath & "\APP\日报表\日报表" & strDate & ".htm"
msExcel.ActiveWorkbook.SaveAs strSaveName
msExcel.Quit
msExcel.DisplayAlerts = True
Set msExcel = Nothing
上面的代码在ifix5.0中能够保存,但是在ifix4.0中无法保存,引用了Microsoft Excel 12.0 Object Library,office版本为2007,操作系统为windows xp sp3
- 已编辑 烟渚萧客 2013年8月23日 5:34