Excel:布尔值c#的本地名称

本文关键字:布尔值 Excel | 更新日期: 2023-09-27 18:22:06

我想知道Excel如何显示布尔值的名称。例如,如果单元格A1包含true,excel的英文版将显示"true"并抛光"PRAWDA"。如何通过编程检查excel如何为用户显示这些值?

Excel:布尔值c#的本地名称

我认为如果不在本地运行应用程序,就无法获得这些信息。如果有的话,我想知道怎么做。

在本地运行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);
            }
        }
    }