Python 读取Excel中的数据插入到数据库中
1 import xlrd 2 import os 3 4 5 # 读取Excel中的数据 6 def read_excel_data(): 7 excel_path = os.path.join(os.getcwd(), 'total.xlsx') 8 print("~~~~~~~~~~~~>>>Excel文件路径是:" + excel_path) 9 excel_file = xlrd.open_workbook(excel_path) 10 table = excel_file.sheets()[0] 11 print("~~~~~~~~~~~~>>>已经打开的工作簿名称:" + table.name) 12 13 all_content = [] 14 for i in range(table.nrows): 15 row_content = [] 16 for j in range(table.ncols): 17 cell_value = table.cell(i, j).value 18 row_content.append(cell_value) 19 all_content.append(row_content) 20 return all_content 21 22 23 if __name__ == '__main__': 24 all_list = read_excel_data() 25 for item in all_list: 26 print(item)