如何使用openpyxl读取文本框中的文本 [英] How to read the text in textbox by using openpyxl
本文介绍了如何使用openpyxl读取文本框中的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
全部我可以读取单元格中的文本,但文本框无法读取文本...
all I can read the text in cells, but the textbox can't read the text...
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re,os,sys,time
import openpyxl
from openpyxl import load_workbook
from openpyxl import Workbook
from openpyxl.drawing import *
reload(sys)
sys.setdefaultencoding('utf8')
wb = load_workbook(u'2.xlsx')
sheetnames = wb.get_sheet_names()
for i in range(0,len(sheetnames)):
sheet = wb.get_sheet_by_name(sheetnames[i])
for row in sheet.rows:
for cell in row:
if cell.value:
print cell.value
我尝试解压缩 xlsx 文件并在 xl\drawings\drawing[0-9].xml 文件中找到文本框的内容..并且 openpyxl.drawing.text 可以读取文本框吗?我不知道...我怎样才能做到这一点..?谢谢...
I try to unzip the xlsx file and find the content of textbox in xl\drawings\drawing[0-9].xml files.. and can openpyxl.drawing.text can read the textbox? I have no idea... How can i do this..? thx...
推荐答案
我要解压xlsx文件......
I have to unzip the xlsx file......
zipFile = zipfile.ZipFile(os.path.join(os.getcwd(), u''+str(flist)+''))
for file in zipFile.namelist():
zipFile.extract(file, r'tmp')
zipFile.close()
num = 0
if os.path.exists(r'tmp/xl/drawings'):
xmldir = os.listdir(r'tmp/xl/drawings')
for xmlfile in xmldir:
xml = os.path.basename(xmlfile)
if os.path.splitext(xml)[1] == '.xml':
a = open(u'tmp/xl/drawings/'+str(xml)+'').read()
b = a.replace('\n','').replace(' ','')
c = re.findall(r'<a:p>(.*?)</a:p>',b)
for i in c:
text = "".join(re.findall(r'(?<=<a:t>).*?(?=</a:t>)',u''+str(i)+'',re.S)).replace(' ','').replace(' ','').replace('\\u6d3b\\u52a8','').replace('<','<').replace('>','>').replace('&','&')
这篇关于如何使用openpyxl读取文本框中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文