python读取图片文字为表格_python处理文字,读取execl表格入库

import pymysql

from docx import Document

db=pymysql.connect(host="172.16.22.208",port=3316,user="root",password="123456789Aa",database="hydrological_dev",charset="utf8")

cursor=db.cursor()

path= "C:\\Users\\Administrator\\Desktop\\2017年城市防汛积水隐患调查表3.docx"          #文件路径

document= Document(path)                #读入文件

tables= document.tables                    #获取文件中的表格集

table= tables[0]                                  #获取文件中的第一个表格

t=181

for i in range(49,len(table.rows)):                              #从表格第二行开始循环读取表格数据

index1=int(table.cell(i,0).text)

stnm=table.cell(i,1).text

r= table.cell(i,8).text.split(',\n')

x= r[0]

y= r[1]

sql="insert into test(index1,stnm,lgtd,lttd,expand1,expand2,index2) values ('%s','%s','%s','%s',3,'2017年城市防汛积水隐患调查表',%d)"%(index1,stnm,x,y,t)

try:

cursor.execute(sql)

db.commit()

print("successfully")

except:

db.rollback()

db.close()

print("fail")

print(sql)

t=t+1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值