python指定sheet转化为csv_在python中将包含多个工作表的xls文件转换为单独的csv

这个怎么样?在

下面的脚本应该执行您想要的操作:import xlrd, xlwt, sys

def raj_split(in_path, out_stem):

in_book = xlrd.open_workbook(in_path)

in_sheet = in_book.sheet_by_index(0)

first_row = in_sheet.row_values(0)

# find the rightmost 1 value in the first row

split_pos = max(

colx for colx, value in enumerate(first_row) if value == 1.0

) + 1

out_book = xlwt.Workbook()

out_sheet = out_book.add_sheet("Sheet1", cell_overwrite_ok=True)

# copy the common cells

for rowx in xrange(in_sheet.nrows):

row_vals = in_sheet.row_values(rowx, end_colx=split_pos)

for colx in xrange(split_pos):

out_sheet.write(rowx, colx, row_vals[colx])

out_num = 0

# for each output file ...

for out_col in range(split_pos, in_sheet.ncols):

out_num += 1

# ... overwrite the `split_pos` column

for rowx, value in enumerate(in_sheet.col_values(colx=out_col)):

out_sheet.write(rowx, split_pos, value)

# ... and save the file.

out_book.save("%s_%03d.xls" % (out_stem, out_num))

raj_split(*sys.argv[1:3])

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值