python ²Ù×÷ms office Éú³É±¨¸æÏà¹Ø×ܽá
¹Ø¼ü×Ö: python com ±¨¸æ
http://appofis.javaeye.com/blog/417446
python ²Ù×÷ms office Éú³É±¨¸æÏà¹Ø×ܽá
I. ÏîÄ¿ÖÐÐèÒªÉú³ÉwordºÍexcel±¨¸æ£¬Í¨³£ÓÐÁ½ÖÖ·½·¨£º»ùÓÚ×Ö·û´®Æ´½ÓÒÔ¼°COMµ÷Óá£
1) ×Ö·û´®Æ´½ÓÉú³ÉofficeÎĵµµÄÔÀí£º officeÎĵµ±¾Éí¿ÉÒÔÌåÏÖΪxmlÎļþ¸ñʽ£¬ÓÈÆäÊÇMS Excel
2003£¬ÎÒÃÇ¿ÉÒÔ×Ô¼º½«Ò»¸öexcelÁí´æΪxml¸ñʽ£¬ÓÃÎı¾±à¼Æ÷´ò¿ªËü——ºÜÈÝÒ׿´¶®¡£
Òò´ËÖ»Òª³ÌÐòÖа´ÕÕ¸ñʽÊä³öÕâÑùµÄxmlÎļþ£¬ÔÙ±£´æ³ÉofficeÎĵµ¼´¿É¡£Éú³É´óÁ¿¸ñʽ»¯×Ö·û´®ÓÐÒ»¸ö·Ç³£ÖØÒªµÄ¹¤¾ß¾ÍÊÇÄ£°åÒýÇæ
£¨±ÈÈçjsp¾ÍÊÇÕâÑùµÄ¶«Î÷£©£¬ÔÚÉú³ÉofficeÎĵµÊ±£¬javaÓïÑÔ³£ÓõÄÄ£°åÒýÇæ¾ÍÊÇvelocity£¬pythonÖÐÓкÍvelocity·Ç³£ÀàËƵÄAirspeed£¬
»¹ÓÐһЩµÚÈý·½µÄCheetah£¬MakoµÈÄ£°åÒýÇæÏîÄ¿¡£ 2) COMµ÷ÓÃ
×Ö·û´®Æ´½ÓµÄºÃ´¦ÊÇËٶȿ죬µ«È±µã¾ÍÊDZØÐëÊÇÎĵµµÄÎı¾¸ñʽ±ØÐë¼òµ¥Ò׶®£¬Óи´Ôӵĸñʽ¾ÍÎÞÄÜΪÁ¦ÁË£¬ÓÈÆäÊǶÔMS OfficeÕâ¸öËƺõ²¢Ã»ÓÐÍêÈ«
¿ª·Å¸ñʽµÄ°ì¹«Èí¼þ¸üÂé·³¡£¶øCOMµ÷Óü¸ºõ¿ÉÒÔ×öÈκÎÊÂÇ飬ֻҪÈ˹¤²Ù×÷Office¿ÉÒÔÍê³ÉµÄ£¬Ëü¶¼¿ÉÒÔ×ö¡£ÌåÏÖÔÚÎÒÃÇÕâÀï¾ÍÊǶ¯Ì¬Éú³Éͼ£¬
µ÷Õû±í¸ñ¾ÓÖУ¬±íÍ·ÑÕÉ«µÈ£¬ÍùÍùÒ»¸öµ÷ÓþÍÍê³ÉÁË£¨µ«ËüÃÇÉú³ÉµÄÎĵµ¸ñʽÈÃÈË¿´µÃ½¹Í·Àö¡£JavaÖнøÐÐCOMµ÷ÓõĺÃÏñ¾ÍÊÇjacobÁË¡£
PythonÖÐʹÓÃwin32com¡£ÎÒ¾õµÃPythonÖеÄÕâ¸ö×é¼þ¸üºÃÓÃЩ£¬µÃÒæÓÚ¶¯Ì¬ÓïÑÔµÄÓÅÊÆ£¬ËüµÄ±äÁ¿ÀàÐͶ¼ÊǶ¯Ì¬¸³ÓèµÄ£¬
Òò´Ë¿ÉÒÔд³öµÄCOMµ÷ÓôúÂëºÍexcelºê¼ÖƵÄVB´úÂëºÜÏàËÆ£¬ºÜ¶àʱºòÄùýÀ´Ö±½ÓÓþÍÐС£¶øjavaµÄCOMµ÷ÓôúÂëµ½´¦ÊÇDispatch¡£
II.
ʹÓùýÒ»¸ö½Ðsnakelets(Éßòþ»¹ÊÇÓÐÔ¨Ô´µÄ)µÄµÚÈý·½Ä£°åÒýÇ档ͨ³£ËûµÄºó׺ÃûÊÇy¡£yÎļþÖÐÓÃ<%%>À¨ÆðÀ´µÄÊÇpython´úÂ룬
ͨ¹ýÄÚÖ÷½·¨out.writeÊä³ö×Ö·û´®ºÍÉÏÏÂÎĵÄÆÕͨ×Ö·û´®£¨literal text£©Æ´½Ó£¨¿´ÆðÀ´ºÍjspµÄÏë·¨ºÜÏàËÆ£©¡£
ÓɸÃyÎļþÉú³ÉµÄÒ»¸öÆÕͨµÄÎı¾Îļþ¾ÍÊÇÒ»¸ö·ûºÏexcel¸ñʽµÄxmlÎļþ£¬ÀïÍ·ÓÐÒ»¸öexcel±í¸ñ¡£
ÕâÑùÎÒÃǾÍÉú³ÉÒ»¸öexcel sheetµÄ³ûÐΣ¬¶à¸öyÎļþÉú³ÉµÄ´ú±íexcel
sheetµÄ×Ö·û´®ÔÙÆ´ÆðÀ´¾Í¿ÉÒÔ¹¹³ÉÒ»¸öÍêÕûµÄexcelÎļþ¡£È»ºó½øÐÐCOMµ÷Ó㬸øÕâ¸öÎļþ¼ÓÉÏÊ×Ò³£¬Êʵ±µ÷Õû³¬Á´½Ó——excel±¨¸æ¾ÍÕâôÉú³ÉÁË¡£
Word±¨¸æÒª¸´ÔÓÐí¶à£¬ÓÉÓÚexcel±í¸ñ±£´æµÄxmlÎļþ¸üÈÝÒ׿´¶®£¬¶øwordÖеÄͼ£¬Õ½ڵȽṹºÜ¸´ÔÓ£¬
ÔÚÉú³ÉwordÖбí¸ñµÄʱºò½èÖúÇ°ÃæÌáµ½µÄyÎļþÏÈÉú³Éexcel±í¸ñ£¨ÓÐÊÂʹÓøñí¸ñÔÙµ÷ÓÃCOM½Ó¿ÚÉú³ÉÍ
Ïà¹ØÎĵµ£º
#ʹÓÃÀà
class CPerson:
#Àà±äÁ¿ºÃ±ÈC++Öеľ²Ì¬³ÉÔ±±äÁ¿
population = 0
def SayHi(self):
print('Hello World')
def HowMany(self):
if CPerson.population == 1:
print('I am the only person here.')
else:
print(('We have %d perso ......
1.ÁбíµÄµÝ¹é---ÓÃÓÚÊä³öÁбí×Ö·û´®ÖеÄÿ¸öÔªËØ >>> def printList(L):
#Èç¹ûΪ¿Õ£¬Ôòʲô¶¼²»×ö
if not L:
return
#Èç¹ûÊÇÁ´±í£¬Ôò¶ÔµÚÒ»¸öÔªËص÷ÓÃprintListº¯Êý
& ......
дÁ˸öͼƬ֩ÖëÈËÍæÍ棬ץÁ˼¸¸öÍøÒ³ÊÔÊÔ£¬¸Ð¾õ²»²»´í¡£ºËÐĵĴúÂë¿ÉÄÜ20ÐÐÒ²²»µ½£¬¼ò½àÃ÷ÁË£¬ÎûÎû¡£·Ï»°ÉÙ˵£¬´ä»¨£¬ÉÏ´úÂë~~
#coding=utf-8
import os
import sys
import re
import urllib
URL_REG = re.compile(r'(http://[^/\\]+)', re.I)
IMG_REG = re.compile(r'<img[^>]*?src=([ ......
http://cocobear.info/blog/2009/01/16/use-python-deal-with-excel/
ʹÓÃPython´¦ÀíExcel±í¸ñ 2009Äê01ÔÂ16ÈÕ
¸ø°³µÄbossдµÄÒ»¸öС¹¤¾ß£¬Ê¹ÓÃPython¶ÔExcel½øÐÐͳ¼Æ£¬È»ºó°Ñ½áÊøÉú³ÉÒ»¸öеÄExcel±í¸ñ£¬Ê¹Óõ½ÁËxlrdºÍpyExceleratorÁ½¸ö¿â¡£
¼òµ¥µÄ½éÉÜÒ»ÏÂÕâÁ½¸ö¿â£¬ÏÈ˵xlrd£¬Õâ¸ö¿â¶ÁExcel±È½Ï·½±ã£¬¸÷ÖÖ·½·¨Ê¹ÓÃÆ ......
1)Excel hyperlink:
xlsApp = win32com.client.Dispatch('Excel.Application')
cell = xls.App.ActiveSheet.Cells(1,1)
cell.Hyperlink.Add(cell,'http://xxx')
2)Excel row/column count:
sht = xlsApp.ActiveSheet
sht.Columns.Areas.Count
sht.Rows.Areas.Count
*************************
£Û1£ÝʹÓÃPyExcelera ......