我正在编写一个将Excel链接到PSSE的代码。我使用的是win32
模块,因为我的学校不允许使用模块xlrd
,openpyxl
和csv
。所以我在代码中的目标是最初使用win32
模块读取excel文件。
它读取文件,但我正在尝试执行以下操作:
我已经发布了我页面格式的excel表格的片段。我的下一个目标是将年份和位置链接在一起作为查找 busnum,busname,和 power 的标准。我会使用raw_input()
作为年和位置,如果输入 location 和年 ,输出应该给我总线编号,总线名称和电源。
我的代码如下所示,这是我做代码的想法。它没有运行,我尝试了一切,没有任何作用。
import os, sys
import psspy
import win32com.client
from win32com.client import Dispatch
PSSE_LOCATION = r"C:\Program Files (x86)\PTI\PSSE33\PSSBIN"
sys.path.append(PSSE_LOCATION)
os.environ['PATH'] = os.environ['PATH'] + ';' + PSSE_LOCATION
xlApp = Dispatch ("Excel.Application") #Calls for Excel
xlWb = xlApp.Workbooks.Open('Load forecast 12152016.xlsx') #It finds the workbook
xlSht = xlWb.Worksheets (18)
dataList = []
for row in range (2,760): #It goes through the 758 items in A and B
for col in (1,2,3,4,5):
dataList.append(xlSht.Cells(row,col))
mydict = {}
for row in dataList:
year = xlSht.Cells[1:760,1]
busnnum = row[B2:B760]
busname = row[C2:C760]
Power = row[D2:D760]
Area = row[E2:E760]
location = row[F2:F760]
# convert the types from string to Python numbers
change= float(change)
bus = int(busnum)
#If this is a year not seen before, add it to the dictionary
if year not in mydict:
mydict[year] = {}
busses_in_year = mydict[year]
if location not in busses_in_year:
busses_in_year[location] = []
#Add the bus to the list of busses that stop at this location
busses_in_year[location].append((busnum,busname,power))
year = raw_input("Please Select Year of Study: ")
print("\n")
commands = ["M", "As", "Br", "D",
"V", "G","W","E","S","E",
"Ea","DU","Cor","Asto",
"AV","A"]
max_columns = 50
for index, commands in enumerate(commands):
stars_amount = max(max_columns - len(commands), 0)
row = "# {} {}({})".format(commands, "." * stars_amount, index + 1)
print row
location=raw_input(" \n The list above show the TLA Pockets as well as the ID numbers assigned to them ()\n\n Please enter the ID #: ")
print("\n")
# assume CSV has columns as described in the doc string
if year in mydict and location in mydict[year]:
busses_in_year = mydict[year]
print("Here are all the busses at that location for that year and the new LOAD TOTAL: ")
print("\n")
for busnum,busname,change in busses_in_year[location]:
change= float(change)
busnum = int(busnum)
print('Bus #: %d' % busnum ,'Area Station: %s'% busname, 'New_load: %d MW' %change)
psspy.bsys(1,0,[0.0,0.0],0,[],1,[busnum],0,[],0,[])
psspy.scal_2(1,0,1,[0,0,0,0,0],[0.0,0.0,0.0,0.0,0.0,0.0,0.0])
psspy.scal_2(0,1,2,[0,1,0,1,0],[change,0.0,0,-.0,0.0,-.0,0])