v2
import pandas as pd
import re
# Sửa lỗi unicodeescape bằng cách dùng raw string (r'')
input_path = r'C:\path\to\your\file.xlsx'
output_path = r'C:\path\to\your\result.xlsx'
def identify_cjk(text):
text = str(text)
if re.search(r'[\uac00-\ud7af]', text): return "Tiếng Hàn"
if re.search(r'[\u3040-\u309f\u30a0-\u30ff]', text): return "Tiếng Nhật"
if re.search(r'[\u4e00-\u9fff]', text): return "Tiếng Trung"
return "Khác"
try:
df = pd.read_excel(input_path)
# Giả sử cột dữ liệu tên là 'Content'
df['Language'] = df['Content'].apply(identify_cjk)
df.to_excel(output_path, index=False)
print("Xử lý thành công!")
except Exception as e:
print(f"Lỗi rồi: {e}")
v1
import pandas as pd
import re
def detect_cjk(text):
text = str(text)
# Dải Unicode cho tiếng Hàn (Hangul)
if re.search(r'[\uac00-\ud7af]', text):
return "Tiếng Hàn"
# Dải Unicode cho tiếng Nhật (Hiragana & Katakana)
if re.search(r'[\u3040-\u309f\u30a0-\u30ff]', text):
return "Tiếng Nhật"
# Dải Unicode cho tiếng Trung (Hanzi)
if re.search(r'[\u4e00-\u9fff]', text):
return "Tiếng Trung"
return "Ngôn ngữ khác/Tiếng Anh"
def process_excel(input_file, output_file, column_name):
# Đọc file Excel mà không cần mở ứng dụng Excel
df = pd.read_excel(input_file)
# Tạo cột mới để lưu kết quả xác nhận ngôn ngữ
df['Xac_Nhan_Ngon_Ngu'] = df[column_name].apply(detect_cjk)
# Lưu kết quả ra file mới
df.to_excel(output_file, index=False)
print(f"Đã xử lý xong! Kết quả lưu tại: {output_file}")
# --- CẤU HÌNH TẠI ĐÂY ---
file_vao = 'danh_sach.xlsx' # Tên file gốc của bạn
file_ra = 'ket_qua_ngon_ngu.xlsx' # Tên file sau khi xử lý
cot_can_check = 'Noi_Dung' # Tên tiêu đề cột chứa văn bản
process_excel(file_vao, fil
e_ra, cot_can_check)