如何在S3存储桶中保存新的XLS工作簿

时间:2019-04-10 07:30:13

标签: python

我正在从s3存储桶中读取xls文件并创建新的xls,然后尝试保存在同一存储桶中的另一个文件夹中。

aws_file_path='KMU/input/'+file_name
s3_session = Session(aws_access_key_id=access_key, aws_secret_access_key=secret_key)
print("aws_file_path---------",aws_file_path)
bucket_object = s3_session.resource('s3').Bucket('subscriptionconfigurable').Object(aws_file_path)
content = bucket_object.get()['Body'].read()
workbook = open_workbook_xls(file_contents=content)
#wb = xlrd.open_workbook(data)
sheet = workbook.sheet_by_index(0)
num_rows = sheet.nrows #Number of Rows
num_cols = sheet.ncols #Number of Columns
Subscription_Product = Workbook()
subs_cash = Subscription_Product.add_sheet('CASH')
newRow=0
for curr_row in range(1, num_rows, 1):
    newCell=0
    firstCelllData=sheet.cell_value(curr_row, 0)
    secondCelllData=sheet.cell_value(curr_row, 1)
    prevCelllData=sheet.cell_value(curr_row-1, 1)
    if firstCelllData=='ROUTE No:' or secondCelllData.isdigit() or prevCelllData.isdigit():
        newRow=newRow+1
        for curr_col in range(0, num_cols, 1):
            data = sheet.cell_value(curr_row, curr_col)
            subs_cash.write(newRow,newCell,data)
            newCell=newCell+1
Subscription_Product.save('a.xls')           

0 个答案:

没有答案