Python 处理excel并转为table
使用xlrd
来
读取,xlrd的下载及安装可以参看:
Python
"xlrd" package for extracting data from Excel files
---------------------------------------------------------------------------------
#coding=utf-8
import xlrd
import os, types, datetime
#excel存放目录
dir = u'D:\\temp\\excel'
#生成html存放目录,需要事先建立
htmlroot = u'D:\\temp\\html'
#excel从1899/12/31计算时间
__s_date = datetime.date(1899, 12, 31).toordinal() - 1
#读取时间格式的单元
def getdate(date):
if isinstance(date, float):
date = int(date)
d = datetime.date.fromordinal(__s_date + date)
return d.strftime("%Y-%m-%d")
#遍历文件夹
for root, dirs, files in os.walk(dir):
for file in files:
#生成excel文件路径
path = os.path.join(root, file)
print u'converting... ' + path
book = xlrd.open_workbook(path) #打开excel文件
#遍历excel文件中的sheet
for shn in range(book.nsheets):
sh = book.sheet_by_index(shn)
#判断该表是否为空
if sh.nrows == 0:
continue
#搜索“路径”列
&nbs
相关文档:
python
语言概览
python
脚本可以处理外部传进来的参数 即sys.argv[]
,argv[]
的使用与linux
下相同
python
本身是解释语言,可以对输入的式子求值。python
支持的对象如整数都是立即数,此外他支持复数,及对四则运算解释。
ptyhon
支持字符串,放在单/
双引号内,字符串是数组,可以通过[i: ......
今天是第二天自己看关于Python了,看见一个Python2写的百度词典,我也用Python 3 写了一个。真的很小巧,呵呵,很好的语言。
不知道怎么上传代码格式的,就上传文本了:
# -*- coding: utf8 -*-
import urllib.parse
import urllib.request
def search(word):
#word = input("输入你要查询的 ......
关键字: python
Python、Unicode和中文[转]
python的中文问题一直是困扰新手的头疼问题,这篇文章将给你详细地讲解一下这方面的知识。当然,几乎可以确定的是,在将来的版本中,python会彻底解决此问题,不用我们这么麻烦了。
先来看看python的版本:
>>> import sys
>> ......
基本上都是使用python来解析xml文件的。
比如我要将内容为
<?xml version="1.0" encoding="utf-8"?>
<root>
<book isbn="34909023">
<author>
&n ......