我有一个非常庞大的excel文件。那里" ------------"几行之间的这个字符串。我想将文件从" ------------"中删除。到另一个" ------------"并用" ------------"'''的下一个单元格中的单词命名。请帮我这样做。
答案 0 :(得分:1)
我要做的是使用:http://www.python-excel.org/。
pip install xlrd xlwt
xlrd - 读取Excel文件
xlwt - 写入Excel文件
然后我会尝试这样的事情:
import xlrd
import xlwt
def write_rows(batch, filename):
current_batch_xls = xlwt.Workbook(encoding='utf-8')
first_sheet = current_batch_xls.add_sheet(filename + ' sheet')
for row_number, row in enumerate(batch):
for cell_number, cell in enumerate(row):
first_sheet.write(row_number, cell_number, cell.value, style=cell.xf_index)
current_batch_xls.save(filename)
FILENAME='big-excel-spreadsheet.xls'
DELIMITER='------------'
big_spreadsheet = xlrd.open_workbook(FILENAME)
# assuming you have only one sheet
sheet = big_spreadsheet.sheet_by_index(0)
current_batch_of_rows = []
for row in xrange(2, sheet.nrows):
if row.cell(row, 0) == DELIMITER:
write_rows(current_batch_of_rows, filename=row.cell(row, 1))
current_batch_of_rows = []
continue
current_batch_of_rows.append(sheet.row(row))
未测试。对于xlrd
和xlwt
,文档似乎非常糟糕。