我是用户excell到python中的csv转换器,但是在执行此代码时获取交替行中的值

时间:2019-01-09 12:23:37

标签: python-3.x

在执行此代码时,会在交替的行中获取值

记录的时间服务段源Sinumber否FTR编号解析代码技术SR&FTR类别Circle23 CELL_ID LOCATION_AREA_CODE

43454金新员工9136909842否FTR号码已完成故障排除4G发布FTR数据MUM 6673 1377

43454 GoldNew DTPSTCC 9940686313未提供FTR编号信息-重新插入SIM 2G,然后再进行FTR连接CHN 47717 352

43454金牌DTPSTCC 8448759162没有FTR编号站点计划的2G FTR后覆盖率DEL 41392 160

from xlrd import open_workbook

import csv

wb = open_workbook('C:\\Cluter_Dashboard\\Sample Data (003).xlsx')

for i in range(0, wb.nsheets):

    sheet = wb.sheet_by_index(i)

    print(sheet.name)
    with open("C:\\Cluter_Dashboard\\%s.csv" %(sheet.name.replace(" ","")), "w") as file:

        writer = csv.writer(file, delimiter = ",")

        print(sheet, sheet.name, sheet.ncols, sheet.nrows)

        header = [cell.value for cell in sheet.row(0)]

        writer.writerow(header)

        for row_idx in range(1, sheet.nrows):

            row = [int(cell.value) if isinstance(cell.value, float) else cell.value

                   for cell in sheet.row(row_idx)]

            writer.writerow(row)

0 个答案:

没有答案