Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
410 views
in Technique[技术] by (71.8m points)

How to read the text in textbox by using 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

I try to unzip the xlsx file and find the content of textbox in xldrawingsdrawing[0-9].xml files.. and can openpyxl.drawing.text can read the textbox? I have no idea... How can i do this..? thx...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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('
','').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('&lt;','<').replace('&gt;','>').replace('&amp;','&')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...