kk Blog —— 通用基础

date [-d @int|str] [+%s|"+%F %T"]

python读写Excel,优化PHPExcel

PHPExcel getCalculatedValue() 可能很慢,一次需要30ms。预先有python处理后就很快了

1
2
yum install python-pip
pip install xlrd==1.2.0 xlwt

https://www.cnblogs.com/caesar-id/p/11802440.html#top

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#coding:utf-8
import xlrd
import xlwt
import sys

if len(sys.argv) != 3:
	print 'python export.py xlsx sheet'
	exit(1)

filename = sys.argv[1]
sheetname = sys.argv[2]

data = xlrd.open_workbook(filename)
#table = data.sheet_by_index(0)
table = data.sheet_by_name(sheetname.decode('utf-8'))

workbook = xlwt.Workbook(encoding = 'utf-8')
worksheet = workbook.add_sheet(sheetname)

for rn in range(table.nrows):
	line = table.row_values(rn)
	j = 0
	for v in line:
		worksheet.write(rn, j, line[j])
		j = j + 1

workbook.save((filename+'.xls'))