如何使用openpyxl
所有 阅读文本框中的文本,我可以阅读单元格的文本,但文本框无法阅读文字...如何使用openpyxl
#!/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 ...
回答:
我要解压缩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('&','&')
以上是 如何使用openpyxl 的全部内容, 来源链接: utcz.com/qa/261857.html