我想知道 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/