# GBK to UTF-8 CSV Converter Script Generator for China ERP Data

> Source: https://netray.co/tools/china-csv-gbk-utf8-converter-script-generator
> Publisher: Netray (netray.co), AI and integration engineering for ERP and manufacturing systems.
> Section: Free Tools

## Short answer

Generates a ready-to-run Python script that converts CSV files between GBK, GB18030 and UTF-8 so Chinese ERP imports and exports do not turn into garbled text.

## Category

developer

## Region

China

## Audience

- ERP developer
- Data migration lead
- Integration engineer

## Tool

**Kind:** template

**Output:** code

**Language:** python

**Fields:**

#### Input file path

**Key:** input_file

**Type:** text

**Default:** vendor_master_export.csv

#### Output file path

**Key:** output_file

**Type:** text

**Default:** vendor_master_utf8.csv

#### Source encoding

**Key:** source_enc

**Type:** select

**Options:**

- gb18030
- gbk
- utf-8
- utf-8-sig

**Default:** gb18030

#### Target encoding

**Key:** target_enc

**Type:** select

**Options:**

- utf-8
- utf-8-sig
- gb18030
- gbk

**Default:** utf-8-sig

#### Delimiter

**Key:** delimiter

**Type:** select

**Options:**

- ,
- ;
- |

**Default:** ,

#### On bad bytes

**Key:** error_mode

**Type:** select

**Options:**

- strict
- replace

**Default:** strict

**Blocks:**

#### convert_encoding.py

**Body:** import csv
import sys

INPUT_FILE = "{{input_file}}"
OUTPUT_FILE = "{{output_file}}"
SOURCE_ENC = "{{source_enc}}"
TARGET_ENC = "{{target_enc}}"
DELIMITER = "{{delimiter}}"
ERRORS = "{{error_mode}}"

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

**Body:** # Print the first 3 rows of the converted file to confirm Chinese text is readable
import csv
with open("{{output_file}}", "r", encoding="{{target_enc}}", newline="") as f:
    for i, row in enumerate(csv.reader(f, delimiter="{{delimiter}}")):
        print(row)
        if i >= 2:
            break

**Notes:** Pick 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.

## Content

**Intro:** 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.

**Sections:**

#### How to use the script

**Body:** 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

**Body:** 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.

**Bullets:**

- 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

**Body:** 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

**Body:** 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.

**Cta:** If you migrate master data into a Chinese ERP regularly, Netray can help build a repeatable, checked load pipeline instead of one-off scripts.

**Faq:**

#### Why do Chinese characters look garbled in my CSV?

**Answer:** 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?

**Answer:** 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?

**Answer:** 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?

**Answer:** 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.

## Search terms

gbk to utf-8 csv python, gb18030 csv converter, chinese characters garbled csv erp, kingdee import csv encoding, convert csv encoding python script, utf-8 bom chinese excel csv, china erp data migration encoding, mojibake chinese csv fix

---
Talk to an engineer: https://netray.co/contact?intent=erp_ai | Machine catalog: https://netray.co/agent/catalog.json
