Encoding CSV File With Arabic Content

Encoding CSV File With arabic content

You need to convert your CSV file in UTF-8 or process your string using utf8_encode.
Make sure your MySQL table is also in UTF-8

CSV file with Arabic characters is displayed as symbols in Excel

This is a problem I face frequently with Microsoft Excel when opening CSV files that contain Arabic characters. Try the following workaround that I tested on latest versions of Microsoft Excel on both Windows and MacOS:

  1. Open Excel on a blank workbook

  2. Within the Data tab, click on From Text button (if not
    activated, make sure an empty cell is selected)

  3. Browse and select the CSV file

  4. In the Text Import Wizard, change the File_origin to "Unicode (UTF-8)"

  5. Go next and from the Delimiters, select the delimiter used in your file e.g. comma

  6. Finish and select where to import the data

The Arabic characters should show correctly.

How to open a CSV file in excel with arabic in it

  1. Rename File Extension with Arabic Character from .csv to txt say MS DOS.
  2. Here is the sample file
    arabic 3

When you first save the File from csv to txt after renaming it, a pop up dialog will appear
arabic2

3 Click cancel then a dialog box will appear

arabic2


  1. Save the txt file in Dir and rename to csv.

    Here you will get choices for arabic characters.Arabic 708.720, 28596

  2. save the file and rename to txt, it opens with proper characters as shown below. But please ensure that , separation character is maintained, Some adjustment at line breaks and page may be required

arabic1

How to a read CSV file that contains Arabic lines using Python

The python 2 csv module doesn't handle unicode encodings well. The best solution is to start using python 3 which has integrated unicode and is well-suited for multi-language programming. If you need to stick with python 2, the unicodecsv module (pip install unicodecsv) is a drop-in replacement for csv that handles non-ascii files.

# -*- coding: utf-8 -*-
import sys

try:
import unicodecsv as csv
except ImportError:
sys.stderr.write(
"`sudo pip install unicodecsv` for unicode csv support\n")
exit(1)

with open(u'testfile.csv', "rb") as csvfile:
reader = csv.reader(csvfile, encoding="utf-8-sig")
for row in reader:
print u", ". join(row)


Related Topics



Leave a reply



Submit