Don't change the business codes in dropdown lists when translating Excel

Excel translation: data validation formulas that are mistranslated will make the rules fail. This article explains the difference between validation definitions and display text, and gives an example of extracting validation metadata with openpyxl, along with edge-case handling and manual acceptance criteria.

Key Points of This Article

  • Data validation formula1 values are often backend status codes, and directly translating inline enumerations would break the business logic.
  • openpyxl does not evaluate validation rules when reading or writing, but Excel clients still enforce them strictly, and the tool will not intercept accidental changes to formula1.
  • Usually only UI text such as error, errorTitle, prompt, and promptTitle is translated; enumeration values are locked by default.
  • showDropDown=True means hiding the dropdown arrow in Excel and LibreOffice, so do not assume the setting is inverted when configuring it.

Multilingual Excel files often look fine after translation, yet users hit errors in dropdown menus, or the system fails to recognize options after submission. These problems usually stem from a translation workflow that confuses "data validation formulas" with "displayed cell content." This article is for localization and operations staff who handle Excel files containing dropdown lists. It explains which content should be locked and which should be translated, and provides a Python approach for extracting validation metadata along with manual acceptance criteria.

All examples here use synthetic data. Before processing important files, keep the original, and review them against the boundaries and acceptance items described in the text.

How to translate multilingual Excel without breaking dropdown lists? One-sentence conclusion

First lock down the business codes of the dropdown options, and only translate the prompt and error messages; after confirming there is a mapping relationship, then replace the enum values.

Your situationRecommended approachReason
Dropdown lists are inline enumerations (formula1 in the form "A,B,C")Lock formula1, do not send for translationThese strings are often backend status codes, and translating them would break business logic
Prompts and error messages shown to usersTranslate error, errorTitle, prompt, promptTitleThese four properties are the user-facing UI text
Dropdown source references another worksheet range (starting with =)Keep the reference and verify the source rangeAfter the source range is wholly replaced or renamed, validation will fail
Already have a reliable bilingual enumeration mapping tableReplace with the valid enumeration values corresponding to the target languageOnly replacing after confirming the mapping relationship ensures options are correctly recognized
Validator not bound to any cell rangeFilter out during the preprocessing stageAccording to the openpyxl official documentation, this type of validator is ignored when saved

Verifying the Essential Difference Between Formulas and UI Copy

Excel's Data Validation is essentially a set of metadata rules that define which inputs are valid. Before translating, you need to distinguish between two types of content.

According to openpyxl Official Documentation, the library "neither enforces nor evaluates" these rules when reading and writing .xlsx files; this is only the behavior of the Python library. In the Excel client, the validation rules are still strictly enforced.

  • When reading files: The DataValidation object is merely an in-memory mapping of the XML structure, and it will not tell you whether the current cell value is compliant.
  • When translating: The tool will not automatically intercept erroneous modifications you make to formula1; this is precisely where the risk lies.

type="list"'s validators usually come from two sources:

  1. Inline string lists: comma-separated and written directly inside formula1. This kind of content is the most easily damaged by machine translation, because in XML it is just plain text nodes.
  2. Range references: such as =Sheet2!$A$1:$A$10. Relatively safe, but if the source range is replaced or renamed, validation will fail in the same way.

The key to distinguishing the two is checking whether formula1 starts with an equals sign.

Additionally, the four attributes error, errorTitle, prompt, and promptTitle are the actual user-facing interface text and should be included in the translation scope. Enum values in formula1 are locked by default.

There is one more counterintuitive detail: the official openpyxl documentation explicitly states that showDropDown=True actually means "hide the dropdown arrow" in Excel and LibreOffice, the opposite of the usual boolean meaning. When translating or refactoring configuration, never modify this parameter on assumption.

Synthetic Example: Correct Extraction and Boundary Protection

Suppose the source file has an "Order Status" column whose validation formula is the inline list "NEW,PROCESSING,SHIPPED", with an English error message. The correct handling is: keep formula1 unchanged (replace it only when an explicit bilingual enumeration mapping table exists), translate error into the target language, and make sure boolean flags such as allow_blank are not modified accidentally. This example builds its data entirely in memory, so no external Excel file is needed, and it can run directly in a local Python environment.

The following edge cases require special attention:

  • Quoted strings containing commas: e.g. ""Yes, sure"","No"". If you simply split by commas, you get three fragments instead of two valid options.
  • Defined names (Named Range): formula1 references a name rather than a direct range, and the string contains neither ! nor a comma, so it is easily mistaken for plain text. The handling approach is to check before parsing whether it matches the naming convention. If it does, skip translating the content and only record the reference for manual review.
  • Data validators not bound to a cell range: According to the openpyxl documentation, these are ignored on save, so they should be filtered out during preprocessing to avoid meaningless translation of invalid rules.

Safely Extracting Validation Metadata with openpyxl

The following example shows how to construct a workbook with list validation in memory, and how to extract the fields that need translation and the fields that need to be locked. For the properties and behavior of data validation, refer to openpyxl official documentation. Running it in the openpyxl>=3.1.0 environment is recommended. The example contains no network requests, shell commands, credential usage, or file overwrite operations. All assertions are based on the expected state of in-memory objects and are used to verify the extraction logic.

from openpyxl import Workbook
from openpyxl.worksheet.datavalidation import DataValidation

def extract_validation_metadata():
    # 合成示例:在内存中构造含列表验证的工作簿,无需外部文件
    wb = Workbook()
    ws = wb.active
    dv = DataValidation(
        type="list",
        formula1='"NEW,PROCESSING,SHIPPED"',
        allow_blank=True
    )
    dv.error = "Invalid status code"
    dv.prompt = "Select order status"
    ws.add_data_validation(dv)
    dv.add("A1:A10")

    extracted = []
    for validator in ws.data_validations.dataValidation:
        # 跳过未绑定范围的验证器,此类验证器保存时会被忽略
        if not validator.sqref:
            continue

        is_inline_list = (
            validator.type == "list" 
            and validator.formula1 
            and not validator.formula1.startswith("=")
        )

        record = {
            "sqref": str(validator.sqref),
            "formula1_locked": validator.formula1 if is_inline_list else None,
            "translatable_error": validator.error,
            "translatable_prompt": validator.prompt,
            "is_reference": validator.formula1.startswith("=") if validator.formula1 else False
        }
        extracted.append(record)

    # 预期输出校验:验证提取逻辑符合设计预期
    assert len(extracted) == 1
    assert extracted[0]["formula1_locked"] == '"NEW,PROCESSING,SHIPPED"'
    assert extracted[0]["translatable_error"] == "Invalid status code"
    assert extracted[0]["is_reference"] is False
    return extracted

# 注意:此函数需在本地环境执行,此处仅作结构展示,未实际运行

The core decision in this code lies in identifying is_inline_list. Only when it is confirmed to be an inline list is formula1 marked as a locked field. For reference-type validation, the is_reference flag reminds downstream processes that the field may need special regional mapping handling rather than text translation.

Assertion statements only verify the extraction logic. Real production files may contain complex cases such as overlapping validators and formulas containing escape characters, so the robustness of parsing needs to be strengthened on this basis.

📊 Core Comparison: Handling of the Three Types of Verification Content

TypeIdentifying featuresHandling methodMain risks
Inline listformula1 is a comma-separated stringLock formula1, translate the prompt and error copyMachine translation can damage business codes, and quoted strings containing commas are easily split incorrectly.
Range referenceformula1 starts with =, such as =Sheet2!$A$1:$A$10Keep citations, verify source regionsVerification fails after the source area is replaced or renamed
Defined nameformula1 is the name, without ! and without a commaSkip content translation, record citation relationshipsEasily mistaken for ordinary text
Custom typetype is custom, formula1 contains functionsLocked as a whole, internal contents not parsedThe function's logic is complex, so automatic parsing is unreliable.

🎯 Which approach suits you?

If you...

1. Business tables containing inline dropdown lists need translation

Lock formula1. Translate only the four UI text attributes, such as error and prompt.

2. Having a reliable bilingual enumeration mapping table

Once the mapping relationships have been confirmed, the enumeration values can be replaced with valid options in the target language, and each item can then be tested in the target-language version of the Excel file.

3. Dropdown source references another worksheet

Keep the reference relationship, and manually verify after translation whether the source range has been altered.

4. Validating with Custom Types or Complex Function Formulas

Do not hand this off to an automated tool for parsing; route it directly to the manual review queue.

Acceptance Criteria and Boundaries for Manual Review

Automated extraction can only solve the problem of structure recognition; the quality of the deliverables still has to be controlled through acceptance testing. The table below lists typical anomalies and the handling decisions for them. The values in the table are custom thresholds for a synthetic example only, not industry standards, and should be adjusted to the specific business when used.

Observe the phenomenonAutomated decision-makingManual review trigger conditions
formula1 contains more than 3 comma-separated itemsMarked as locked, not sent for translationNumber of items over 20 or length of a single item over 50 characters
The error/prompt field is an empty stringSkip translation, keep empty valueOther validators on the same worksheet have non-empty prompts
formula1 External Workbook ReferencesMarked as external dependencyAny external reference requires manual confirmation of its path.
The validator sqref contains discontinuous regionsNormal extraction, keep the original region representationNecessity of review when the number of zones exceeds 5 groups
type is custom and formula1 contains a functionLocked as a whole, internal contents not parsedTrigger an alert when the function name is not in the whitelist.
showDropDown parameter existsKeep the original value; do not negate it.User feedback: the dropdown arrow displays abnormally

It needs to be made clear that the code above only completes metadata extraction; it does not amount to end-to-end verification of the translation's effect. Genuine acceptance requires actually opening the file in the target-language version of Excel and testing whether the dropdown menus pop up correctly, whether selecting a value triggers the error prompts as expected, and whether the backend system can correctly receive the submitted values.

Runtime entry point for in-memory samples

The following code runs after the function above, using only synthetic data and not reading any customer files.

result = extract_validation_metadata()
assert result[0]["sqref"] == "A1:A10"

❓ Frequently Asked Questions (FAQ)

1. Does openpyxl check whether dropdown list input is valid?

No. According to the official openpyxl documentation, the library does not enforce or evaluate validation rules when reading or writing .xlsx, but the rules are still strictly enforced in the Excel client.

2. Can the options in a dropdown list be translated directly?

It is not recommended. Inline enumerations often correspond to backend status codes, so translating them directly would break the business logic. Leaving them untouched entirely, however, may cause target-language users to see English options. The safer approach is to lock formula1 and translate only the prompts and error messages, or to replace the options with valid enumeration values in the target language once the mapping relationship has been confirmed.

3. Which attributes need to be translated?

The four attributes error, errorTitle, prompt, and promptTitle are user-facing interface text and should be included in the translation scope.

4. Can the showDropDown parameter be inverted to adjust the display?

No. The openpyxl official documentation explicitly states that showDropDown=True indicates hiding the dropdown arrow in Excel and LibreOffice, which is the opposite of the usual boolean semantics, so this needs to be carefully confirmed before making any changes.

📝 Summary

When translating an Excel file that contains dropdown lists, the key is to first distinguish "business codes" from "interface text": keep the codes locked, translate the text, and check the reference relationships manually. After translation, you also need to actually test the dropdowns and error messages in the target-language version of the Excel file.

Try it now: upload a document and start translating right away, with the original layout preserved.

Updated 2026-11-29