You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Excel Interop:Cells.Formula无法跨语言自动翻译公式的问题求助

Fixing Cross-Language Formula Errors in Excel (English/French Versions)

The Issue You're Facing

When you use the Formula property to set a formula like this:

xlWorkSheet.Cells[i, "J"].Formula = string.Format("= MEAN(J3:J{0})", i - 1);

You run into a #NAME? error in French Excel. Even though the Formula property is supposed to auto-translate English function names to the local Excel language, it fails here—likely because MEAN is an alias for the standard AVERAGE function, and Excel's translation engine doesn't handle aliases reliably across locales.

The Fixes

Here are two solid solutions to get your formula working seamlessly in both English and French Excel:

1. Use the Standard English Function Name

Swap MEAN for AVERAGE (the official standard function name in English Excel). Excel's translation engine reliably converts this to MOYENNE (the French equivalent) when opening the file in French Excel:

xlWorkSheet.Cells[i, "J"].Formula = string.Format("=AVERAGE(J3:J{0})", i - 1);

2. Use FormulaR1C1 for Reliable Cross-Language Support

If you need to stick with MEAN or want a foolproof method that works regardless of function aliases, use the FormulaR1C1 property. This property uses R1C1-style references and requires English function names, and Excel automatically handles translation to the local language:

// R3C refers to row 3, current column (J in this case); R[-1]C refers to the row above the current cell
xlWorkSheet.Cells[i, "J"].FormulaR1C1 = "=MEAN(R3C:R[-1]C)";

This avoids any issues with A1-style reference translation and ensures the function name gets converted correctly to MOYENNE in French Excel.

Why This Works

  • Formula relies on Excel's translation of both function names and A1-style references, which can break with non-standard function aliases.
  • FormulaR1C1 uses a universal reference format and strictly requires English function names, so Excel's built-in translation works consistently across all language versions.

内容的提问来源于stack exchange,提问作者Moon Rat

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 09:56:21