1. Recently, I am using nopCommerce, which is an e-commerce framework written based on C#. It is not accurate to say framework, but almost a complete set of e-commerce platform source code, which can be directly deployed and used. Just because it is a foreign software, so in the Chinese and wechat Alipay payment support, need to install additional plug-ins.

2. The Sinicization of nopCommerce is not complicated. Each language corresponds to an XML file. The problem is that if you use the latest version of 4.10, you can hardly find the corresponding Chinese files, so you end up looking for an old version and filling in the missing Chinese fields.

3. The problem is that there are about 6,000 fields. Compare and see which field is in English but not in Chinese, and then add the corresponding Chinese value of this field, so the increase of one record after another, just think about it, I shudder. This is the time to use gadgets.

4, First import all data into Excel, and then sort by field name. Generally speaking, if both Chinese and English are available, it should be sorted in pairs as follows:



If only Chinese (this field is in the old version but deleted in the new version) or only English (this field is new in the new version), it will look like the following:



5. Then it’s time for Python. Excel mainly uses XLRD and XLWT packages, which are easy to remember and can be regarded as the abbreviation of ExcelRead and ExcelWrite. The main tasks are to read which open_workbook(file_name), which sheet_by_name(sheet_name) file, which row(row_NO), which col(col_NO) column, Which cell(row_no,col_no), so to loop through, you have to know how many rows dot nrows or how many columns dot ncols there are. The write API is relatively simple, basically creating an empty Excel object xlwT.workbook (), adding a thin add_sheet(sheet_name) to the file, and writing data write(row_no,col_no,value), Which file to save(file_name) last. Here is an example of a shorthand:

import xlrd
import xlwt

data_source_file_name = "LocaleStringResource.xlsx"
data_source_sheet_name = "LocaleStringResource"
target_source_file_name = "20181015-LocaleStringResource.xls"
target_source_sheet_name = "Sheet1"data_source = xlrd.open_workbook(data_source_file_name) table_source = data_source.sheet_by_name(data_source_sheet_name)  data_target = xlwt.Workbook() table_target = data_target.add_sheet(target_source_sheet_name) nrows_source = table_source.nrows recored_id =""
record_language_id = ""
record_resource_name = ""
record_resource_value = ""

source_row_no = 1
target_row_no = 0

while source_row_no < nrows_source:
    recored_id = table_source.row(source_row_no)[0].value
    record_language_id = table_source.row(source_row_no)[1].value
    record_resource_name = table_source.row(source_row_no)[2].value
    record_resource_value = table_source.row(source_row_no)[3].value

    if nrows_source - source_row_no == 1:
        table_target.write(target_row_no,0,recored_id)
        table_target.write(target_row_no,1,record_language_id)
        table_target.write(target_row_no,2,record_resource_name)
        table_target.write(target_row_no,3,record_resource_value)
        break

    c_record_resource_name = table_source.row(source_row_no+1)[2].value 

    if record_resource_name == c_record_resource_name:
        if nrows_source - source_row_no == 2:
            break
        source_row_no = source_row_no + 2
    else:
        table_target.write(target_row_no,0,recored_id)
        table_target.write(target_row_no,1,record_language_id)
        table_target.write(target_row_no,2,record_resource_name)
        table_target.write(target_row_no,3,record_resource_value)
        target_row_no = target_row_no + 1

    source_row_no = source_row_no + 1

data_target.save(target_source_file_name)
Copy the code

6. Once you have installed the Python environment and the package, create a new file called xxx.py, write the above code, and python3 xxx.py directly from the console will generate a new Excel file that you need. Powerful third-party packages + simplicity and speed have always been a Python killer. May you have such a weapon.



Read the XLRD and XLWT official documentation