用Python处理Excel表格
我想用Python处理Excel表格,但有个问题。用Python处理Excel表格,python,excel,Python,Excel,我想用Python处理Excel表格,但有个问题。 # -*- coding: utf-8 -*- import xlrd from xlwt import * book = xlrd.open_workbook('myExcel.xls') #open a table sheet = book.sheets()[0] nrows = sheet.nrows books = [] for i in range(nrows): value = sheet.cell_value(i, 5
# -*- coding: utf-8 -*-
import xlrd
from xlwt import *
book = xlrd.open_workbook('myExcel.xls') #open a table
sheet = book.sheets()[0]
nrows = sheet.nrows
books = []
for i in range(nrows):
value = sheet.cell_value(i, 5)
if value == u'李雷':
ss = sheet.row_values(i)
for ii in range(len(ss)):
data = ss[ii] #get data in the specified row
books.append(data)
newbook = Workbook(encoding = 'utf-8') # open a new table
newsheet = newbook.add_sheet('李雷')
for item in books:
for item_row in range(2, 100):
for item_col in range(7):
newsheet.write(item_row, item_col, label = item) #write data
newbook.save('newExcel.xls')
- 日期 单号 项目 金额 结算 业务员李>
- 12.1 100001 A 100现金 李雷 李>
- 12.1 100002 D 200现金 韩梅梅李>
- 12.1 100003 A 100现金 李雷李>
- 12.1 100004 E 450现金 小明李>
- 12.1 100005 R 430现金 小明李>
- 12.1 100006 A 100现金 李雷李>
- 12.1 100007 A 100现金 李雷李>
- 12.1 100008 A 100现金 李雷李>
- 12.1 100010 A 90现金 韩梅梅李>
- 12.1 100011 K 120现金 小红李>
异常:尝试覆盖单元格:sheetname=u'\u674e\u96f7'rowx=2 colx=0您需要允许覆盖:
newsheet = newbook.add_sheet('李雷',cell_overwrite_ok=True)
否则,每个单元格只允许一次写入。谢谢。出了点问题。我想要所有关于“李雷" 对于数据,并非所有单元格都是'李雷'.@辜,对不起,我不太理解你的评论,这个错误是关于
“的。”李雷“
,是否有其他错误?@padraiccnningham感谢您的回复。在我修改后运行脚本,所有单元格都将被删除”李雷'. 我不知道为什么?这不是我想要的。在上半部分,“数据”显然是“数据”的行李雷', 写一个Excel,它变成了'李雷'