5

python读写Excel,优化PHPExcel

 2 years ago
source link: http://abcdxyzk.github.io/blog/2021/07/10/lang-python-xlwt/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

python读写Excel,优化PHPExcel

2021-07-10 09:32:00

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

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

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

#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'))

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK