KOTA ITO

Generation

generate functionThu, 15 Dec 2022

openpyxlを使って、Excelファイルの3列目に含まれる日付ごとに、データを新しいシートに格納する。

# import openpyxl import openpyxl # open xlsx file datasheet = openpyxl.load_workbook('datasheet.xlsx') # create new workbook new_datasheet = openpyxl.Workbook() # get sheetnames sheet_names = datasheet.get_sheet_names() # create sheet new_datasheet.create_sheet(index = 0, title = 'new_sheet') # get sheet sheet = datasheet.get_sheet_by_name(sheet_names[0]) # get sheet new_sheet = new_datasheet.get_sheet_by_name('new_sheet') # get rows and cols rows = sheet.max_row cols = sheet.max_column # get first col for i in range(1, sheets.max_row + 1): if sheet.cell(row = i, column = 1).value != 'None': print(sheet.cell(row = i, column = 1).value

Questions about programming?Chat with your personal AI assistant