Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Python script to replace Western Arabic numerals with Eastern Arabic numerals in Excel sheet containing Arabic script
import openpyxl
import sys, re
def ReplaceArabicNumerals(inbook,outbook,sheet):
wb = openpyxl.load_workbook(inbook)
sht = wb[sheet]
arabicCells = SearchForArabic(sht)
arabicNumerals = [(u'\u0660','0'),
for cell in arabicCells:
if cell.value is not None:
val = unicode(cell.value)
for k, v in arabicNumerals:
val = val.replace(v, k)
cell.value = val
def SearchForArabic(worksheet):
arabicCells = []
pattern = re.compile(u'[\u0600-\u06FF]')
for row in worksheet:
for cell in row:
val = unicode(cell.value)
if is not None:
return arabicCells
if __name__ == '__main__':
ReplaceArabicNumerals(sys.argv[1], sys.argv[2], sys.argv[3])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.