我会在 Excel 中使用 SQL 来处理这个问题。此技术不会从您的显示文件中获取数据。相反,它将使用您的第二个选项,即从基础数据库表中获取它。
.odc
文件以访问 IBM i DB2 数据库。在我的 PC 上,ODBC 和 OLE DB 驱动程序与模拟器一起安装,以便您可以使用 Microsoft 协议连接到 IBM i。SELECT
语句获得任意所需的效果: joins 、CTE、子查询、任何格式良好的 DB2 for i SQL。.odc
源。您可以在 IBM Personal Communicagtions 中使用 VBScript 宏。下面是一个示例脚本,它将从屏幕读取信息,然后将该信息发送到 Excel 电子表格。
[PCOMM SCRIPT HEADER]
LANGUAGE=VBSCRIPT
DESCRIPTION=Paste to Excel
[PCOMM SCRIPT SOURCE]
Dim wsh
Set wsh=CreateObject("WScript.Shell")
Dim pComm5250
' Set up Variables
Dim ReadThis
Dim strArray
Dim i
'
' Get Presentation Space of current emulator window
autECLSession.SetConnectionByName(ThisSessionName)
Set pComm5250=autECLSession.autECLPS
' Set up a Function for correcting the case of names
Function PCase(strInput)
Dim i, x, strOut, flg
flg = True
For i = 1 To Len(strInput)
x = LCase(Mid(strInput, i, 1))
If Not IsNumeric(x) And (x < "a" Or x > "z") Then
flg = True
ElseIf flg Then
x = UCase(x)
flg = False
End If
strOut = strOut & x
Next
PCase = strOut
End Function
' The first two numbers are the screen location row and column. The third number is how many characters to read.
autECLSession.autECLOIA.WaitForInputReady
ReadThis=pComm5250.GetText(1,2,10)
' Trim any extra blank spaces to the right
ReadThis=RTrim(ReadThis)
' If the variable is numbers, you use this to replace any blank space with a "0".
ReadThis=Replace(ReadThis," ","0")
' If the variable is text you can do this to capitalize each word
ReadThis=PCase(ReadThis)
'Create the excel object
set objExcel = CreateObject("Excel.Application")
'View the Excel program and file, set to false to hide the whole process
objExcel.Visible = True
'Open the excel file
Set objWorkbook = objExcel.Workbooks.Open("C:\Path\ExcelFile.xlsm", , True)
'Set the cell value at row 2 column 3
objExcel.Cells(2,3).Value = (ReadThis)
Set wsh=Nothing
Set pComm5250=Nothing
你有没有找到可以写在excel中的解决方案?我尝试了Greg提到的,数据可以很好地从persComm读取,但无法使用.Cells.Value方法将其写入excel中。