Use python to read excel files and print to the console
Guide package
import openpyxl
Find excel file
workbook = openpyxl.load_workbook('苏州.xlsx')
sheet = workbook.active
Read column names of excel file
columns = []
for col in range(2, sheet.max_column + 1):
cell = sheet.cell(1, col)
columns.append(cell.value)
All code
import openpyxl
workbook = openpyxl.load_workbook('苏州.xlsx')
sheet = workbook.active
columns = []
for col in range(2, sheet.max_column + 1):
cell = sheet.cell(1, col)
columns.append(cell.value)
for row in range(2, sheet.max_row + 1):
print(" INSERT INTO 0823_02 (", end='')
for i in range(len(columns)):
if i < len(columns) - 1:
print(columns[i] + ", ", end='')
else:
print(columns[i]+") VALUES (", end='')
for col in range(2, sheet.max_column + 1):
cell = sheet.cell(row, col)
print("'"+str(cell.value)+"'", end='')
if col < sheet.max_column:
print(", ", end='')
print(");")