我正撞在墙上。我有一个python脚本,通过shell命令调用SAP脚本。一旦" return.xlsx"那部分就很有效。生成,我使用openpyxl从列A中的值创建一个列表。从那里我尝试将列表附加到剪贴板,以便我可以通过第二个SAP脚本粘贴它。出于某种原因,当我尝试在脚本完成后粘贴excel时,Excel会抛出一个错误窗口," Microsoft Excel无法粘贴数据"。
以下完整脚本:
from subprocess import call
import warnings
import win32gui
import os
import time
from openpyxl import load_workbook
from Tkinter import Tk
import wx
import pyautogui
warnings.filterwarnings('ignore')
filePath = os.path.expanduser("~\Desktop\\")
app = wx.App()
frame = wx.Frame(None, -1)
############## Start and stop dates
dlg = wx.TextEntryDialog(frame, 'Enter Start Date','Start Date')
dlg.SetValue("mm/dd/YYYY")
if dlg.ShowModal() == wx.ID_OK:
startDate = dlg.GetValue()
dlg.Destroy()
dlg2 = wx.TextEntryDialog(frame, 'Enter End Date','End Date')
dlg2.SetValue("mm/dd/YYYY")
if dlg2.ShowModal() == wx.ID_OK:
endDate = dlg2.GetValue()
dlg2.Destroy()
#############
############################Functions for getting the window names and copying data to the clip board
def GetWindowName():
winName=win32gui.GetWindowText (win32gui.GetForegroundWindow())
return winName
def CopytoClip(clipList):
r = Tk()
r.withdraw()
r.clipboard_clear()
for item in clipList:
r.clipboard_append(item)
r.clipboard_append("\n")
r.update()
r.destroy()
############################
###################SAP GUI Shell Commands
command = 'guixt.exe "Input=V[MYDATE]:%s;V[END_DATE]:%s;OK: process=C:\guixt\scripts\\RetReport2.txt"' %(startDate, endDate)
call(command, shell = True, cwd = 'C:\Program Files (x86)\SAP\FrontEnd\SAPgui\\')
###################
################################Waiting for the save as window and saving the file as retuns.xlsx on the desktop
winName = "nothing"
while winName != "Save As":
winName = GetWindowName()
time.sleep(1)
retFile = filePath + 'returns.XLSX'
pyautogui.typewrite(retFile)
pyautogui.press('enter')
################################
###############Waiting for the file to auto open
winName = "nothing"
while winName != "returns.XLSX - Excel":
winName = GetWindowName()
time.sleep(2)
################################
##############################Create the list from column A and append to clipboard
salesOrders = []
wbSales = load_workbook(filename = retFile)
wsSales = wbSales['Sheet1']
for row in wsSales.iter_rows('A:A', row_offset = 1):
for cell in row:
try:
salesOrders.append(int(cell.value))
except TypeError:
pass
CopytoClip(salesOrders)
#################################
现在,如果我使用" returns.xlsx"我在上面的脚本中创建了以下简短脚本...剪贴板已满。任何人都可以帮助找出剪贴板无法在完整脚本中工作的原因吗?
from openpyxl import load_workbook
from tkinter import *
import time
import os
filePath = os.path.expanduser("~\Desktop\\")
retFile = filePath + 'returns.XLSX'
def CopytoClip(clipList):
r = Tk()
r.withdraw()
r.clipboard_clear()
for item in clipList:
r.clipboard_append(item)
r.clipboard_append("\n")
r.update()
r.destroy()
salesOrders = []
wbSales = load_workbook(filename = retFile)
wsSales = wbSales['Sheet1']
for row in wsSales.iter_rows('A:A', row_offset = 1):
for cell in row:
try:
salesOrders.append(int(cell.value))
except TypeError:
pass
CopytoClip(salesOrders)
答案 0 :(得分:0)
为什么不打印第二个参数然后管道参数?
print(saleOrders)
从命令行:
python firstscript.py whateverparamineed | secondscript