读取win32/Excel文件com.clien公司

2024-04-28 20:00:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在写一个代码,我把Excel链接到PSSE。我使用win32模块,因为我的学校不允许使用模块xlrdopenpyxl,和{}。所以我在代码中的目标是最初使用win32模块读取excel文件。在

它读取文件,但我正在尝试执行以下操作:

  • 阅读第一列,使其代表年份
  • 第二列是总线编号
  • 第三列是总线名称
  • 第四列是
  • 第六列是区域
  • 最后一列是位置ID。在

我已经发布了我的页面格式的excel表片段。我的下一个目标是将年份和位置联系起来,作为找到busnum、busname、power的标准。对于年份位置我将使用raw_input(),如果输入位置年份,输出应给出总线编号总线名称电源。在

我的代码如下所示,这是我编写代码的想法。它不运行,我尝试了一切,但没有任何效果。在

Excel Sheet

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])

Tags: the代码inforlocationchangeyearmydict