I was developing an application to log in and out times using a Qr.
The system runs but when it is sent to register the hours the camera turns on and after a while this error appears.
invalid qr code source points (expected: 'contourarea(src_points) > 0.0'), where > 'contourarea(src_points)' is 0 > must be greater than > '0.0' is 0.
This is the part of the code as I have done where the error occurs
while (capture.isOpened()):
_,frame = capture.read()
if (cv2.waitKey(1)== ord('s')):
break
qrDetector = cv2.QRCodeDetector()
data,bbox, rectifiedImage = qrDetector.detectAndDecode(frame)
fecha = date.today()
now = datetime.now()
h=now.time()
**if len(data) > 0:** #LINEA DONDE SALTA EL ERROR
arr = data.replace("\'", "\"")
arreglo = json.loads(arr)
cedula = arreglo["Cedula"]
nombre = arreglo["Nombre"]
sql ='SELECT asi_id,asi_estado FROM asistencia WHERE asi_id = (select MAX(asi_id)from asistencia WHERE asi_cedula = %s)'
cursor.execute(sql,(cedula,))
datos = cursor.fetchone()
id = datos[0]
estado = datos[1]
if(cedula == cedula and estado == None or estado != "Entrada" ):
asistencia.lbestado.setText("Entrada")
estado1 = "Entrada"
sqli = 'INSERT INTO asistencia(asi_cedula,asi_nombre,asi_hora_e,asi_fecha,asi_estado)VALUES(%s,%s,%s,%s,%s)'
datos = (cedula,nombre,h,fecha,estado1)
cursor.execute(sqli,datos)
db.connection.commit()
else:
asistencia.lbestado.setText("Salida")
estado2 = "Salida"
sql2 = 'UPDATE asistencia SET asi_hora_s = %s, asi_estado = %s WHERE asi_cedula = %s AND asi_id = %s'
d2 = (h,estado2,cedula,id)
cursor.execute(sql2,d2)
db.connection.commit()
winsound.Beep(f,d)
time.sleep(2)
else:
image = qimage2ndarray.array2qimage(frame)
asistencia.lbvista.setPixmap(QPixmap.fromImage(image))
The objective is to keep the camera on all the time until the user decides to exit by closing the application.
This is a python code and list users that I only follow them. I would like to use the same list by adding a module for auto unfollowing:
.
.
.
def get_unfollowers(browser):
"""
Opens the profile, obtains the follower and following list
Returns the names of the users who are in the following list, but not in the follower list
"""
to_profile = browser.find_element_by_xpath("//a[contains(#href, '/{}')]".format(username))
to_profile.click()
sleep(3)
to_following = browser.find_element_by_xpath("//a[contains(#href, '/following')]")
to_following.click()
following_list = get_name(browser)
to_followers = browser.find_element_by_xpath("//a[contains(#href, '/followers')]")
to_followers.click()
followers_list = get_name(browser)
not_following_back = [user for user in following_list if user not in followers_list]
print(not_following_back) # prints a list with every name separated by a comma
def get_name(browser):
sleep(2)
scroll_box = browser.find_element_by_class_name('isgrP')
p_height, height = 0, 1
while p_height != height:
p_height = height
sleep(2)
height = browser.execute_script(
"arguments[0].scrollTo(0, arguments[0].scrollHeight); return arguments[0].scrollHeight;", scroll_box)
total_list = scroll_box.find_elements_by_tag_name('li')
names = [name.text for name in total_list if name.text != '']
close_dub = browser.find_element_by_xpath("/html/body/div[4]/div/div/div[1]/div/div[2]/button")
close_dub.click()
return names
get_unfollowers(browser)
This is the code that I wrote and worked to unfollow list I want
def do_unfolow(list):
for x in list:
print(x)
browser.get('https://www.instagram.com/'+x)
# tempy2 = browser.find_element_by_css_selector(".vBF20._1OSdk")
#if not tempy2:
tempy2 = browser.find_element_by_css_selector(".glyphsSpriteFriend_Follow")
#tempy2 = browser.find_element_by_css_selector("Igw0E.rBNOH.YBx95._4EzTm")
tempy2.click()
tempy2 = browser.find_element_by_xpath("//button[contains(text(), 'Unfollow')]")
tempy2.click()
sleep(10)
I have a code, that get selenium information and i need to print this information to the docx, but by template. Here i get information with help of print() (to set some part )
Stuyvesant High School
General Information
School Name:
Stuyvesant High School
Principal:
Mr. Eric Contreras
Principal’s E-mail:
ECONTRE#SCHOOLS.NYC.GOV
Type:
Regular school
Grade Span:
9-12
Address:
345 Chambers Street, New York, NY 10282
I printing this information in console, but i need print this information to the docx.
Here the part of code, where i print:
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
import openpyxl
import docx
from docx.shared import Pt
List = []
wb = openpyxl.load_workbook('D:\INSPR\Rating_100_schools\Top-100.xlsx')
sheet = wb['RI']
tuple(sheet['A1':'A100']) # Get all cells from A1 to A100.
for rowOfCellObjects in sheet['A1':'A100']:
for cellObj in rowOfCellObjects:
List.append(cellObj.value)
School_list_result = []
State = sheet.title
driver = webdriver.Chrome(executable_path='D:\chromedriver') #any path
def check_xpath(xpath):
try:
element = driver.find_element_by_xpath(xpath)
School_list_result.append(element.text)
except NoSuchElementException:
School_list_result.append("No data.")
def check_text(partial_link_text):
try:
element_text = driver.find_element_by_partial_link_text(partial_link_text)
School_list_result.append(element_text.get_attribute("href"))
except NoSuchElementException:
School_list_result.append("No data.")
def check_click(clicker):
try:
element_click = driver.find_element_by_partial_link_text(clicker)
element_click.click()
except NoSuchElementException:
print("No click.")
def get_url(url, _xpath, send_keys):
driver.get(url)
try:
_element = driver.find_element_by_xpath(_xpath)
_element.clear()
driver.implicitly_wait(10)
_element.send_keys(schools, send_keys)
_element.send_keys(u'\ue007')
driver.implicitly_wait(10)
except NoSuchElementException:
print("No data.")
for schools in List[98:100]:
#-----------------------------------------GREAT SCHOOLS-------------------------------------------
get_url("https://www.google.com/", '//*[#id="tsf"]/div[2]/div[1]/div[1]/div/div[2]/input'," " + State + " greatschools")
_clicker = driver.find_element_by_xpath('//*[#id="rso"]/div[1]/div/div[1]/a/h3').click()
check_xpath('//*[#id="hero"]/div/div[1]/h1') #School Name
check_xpath('/html/body/div[6]/div[8]/div/div[1]/div/div/div[2]/div[1]/div[2]/span[1]') #Principal
check_text('Principal email') #Principal’s E-mail
check_xpath('//*[#id="hero"]/div/div[2]/div[2]/div[3]/div[2]') #Grade Span
check_xpath('//*[#id="hero"]/div/div[2]/div[1]/div[1]/div[1]/div[1]/a/div/span[2]') #Address
check_xpath('/html/body/div[6]/div[8]/div/div[1]/div/div/div[2]/div[2]/span/a') #Phone
check_text('Website') #Website
check_xpath('//*[#id="hero"]/div/div[2]/div[1]/div[1]/div[1]/div[2]/a') #Associations/Communities
check_xpath('//*[#id="hero"]/div/div[2]/div[2]/div[1]/div/a/div[1]/div') #GreatSchools Rating
check_xpath('//*[#id="Students"]/div/div[2]/div[1]/div[2]') #Enrollment by Race/Ethnicity
#-----------------------------------------NCES-------------------------------------------
driver.implicitly_wait(10)
get_url("https://nces.ed.gov/search/index.asp?q=&btnG=Search#gsc.tab=0", '//*[#id="qt"]', " " + State)
check_click('Search for Public Schools - ')
driver.implicitly_wait(10)
check_xpath('/html/body/div[1]/div[3]/table/tbody/tr[4]/td/table/tbody/tr[7]/td[1]/font[2]') #School type
check_xpath('/html/body/div[1]/div[3]/table/tbody/tr[4]/td/table/tbody/tr[7]/td[3]/font') #Charter
check_xpath('/html/body/div[1]/div[3]/table/tbody/tr[12]/td/table/tbody/tr[3]/td/table/tbody/tr[2]/td/table/tbody')
#Enrollment by Gender
check_xpath('/html/body/div[1]/div[3]/table/tbody/tr[12]/td/table/tbody/tr[1]/td/table/tbody/tr[2]') #Enrollment by Grade
#-----------------------------------------USNEWS-------------------------------------------
driver.implicitly_wait(10)
url = "https://www.usnews.com/education/best-high-schools/new-york/rankings"
driver.get(url)
check_click(schools)
driver.implicitly_wait(10)
check_xpath('//*[#id="app"]/div/div/div/div[1]/div/div/div[2]/div[1]/div[2]/p[3]') #U.S.News Rankings
#-----------------------------------------PUBLIC REVIEW-------------------------------------------
driver.implicitly_wait(10)
get_url("https://www.google.com/", '//*[#id="tsf"]/div[2]/div[1]/div[1]/div/div[2]/input', " " + State + " publicschoolreview")
clicker = driver.find_element_by_partial_link_text('(2020)').click()
driver.implicitly_wait(10)
check_xpath('//*[#id="quick_stats"]/div/div[2]/ul/li[2]/strong') #Total # Students
check_xpath('//*[#id="total_teachers_data_row"]/td[2]') #Full-Time Teachers
check_xpath('//*[#id="quick_stats"]/div/div[2]/ul/li[3]/strong') #Student/Teacher Ratio
#-----------------------------------------PRINT INFOFMATION-------------------------------------------
print(" ---------------------------------------------------------------"+"\n",
" \033[1m", schools,"\033[0m"+"\n",
" ---------------------------------------------------------------"+"\n",
" \033[1mGeneral Information\033[0m "+"\n",
"\033[1mSchool Name:\n\033[0m",School_list_result[0]+"\n",
"\033[1mPrincipal:\n\033[0m",School_list_result[1]+"\n",
"\033[1mPrincipal’s E-mail:\n\033[0m",School_list_result[2]+"\n",
"\033[1mType:\n\033[0m",School_list_result[10]+"\n",
"\033[1mGrade Span:\n\033[0m",School_list_result[3]+"\n",
"\033[1mAddress:\n\033[0m",School_list_result[4]+"\n",
"\033[1mPhone:\n\033[0m",School_list_result[5]+"\n",
"\033[1mWebsite:\n\033[0m",School_list_result[6]+"\n",
"\033[1mAssociations/Communities:\n\033[0m",School_list_result[7]+"\n",
"\033[1mGreatSchools Summary Rating:\n\033[0m",School_list_result[8]+"\n",
"\033[1mU.S.News Rankings:\n\033[0m",School_list_result[14]+"\n",
" \033[1mSchool Details\033[0m"+"\n",
"\033[1mTotal # Students:\n\033[0m",School_list_result[15]+"\n",
"\033[1mFull-Time Teachers:\n\033[0m",School_list_result[16]+"\n",
"\033[1mStudent/Teacher Ratio:\n\033[0m",School_list_result[17]+"\n",
"\033[1mCharter:\n\033[0m",School_list_result[11]+"\n",
"\033[1mMagnet: \n\033[0m","No""\n",
" \033[1mEnrollment Data\033[0m"+"\n",
"\033[1mEnrollment by Race/Ethnicity: \n\033[0m",School_list_result[9]+"\n",
"\033[1mEnrollment by Gender: \n\033[0m",School_list_result[12]+"\n",
"\033[1mEnrollment by Grade: \n\033[0m",School_list_result[13]+"\n",
()
)
print()
School_list_result.clear()
What i need: print this result not into console by template, but into a docx by template.
And one more: if you know how to not using indexing (like: School_list_result[0]), please tell me.
I assume you are on a windows operating system just as I do, and know how to download python packages:
Install docx and python-docx modules (they are different, make sure you have installed both)
use the following code:
School_list_result = [
"Stuyvesant High School",
"Mr. Eric Contreras",
"ECONTRE#SCHOOLS.NYC.GOV",
"Regular school",
"9-12",
"345 Chambers Street, New York, NY 10282",
]
headers = [
"School Name: ",
"Principal: ",
"Principal's Email: ",
"Type: ",
"Grade Span: ",
"Address: ",
]
def print_into_one_doc():
import os
from docx import Document
from docx.shared import RGBColor
from docx.shared import Pt
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
# after you create a docx file, make sure you double click to open it, write some stuff, press ctrl + s, delete what you have written, press ctrl + s, close the document
# delete what you have written. Otherwise python-docx reports a Package Not Find Error.
p = input('hold shift key right click, copy and paste the file path of docx here: ')
if p[0] == '"' or p[0] == "'":
# validate path
p = p[1:-1]
p = os.path.abspath(p)
doc = Document(p)
h = doc.add_paragraph()
# make title align to center
h.paragraph_format.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
r = h.add_run(School_list_result[0])
# set title color
r.font.color.rgb = RGBColor(54, 95, 145)
# set title size
r.font.size = Pt(36)
doc.add_paragraph('\n')
su = doc.add_paragraph()
ru = su.add_run('General Information')
ru.font.size = Pt(30)
for i, d in enumerate(headers):
sp = doc.add_paragraph()
rp = sp.add_run(headers[i])
rp.bold = True
rp.font.size = Pt(23)
sm = doc.add_paragraph()
rm = sm.add_run(School_list_result[i])
rm.font.size = Pt(22)
rm.italic = True
doc.add_page_break()
doc.save(p)
print_into_one_doc()
If you have a list, which contains School_list_result, iterate it through, here is an example:
List_of_school_list_result = [
[
"Stuyvesant High School",
"Mr. Eric Contreras",
"ECONTRE#SCHOOLS.NYC.GOV",
"Regular school",
"9-12",
"345 Chambers Street, New York, NY 10282",
],
[
"Great Lake College",
"Mr. Jason Madunic",
"MADUNIC#SCHOOLS.VIC.GOV",
"Public school",
"6-12",
"167A High Street, Melbourne, VIC 3228",
],
]
headers = [
"School Name: ",
"Principal: ",
"Principal's Email: ",
"Type: ",
"Grade Span: ",
"Address: ",
]
def print_all_into_one_doc():
import os
from docx import Document
from docx.shared import RGBColor
from docx.shared import Pt
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
# after you create a new docx file, double click to open it, write some stuff, press ctrl + s, delete what you have written, press ctrl + s, close the document
# Otherwise python-docx reports a Package Note Find Error.
p = input('hold shift key right click, copy and paste the file path of docx here: ')
if p[0] == '"' or p[0] == "'":
# validate path
p = p[1:-1]
p = os.path.abspath(p)
doc = Document(p)
# iterate List of all school
for j in List_of_school_list_result:
h = doc.add_paragraph()
# make title align to center
h.paragraph_format.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
r = h.add_run(j[0])
# set title color: you can adjust any color of title here
r.font.color.rgb = RGBColor(54, 95, 145)
# set title size
r.font.size = Pt(36)
doc.add_paragraph('\n')
su = doc.add_paragraph()
ru = su.add_run('General Information')
ru.font.size = Pt(30)
for i, d in enumerate(headers):
sp = doc.add_paragraph()
rp = sp.add_run(headers[i])
rp.bold = True
rp.font.size = Pt(23)
sm = doc.add_paragraph()
rm = sm.add_run(j[i])
rm.font.size = Pt(22)
rm.italic = True
doc.add_page_break()
doc.save(p)
print_all_into_one_doc()
Let's make it simple, what you need to do is:
create a list named List_of_school_list_result, dump your data in, each of them should be one single record of a certain school.
in any location, create a new docx file, double click to open it, write some stuff, press ctrl + s, delete what you have written, press ctrl + s, close the document.
go to the directory where your docx file is, hold on shift, right click, copy as path.
make sure docx and python-docx are installed, run the code, when you are asked to input the path, paste it in from your clipboard. (Please make sure you use an absolute path, which is a full directory with root c, a relative path may not work).
PS: the reason that you have to open the docx file after create, is that Microsoft Word 2005+ docx file have 3 modes. first, if it's brand new after creation, it's in binary format. second, if we open it to edit, it generates a $cache.docx file as hidden into same level directory to ensure performance and secure data just in case of crash. third, if it's edited and saved, the format will be turned into XML, which is EDITABLE using python-docx module.
PS: the Result class below provides a clear way for creating List_of_school_list_result:
class Result:
def __init__(self, length):
self.l = length
self.res = []
self.col = []
def push(self, string):
self.col.append(string)
if(len(self.col) == self.l):
self.res.append(self.col)
self.col = []
def publish(self):
return self.res
r = Result(6) # pass in the length of the headers, then all you need, is to call `r.push()` over and over again. after that, assign it to `List_of_school_list_result`
r.push('school name 1')
r.push('principal name 1')
r.push('principal email 1')
r.push('school type 1')
r.push('grad span 1')
r.push('address 1')
r.push('school name 2')
r.push('principal name 2')
r.push('principal email 2')
r.push('school type 2')
r.push('grad span 2')
r.push('address 2')
List_of_school_list_result = r.publish()
Complete version of code:
headers = [
"School Name: ",
"Principal: ",
"Principal's Email: ",
"Type: ",
"Grade Span: ",
"Address: ",
]
class Result:
def __init__(self, length):
self.l = length
self.res = []
self.col = []
def push(self, string):
self.col.append(string)
if(len(self.col) == self.l):
self.res.append(self.col)
self.col = []
def publish(self):
return self.res
r = Result(len(headers))
# call r.push() over and over again, until all the string data is passed in.
''' for example
r.push('school name 1')
r.push('principal name 1')
r.push('principal email 1')
r.push('school type 1')
r.push('grad span 1')
r.push('address 1')
r.push('school name 2')
r.push('principal name 2')
r.push('principal email 2')
r.push('school type 2')
r.push('grad span 2')
r.push('address 2')
'''
List_of_school_list_result = r.publish()
def print_all_into_one_doc():
import os
from docx import Document
from docx.shared import RGBColor
from docx.shared import Pt
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
# after you create a new docx file, double click to open it, write some stuff, press ctrl + s, delete what you have written, press ctrl + s, close the document
# Otherwise python-docx reports a Package Note Find Error.
p = input('hold shift key right click, copy and paste the file path of docx here: ')
if p[0] == '"' or p[0] == "'":
# validate path
p = p[1:-1]
p = os.path.abspath(p)
doc = Document(p)
# iterate List of all school
for j in List_of_school_list_result:
h = doc.add_paragraph()
# make title align to center
h.paragraph_format.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
r = h.add_run(j[0])
# set title color: you can adjust any color of title here
r.font.color.rgb = RGBColor(54, 95, 145)
# set title size
r.font.size = Pt(36)
doc.add_paragraph('\n')
su = doc.add_paragraph()
ru = su.add_run('General Information')
ru.font.size = Pt(30)
for i, d in enumerate(headers):
sp = doc.add_paragraph()
rp = sp.add_run(headers[i])
rp.bold = True
rp.font.size = Pt(23)
sm = doc.add_paragraph()
rm = sm.add_run(j[i])
rm.font.size = Pt(22)
rm.italic = True
doc.add_page_break()
doc.save(p)
print_all_into_one_doc()
First of all I'm a rookie in programming.
I'm trying to export MySQL database to excel format with python3. I'm using openpyxl for it. Now I have a interesting error in excel. If I run the code but the SQL query is small (around 1000 rows) then I do not have an error when opeening the excel, but if it is bigger (>30k rows) when I try to open the excel I have an error:
error135840_01.xmlErrors were detected in file 'C:\Users\id022504\PycharmProjects\GetMySQLdata\Interface planning _mau.xlsx'Removed Records: Formula from /xl/worksheets/sheet1.xml part
Interesting enough when I use Open XML SDK to open the excel file it points that the issue is in the color:
enter image description here
enter image description here
Bellow is the code:
import mysql.connector
import openpyxl
from openpyxl import Workbook
from openpyxl.styles import Border, Side, Font, Alignment
import datetime
import os
from openpyxl.worksheet import Worksheet
mydb = mysql.connector.connect(
host="10.10.10.10",
user="user",
passwd="password"
)
#Funcao para por as colunas com auto size
def auto_column_resize(worksheet):
for col in worksheet.columns:
max_length = 0
column = col[0].column # Get the column name
for cell in col:
try: # Necessary to avoid error on empty cells
if len(str(cell.value)) > max_length:
max_length = len(cell.value)
except:
pass
adjusted_width = (max_length + 2) * 1.2
if adjusted_width <= 95:
worksheet.column_dimensions[column].width = adjusted_width
else:
worksheet.column_dimensions[column].width =95
return worksheet
# definir path
path='C:/Users/'
# definir path para arquivo
path_arquivo='C:/Users/Arquivo/'
#definir tamanho do arquivo
arquivo_file_size = 26
# Abrir ficheiro actual e guardar nos arquivos
current_wb = openpyxl.load_workbook(path+"Interface planning.xlsx")
current_ws = current_wb["Ports allocation"]
if int(datetime.datetime.now().isocalendar()[1]) >9:
current_wb.save("{0}/Interface planning_{1}{2}.xlsx".format(path_arquivo, str(int(datetime.datetime.now().isocalendar()[0])),str(int(datetime.datetime.now().isocalendar()[1]))))
else:
#introduce 0 in the week so it can calculate later which file is the oldest
current_wb.save("{0}/Interface planning_{1}0{2}.xlsx".format(path_arquivo, str(int(datetime.datetime.now().isocalendar()[0])),str(int(datetime.datetime.now().isocalendar()[1]))))
#Abrir SQL e comando
mycursor = mydb.cursor()
mycursor.execute("SELECT hostname, hardware, port_label, ifHighSpeed, ifAdminStatus, ifOperStatus, ifAlias FROM `observium`.`ports` JOIN `observium`.`devices` ON `observium`.`devices`.device_id = `observium`.`ports`.device_id WHERE (port_label LIKE 'xe-%' or port_label LIKE 'et-%' or port_label LIKE 'ge-%' or port_label LIKE '%Ethernet%') and port_label NOT RLIKE '[.][1-9]' ORDER BY hostname, port_label;")
#Meter em tupel os dados recebidos pela base de dados
myresult = mycursor.fetchall()
header = mycursor.column_names
#Criar workbook
new_wb = Workbook()
#Criar worksheet
new_ws = new_wb.active
new_ws.title = "Ports allocation"
############################################## Meter dados SQL em excel ##########################################
#Add header information and formating
new_ws.append(header)
new_ws["H1"].value = "Person assigned"
for format_row in new_ws:
for i in range(8):
format_row[i].font = Font(bold=True)
#Add content from SQL to excel
for row in myresult:
new_ws.append(row)
new_ws.auto_filter.ref = "A:H"
#Verificar o estado da interface e colocar a pessoa responsavel se a interface esta administrativamente e operacionalmente em baixo
for current_ws_row in current_ws:
if current_ws_row[7].value is not None:
for new_ws_row in new_ws:
if (new_ws_row[4].value != "up" or new_ws_row[5].value != "up") and current_ws_row[0].value == new_ws_row[0].value and current_ws_row[2].value == new_ws_row[2].value :
new_ws_row[7].value= current_ws_row[7].value
new_ws_row[6].value = current_ws_row[6].value
for format_row in new_ws:
for i in range(8):
format_row[i].border = Border(right=Side(style='thin'),)
#Meter o worksheet bonitinho
new_ws = auto_column_resize(new_ws)
new_ws.sheet_view.zoomScale = 85
c=new_ws['D2']
new_ws.freeze_panes = c
wrap_alignment = Alignment(wrap_text=True)
for row in new_ws.iter_rows():
for cell in row:
cell.alignment = Alignment(shrink_to_fit=True)
#Salvar workbook
new_wb.save(path+"Interface planning.xlsx")
#remover ficheiro no arquivo
count_files=0
#infinite time
file_to_delete = '299952'
for directory in os.walk(path_arquivo):
for file in directory[2]:
count_files = count_files+1
if str(file)[-11:-5] < file_to_delete:
file_to_delete = str(file)[-11:-5]
if count_files > arquivo_file_size:
os.remove(path_arquivo+'Interface planning_'+file_to_delete+'.xlsx')
I found the issue, in one of the cells there was the "=" symbol and somehow excel identify it as a formula. To solve the issue I just clean up the "=".
import re
try:
new_ws_row[7].value = re.sub("=", "", new_ws_row[7].value)
except:
pass
Extending on the awesome answer provided by Pedro on 12th December 2018.
I found below to be an efficient way to address trouble columns containing values starting with an equal sign when trying to use Openpyxl
for cell in ws['R']:
if "=" in str(cell.value):
cell.value = re.sub('^=', ' =', cell.value)