单元格名称和行/列索引之间的转换
从行和列索引获取单元格名称
可以通过给定行和列索引来查找单元格的名称。 本文解释了如何操作。 Aspose.Cells提供了CellsHelper.CellIndexToName方法,允许开发人员在提供行和列索引时获取单元格的名称。
以下示例代码说明如何使用CellsHelper.CellIndexToName来访问已知行和列索引的单元格名称。该代码生成以下输出。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
int row = 3; | |
int column = 5; | |
string name = Aspose.Cells.CellsHelper.CellIndexToName(row, column); | |
Console.WriteLine("Cell name: {0}", name); |
从单元格名称获取行和列索引
可以从单元格名称中找到单元格的行和列索引。 本文解释了如何操作。 Aspose.Cells提供了CellsHelper.CellNameToIndex方法,允许开发人员从单元格的名称中获取行和列索引。
以下示例代码说明如何使用CellsHelper.CellNameToIndex来从单元格的名称中获取行和列索引。该代码生成以下输出。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
string name = "C4"; | |
int row; | |
int column; | |
Aspose.Cells.CellsHelper.CellNameToIndex(name, out row, out column); | |
Console.WriteLine("Row: {0}, Column: {1}", row, column); |
创建安全的工作表名称
有时候需要在运行时指定工作表名称。在这种情况下,工作表名称可能包含一些附加字符,如<>+(?”。有必要替换不允许作为工作表名称的任何此类字符,使用用户提供的某个预设字符。同样,长度可能会增加到超过31个字符,需要截断。Apache POI提供了创建安全名称的某些功能,因此Aspose.Cells提供了类似的功能来处理所有这些问题。以下示例代码演示了此功能:
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Long name will be truncated to 31 characters | |
string name1 = CellsHelper.CreateSafeSheetName("this is first name which is created using CellsHelper.CreateSafeSheetName and truncated to 31 characters"); | |
// Any invalid character will be replaced with _ | |
string name2 = CellsHelper.CreateSafeSheetName(" <> + (adj.Private ? \" Private\" : \")", '_');//? shall be replaced with _ | |
// Display first name | |
Console.WriteLine(name1); | |
//Display second name | |
Console.WriteLine(name2); |
输出:
这是第一个名字,它是特别私人的
` ``<> + (adj.Private _ " 私有"