单元格名称与行/列索引之间的转换
Contents
[
Hide
]
从行和列索引中获取 Cell 名称
给定行和列索引可以找到单元格的名称。这篇文章解释了如何。 Aspose.Cells 提供了 CellsHelper.CellIndexToName 方法,如果开发人员提供行和列索引,该方法允许开发人员获取单元格的名称。
与 Microsoft Excel 的行和列索引从 1 开始不同,Aspose.Cells 从 0 开始计算行和列索引。
以下示例代码说明了如何使用 CellsHelper.CellIndexToName 访问给定已知行和列索引的单元格名称。该代码生成以下输出。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
从 Cell 名称获取行和列索引
可以从单元格的名称中找到单元格的行和列索引。这篇文章解释了如何。 Aspose.Cells 提供了 CellsHelper.CellNameToIndex 方法,允许开发人员从单元格的名称中获取行和列索引。
与 Microsoft Excel 的行和列索引从 1 开始不同,Aspose.Cells 从 0 开始计算行和列索引。
以下示例代码说明了如何使用 CellsHelper.CellNameToIndex 从单元格名称中获取行和列索引。该代码生成以下输出。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 提供了类似的功能来处理所有这些问题。以下示例代码演示了此功能:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
输出:
这是名字 cre
<> + (adj.Private _ “私人”