GBK to UTF-8 CSV Converter Script Generator for China ERP Data
Chinese ERP exports and legacy databases often use GBK or GB18030, while modern tools expect UTF-8. A mismatch turns supplier names and part descriptions into unreadable characters. This generator writes a short Python script that converts a CSV file with the encodings you choose.
Fill in
convert_encoding.py
import csv
import sys
INPUT_FILE = "vendor_master_export.csv"
OUTPUT_FILE = "vendor_master_utf8.csv"
SOURCE_ENC = "gb18030"
TARGET_ENC = "utf-8-sig"
DELIMITER = ","
ERRORS = "strict"
def convert():
rows = 0
with open(INPUT_FILE, "r", encoding=SOURCE_ENC, errors=ERRORS, newline="") as src:
reader = csv.reader(src, delimiter=DELIMITER)
with open(OUTPUT_FILE, "w", encoding=TARGET_ENC, errors=ERRORS, newline="") as dst:
writer = csv.writer(dst, delimiter=DELIMITER, quoting=csv.QUOTE_MINIMAL)
for row in reader:
writer.writerow(row)
rows += 1
return rows
if __name__ == "__main__":
try:
count = convert()
print("Converted", count, "rows from", SOURCE_ENC, "to", TARGET_ENC)
except UnicodeError as exc:
print("Encoding error:", exc)
print("Try source encoding gb18030, which is a superset of gbk.")
sys.exit(1)Quick check of the result
# Print the first 3 rows of the converted file to confirm Chinese text is readable
import csv
with open("vendor_master_utf8.csv", "r", encoding="utf-8-sig", newline="") as f:
for i, row in enumerate(csv.reader(f, delimiter=",")):
print(row)
if i >= 2:
breakPick gb18030 as the source when unsure because it reads everything gbk does. Use utf-8-sig as the target if the file will be opened in Excel, which relies on the byte order mark to detect UTF-8. Check whether your ERP import wizard wants UTF-8, GBK or Unicode text, as versions differ.
Master data load review
Optional: tell us your source and target systems and we will outline a validated migration load approach.
Optional. The tool and every export work without this. No spam.
How to use the script
Fill in the input and output file names, choose the source and target encoding and pick the delimiter. The generated script uses only the Python standard library, so it runs on a plant server or a laptop without installing anything. Run it with python convert_encoding.py in the same folder as your file. The second block prints the first three rows so you can confirm that Chinese characters render properly before loading the file into the ERP.
Which encoding to choose
GBK is the older double byte encoding covering simplified Chinese. GB18030 is the national standard that extends GBK and is fully compatible with it for existing characters, so reading with gb18030 is the safer choice. UTF-8 is the default for most web services and databases. Excel on Windows needs a byte order mark to treat a CSV as UTF-8, which is why utf-8-sig is the default target here.
- Unknown source: try gb18030 first
- Excel opening: use utf-8-sig
- REST or database load: use utf-8
- Legacy import wizard: check if it needs GBK
Reading the result
If conversion raises a UnicodeError the file is probably not in the encoding you named. If it succeeds but shows odd symbols, the file may have been decoded wrongly earlier and saved again, which corrupts data permanently. In that case ask for a fresh export from the source system rather than trying to repair the damaged file.
Common mistakes
Do not open the CSV in Excel and save it again, because Excel may change encoding and strip leading zeros from codes such as part numbers or tax IDs. Do not use the replace error mode for master data loads, because replaced characters become question marks that will reach production. Keep the original file untouched and write to a new name.
Frequently Asked Questions
Why do Chinese characters look garbled in my CSV?
The file was written in one encoding and read in another, typically GBK read as UTF-8 or the reverse. Reconvert from the true source encoding, with gb18030 being the safe first guess for Chinese system exports.
Is GB18030 the same as GBK?
GB18030 is a superset. It reads all GBK content and adds further characters, including a full mapping of Unicode. Decoding with gb18030 therefore works for GBK files and is the more robust option.
Does Excel read UTF-8 CSV files correctly?
Excel on Windows usually needs a byte order mark to detect UTF-8 in a CSV. Writing the file with utf-8-sig adds that marker so Chinese text shows correctly when double clicking the file.
Does the script upload my data anywhere?
No. This page only generates the script text in your browser. The script itself runs locally on your machine and reads and writes local files only.
If you migrate master data into a Chinese ERP regularly, Netray can help build a repeatable, checked load pipeline instead of one-off scripts.
Related Tools
China GL Voucher Trial Balance SQL Generator
Builds a trial balance SQL query by account from a voucher line table, with opening, period movement and closing columns.
Country & TaxChina Accounting Standards Chart of Accounts Reference
First-level account codes and English names used in Chinese statutory books, for mapping to a group chart of accounts during an ERP rollout.
ERP Migration & SelectionChina ERP Implementation Cost Estimate Worksheet
Build a line-item budget for an ERP project in China with licences, implementation days, fapiao and tax interface, data migration and contingency.
Compliance & ContractsChina ERP Data Security and Compliance Assessment
Ten questions covering data location, cross-border transfer, personal information, classified protection and access control for an ERP running in China.
More Developer Tools tools
See all- China Unified Social Credit Code Validator Script Generator
- SAP Sales Order ABAP SELECT Generator (VBAK, VBAP, VBFA)
- SAP Sales Order Create BAPI ABAP Generator (BAPI_SALESORDER_CREATEFROMDAT2)
- SAP ABAP Open Items SELECT Generator
- SAP ACDOCA SQL Query Generator
- SAP QM Inspection Lot ABAP SELECT Generator
- SAP Quality Notification Pareto SQL Query Generator
- SAP QM Usage Decision BAPI Skeleton
- ABAP Custom Exception Class Generator