python 安装win32com_python调用win32com.client时提示:No module named win32com.client
本人是python菜鳥,根本沒學過,因為要用到所以搜索了段代碼,鏈接如下:http://hi.baidu.com/%C0%E1%B9%FD%CE%DE%BA%DBno1/blog/item/b11e5b186e3143a94aedbc15.html代碼如下:fromw...
本人是python菜鳥,根本沒學過,因為要用到所以搜索了段代碼,鏈接如下:
http://hi.baidu.com/%C0%E1%B9%FD%CE%DE%BA%DBno1/blog/item/b11e5b186e3143a94aedbc15.html
代碼如下:
from win32com.client import Dispatch
import win32com.client
class easyExcel:
"""A utility to make it easier to get at Excel. Remembering
to save the data is your problem, as is error handling.
Operates on one workbook at a time."""
def __init__(self, filename=None):
self.xlApp = win32com.client.Dispatch('Excel.Application')
if filename:
self.filename = filename
self.xlBook = self.xlApp.Workbooks.Open(filename)
else:
self.xlBook = self.xlApp.Workbooks.Add()
self.filename = ''
def save(self, newfilename=None):
if newfilename:
self.filename = newfilename
self.xlBook.SaveAs(newfilename)
else:
self.xlBook.Save()
def close(self):
self.xlBook.Close(SaveChanges=0)
del self.xlApp
def GetExcelLineCount(self):
count = 0
sht = self.xlBook.Worksheets('第一輪')
while True:
if sht.Cells(count + 1, 1).Value == None:
break
count += 1
return count
def getCell(self, sheet, row, col):
"Get value of one cell"
sht = self.xlBook.Worksheets(sheet)
return sht.Cells(row, col).Value
def setCell(self, sheet, row, col, value):
"set value of one cell"
sht = self.xlBook.Worksheets(sheet)
sht.Cells(row, col).Value = value
def getRange(self, sheet, row1, col1, row2, col2):
"return a 2d array (i.e. tuple of tuples)"
sht = self.xlBook.Worksheets(sheet)
return sht.Range(sht.Cells(row1, col1), sht.Cells(row2, col2)).Value
if __name__ == "__main__":
xls = easyExcel('E:/pythonWorkspace/test.xls')
lineNum = xls.GetExcelLineCount()
for i in range(1,lineNum + 1):
for j in range(1,8):
print ,xls.getCell('第一輪', i, j)
xls.save()
xls.close()
運行時,提示:from win32com.client import Dispatch
ImportError: No module named win32com.client
環境:Win7 專業版
python 3.2.2+IDEL
我知道是缺少win32com.client,我想得到的是如何才能成功加載win32com.client
安裝pywin32-216.1.win32-py3.2.exe 之后,原來的問題解決,但是出現新的問題:
File xxx, line 1, in
from win32com.client import Dispatch
File "D:\Program Files\Python32\lib\site-packages\win32com\__init__.py", line 5, in
import win32api, sys, os
ImportError: No module named win32api
展開
總結
以上是生活随笔為你收集整理的python 安装win32com_python调用win32com.client时提示:No module named win32com.client的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 重新定义旅游网站,米胖新版发布
- 下一篇: LINUX下的APACHE的配置