Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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;','&')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...