python操作excel
既然选择了远方,就必须日夜兼程 http://wrsuifeng.javaeye.com
Python代码
# Filename: excel.py
import os,sys,time
import win32com.client
import traceback
excel = win32com.client.Dispatch("Excel.Application")
filename = "D:\\test.xls"
try:
d1 = excel.Workbooks.Add()
sheet = d1.Sheets(1)
for i in xrange(1,10):
for j in xrange(1,10):
sheet.Cells(i,j).Value = str(i*j)
d1.SaveAs(filename)
except Exception, e:
print traceback.print_exc()
print e
excel.Quit()
相关文档:
def MergeSort(mylist, low, mid, high):
i = low
j = mid + 1
tmp = []
while i <= mid and j <= high:
if mylist[i] <= mylist[j]:
tmp.append(mylist[i])
i = i + 1
else:
tmp.append(mylist[j])
j = j + 1
......
Python最大的特点就在于她的快速开发功能。作为一种胶水型语言,python几乎可以渗透在我们编程过程中的各个领域。这里我简单介绍一下用python进行gui开发的一些选择。
1.Tkinter
Tkinter似乎是与tcl语言同时发展起来的一种界面库。tkinter是python的配备的标准gui库,也是opensource的产物。Tkinter可用于win ......
时常见到一些好的Python模块,如果不随时记下,等用的时候又是一阵乱翻,好在Python引用一个模块极其方便,OK,废话少说:
1. decimal
标准模块,2.4引入,用于浮点数的精确表示:
>>> 0.1 + 0.1 + 0.1 - 0.3
5.5511151231257827e-17
>>> from decimal import Decimal
>>> def _(x): retu ......
写了个图片蜘蛛人玩玩,抓了几个网页试试,感觉不不错。核心的代码可能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=([ ......
下载的PDF文档中有的命名很乱,就想起了自己写个程序,然后读取PDF的title属xing,根据这个属xing,更改次文档的名字!以下是代码:
需要到:http://pybrary.net/pyPdf/上面下载对应平台的PDF的库文件,然后安装,导入。
#encoding:utf-8
import os
import operator
from pyPdf import PdfFileWriter, PdfFileReader ......