def docx_insert_data():
for files in os.listdir(path):
print(files)
if os.path.splitext(files)[1] == '.docx':
try:
word = Document(path + '/' + files)
tables = word.tables
table = tables[0]
# print('table = %s' % table)
tables = ['sequence_number', 'drug_name', 'enterprise', 'batch_number', 'specification',
'source', 'standard', 'result', 'defective_item', 'certification_body', 'placeholder1',
'placeholder2', 'placeholder3', 'placeholder4', 'placeholder5', 'placeholder6',
'placeholder7',
'placeholder8', 'placeholder9', 'placeholder10', 'placeholder11', 'placeholder12',
'placeholder13',
'placeholder14', 'placeholder15', 'placeholder16', 'placeholder17', 'placeholder18']
for rows in table.rows:
# print('k = %s' % rows)
col_list = []
for cols in rows.cells:
col_list.append(cols.text)
# print('col_lists = %s' % col_list)
table_jsda = ', '.join(tables[0:len(col_list)])
# print('table_jsda = %s' % table_jsda)
values_s = ', '.join(['%s'] * len(col_list))
# print('values_s = %s' % values_s)
sql_query = 'insert into jsda(%s) values(%s)' % (table_jsda, values_s)
cursor.execute(sql_query, col_list)
except Exception as e:
print(e)
doc解析到数据库
最新推荐文章于 2021-03-31 23:36:27 发布