所有 我可以在单元格中阅读文本,但文本框无法读取文本...
#!/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可以读取文本框吗?我不知道... 我怎样才能做到这一点..? THX ...
答案 0 :(得分:0)
我必须解压缩xlsx文件......
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('&','&')