c# - Excel: boolean 值的本地名称c#

标签 c# excel localization boolean

我想知道 Excel 如何显示 boolean 值的名称。例如,如果单元格 A1 包含 true,则英文版的 excel 显示“TRUE”和波兰语“PRAWDA”。我如何以编程方式检查 excel 如何为用户显示这些值?

最佳答案

如果不在本地运行应用程序,我认为您无法获取该信息。如果有,我想知道怎么做。

在本地运行Excel,您可以使用以下代码获取本地化的字符串:

    using System;
    using MSExcel = Microsoft.Office.Interop.Excel;
    using System.Runtime.InteropServices;

    static void Main(string[] args)
    {
        MSExcel.Application excel = null;
        MSExcel.Worksheet sheet = null;
        string localizedFalse;
        string localizedTrue;

        try
        {
            excel = new MSExcel.Application();
            excel.DisplayAlerts = false;
            sheet = (MSExcel.Worksheet)excel.Workbooks.Add(MSExcel.XlWBATemplate.xlWBATWorksheet).Sheets.Add();
            sheet.Cells[1, 1] = false;
            sheet.Cells[1, 2] = true;
            sheet.Columns.AutoFit(); //If the localized string doesn't fit in the default column width, the returned text will be ##########.
            localizedFalse = sheet.Cells[1, 1].Text;
            localizedTrue = sheet.Cells[1, 2].Text;

            Console.WriteLine("Excel localized true: {0} \r\nExcel localized false: {1}", localizedTrue, localizedFalse);
            Console.ReadLine();
        }
        finally
        {
            if (sheet != null)
            {
                Marshal.ReleaseComObject(sheet);
            }

            if (excel != null)
            {
                excel.Quit();
                Marshal.ReleaseComObject(excel);
            }
        }
    }

关于c# - Excel: boolean 值的本地名称c#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25887150/

相关文章:

javascript - 在 Unityscript 中更改按钮的背景

c# - WPF 数据网格 : DataGridComboxBox ItemsSource Binding to a Collection of Collections

iphone - Xcode - 本地化图像无法在设备上运行

wpf - 我们是否需要安装 os 语言包来本地化 wpf 应用程序?

java国际化规则

c# - Selenium - 发送 key 以在影子根(打开)和挪威 BankId 的多个 iframe 中输入密码

c# - 将字符串格式化为英国电话号码

VBA循环遍历一个列,获取每个位置的前10个(如果小于10,则为最大值)的范围

excel - 将 Excel 文件转换为 Google 表格会破坏带有 HYPERLINK 的公式

vba - 如何使用VBA在Excel中移动图像?